The Artima Developer Community
Sponsored Link

Java Answers Forum
Trying to get rating applet to work

4 replies on 1 page. Most recent reply: Jul 5, 2003 3:58 PM by zenykx

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
timmy

Posts: 3
Nickname: tamir
Registered: Jul, 2003

Trying to get rating applet to work Posted: Jul 5, 2003 8:17 AM
Reply to this message Reply
Advertisement
Hey guys.

Okay i'm trying to make an applet which will act as a sort of rating system. with a choice from 1 to10. and the average result shown next to it.

I have some java code:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Rate extends Panel implements ItemListener{

Choice numbers = new Choice();
Label average = new Label("0");
Label total = new Label("0");
int t;
double a;
double newa;
int selected;
Canvas c = new Canvas();

public void init() {
c.setBackground(Color.yellow);
setLayout(new FlowLayout());
numbers.add("1"); numbers.add("2"); numbers.add("3");
numbers.add("4"); numbers.add("5"); numbers.add("6");
numbers.add("7"); numbers.add("8"); numbers.add("9");
numbers.add("10");
numbers.addItemListener(this);
add(numbers );
add(average);
add(total);
setVisible(true);

}


public void itemStateChanged(ItemEvent e) {

t = (Integer.parseInt(total.getText()) + 1);
a = Double.parseDouble(average.getText());
newa = 0;
selected = (numbers.getSelectedIndex() + 1);

newa = (a+selected) / (t);

average.setText(""+newa);
total.setText(""+t);
}
}

this compiles fine but if i try to run it in a browser as an applet i get a class exception error ( to be more specific: "Exception: java.lang.ClassCastException: Rate")

could anyone help me out?
thanks


zenykx

Posts: 69
Nickname: zenykx
Registered: May, 2003

Re: Trying to get rating applet to work Posted: Jul 5, 2003 8:33 AM
Reply to this message Reply
Must extend Applet... not Panel

timmy

Posts: 3
Nickname: tamir
Registered: Jul, 2003

Re: Trying to get rating applet to work Posted: Jul 5, 2003 8:41 AM
Reply to this message Reply
Oh b****y hell!!!
It's always something really small.
A past mistake when experimenting.

Thanks alot. for the life of me i just kept skipping past that.

timmy

Posts: 3
Nickname: tamir
Registered: Jul, 2003

Re: Trying to get rating applet to work Posted: Jul 5, 2003 8:45 AM
Reply to this message Reply
hmm...it still doesn't work...it still comes up with the same error even when i change Panel to Applet.

zenykx

Posts: 69
Nickname: zenykx
Registered: May, 2003

Re: Trying to get rating applet to work Posted: Jul 5, 2003 3:58 PM
Reply to this message Reply
If you really make Rate extend Applet and then recompile it works. I don't know what is wrong but i try it!

Flat View: This topic has 4 replies on 1 page
Topic: please check this code Previous Topic   Next Topic Topic: pls help I'm desparate - still new in Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use