Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-28-2004, 08:50 PM   PM User | #1
mrprimo55
New Coder

 
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
mrprimo55 is an unknown quantity at this point
Question Java Troubles

I'm taking a Java class at school and almost every computer seems to heaving the same problem and we can't figure out what is wrong. We are using Codewarrior on XP machines. We wrote an applet and when we try to run it, everyone gets the same error saying that the main class needs to be declared as 'abstract'. Now the really weird thing about all this is that for some reason one person's applet worked, so I copied his .java file (which is the same as mine and everyone elses) onto a disk and put it in a new project on my computer and it worked fine. I've done this on every computer now and it works. I've gone through line by line and his program is EXACTLY the same as everyone elses. Does anyone know why this is happening and what the error means when it says the class needs to be declared as 'abstract'? Any help would be appreciated. Thanks.
mrprimo55 is offline   Reply With Quote
Old 10-29-2004, 06:47 AM   PM User | #2
JPM
Regular Coder

 
Join Date: Mar 2004
Location: Norway
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
JPM is an unknown quantity at this point
you should post the code/class
__________________
<JPM />
JPM is offline   Reply With Quote
Old 10-29-2004, 10:11 PM   PM User | #3
mrprimo55
New Coder

 
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
mrprimo55 is an unknown quantity at this point
Ya I dont have class until Monday so I will get the code then and post it sometime Monday afternoon.
mrprimo55 is offline   Reply With Quote
Old 11-01-2004, 08:34 PM   PM User | #4
mrprimo55
New Coder

 
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
mrprimo55 is an unknown quantity at this point
Code:
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.text.DecimalFormat;

public class CheckBoxApplet extends Applet implements ItemListener
{
	double dollars, answer;
	int empCode;
	Color darkRed = new Color(160,50,0);
	
	
	Label promptLabel = new Label("Enter the sales amount (do not use commas or dollar signs):");
		TextField salesField = new TextField(20);
		
	Label codeLabel = new Label ("Select the appropriate commission code:");
	
	CheckboxGroup codeGroup = new CheckboxGroup();
		Checkbox telephoneBox = new Checkbox("Telephone Sales",false,codeGroup);
		Checkbox inStoreBox = new Checkbox("In-Store Sales",false,codeGroup);
		Checkbox outsideBox = new Checkbox("Outside Sales",false,codeGroup);
		Checkbox hiddenBox = new Checkbox(" ",true,codeGroup);
		
	Label outputLabel = new Label("Click an option button to calculate the sales commission.");		

	public void init() 
	{
		setBackground(darkRed);
		setForeground(Color.white);
		add(promptLabel);
		add(salesField);
		salesField.requestFocus();
		salesField.setForeground(Color.black);
		add(codeLabel);
		add(telephoneBox);
		telephoneBox.addItemListener(this);
		add(inStoreBox);
		inStoreBox.addItemListener(this);
		add(outsideBox);
		outsideBox.addItemListener(this);
		add(outputLabel);
	}
	
	public void itemStateChanged(ItemEvent choice)
	{
		try
		{
			dollars = getSales();
			empCode = getCode();
			answer = getComm(dollars,empCode);
			output(answer,dollars);
		}
		
		catch (NumberFormatException e)
		{
			outputLabel.setText("You must enter a dollar amount greater then zero,");
			hiddenBox.setState(true);
			salesField.setText("");
			salesField.requestFocus();
			
		}
	}		
	
	public double getSales()	//getSalses method
	{
		double sales = Double.parseDouble(salesField.getText());
		
		if (sales <=0) throw new NumberFormatException();
		
		return sales;
	}
		
	public int getCode()
	{
		int code = 0;
		if (telephoneBox.getState()) code = 1;
		else 
			if (inStoreBox.getState()) code = 2;
			else
				if (outsideBox.getState()) code = 3;
		return code;
	
	}
	
	public double getComm(double sales, int code)
	{
		double commission = 0.0;
		switch(code)
		{
			case 1:
				commission = .10 * sales;
				break;
				
			case 2:
				commission = .14 * sales;
				break;
			
			case 3:
				commission = .18 * sales;
				break;
				
		}
			return commission;
			
	}
	
	public void output(double commission, double sales)
	{
		DecimalFormat twoDigits = new DecimalFormat("$#,000.00");
		outputLabel.setText("Your commission on sales of "+twoDigits.format(sales)+" is "+twoDigits.format(commission));
	}
			
		
	public void paint(Graphics g) 
	{
		
	}
}

Last edited by Antoniohawk; 11-02-2004 at 03:33 AM..
mrprimo55 is offline   Reply With Quote
Old 11-01-2004, 10:54 PM   PM User | #5
mrprimo55
New Coder

 
Join Date: Sep 2004
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
mrprimo55 is an unknown quantity at this point
The error I kept getting said something about needing to declare the CheckBoxApplet class as "abstract". I would post the entire error, but I can't get it anymore now that I've "fixed" the program. All I did was copy and paste the .java file into a new project and now it works. I'm not sure why that worked, but it did.
mrprimo55 is offline   Reply With Quote
Old 11-02-2004, 03:34 AM   PM User | #6
Antoniohawk
Senior Coder

 
Join Date: Aug 2002
Location: Kansas City, Kansas
Posts: 1,518
Thanks: 0
Thanked 2 Times in 2 Posts
Antoniohawk will become famous soon enough
Next time slap your code in the vbcode [code] tags so that it retains the formatting.
Antoniohawk is offline   Reply With Quote
Old 11-02-2004, 07:26 AM   PM User | #7
Roelf
Senior Coder

 
Join Date: Jun 2002
Location: Zwolle, The Netherlands
Posts: 1,110
Thanks: 2
Thanked 28 Times in 28 Posts
Roelf is on a distinguished road
mostly (perhaps always) the reason for needing to declare a class as abstract, is because you don't implement all members of the interface. So it is not a true implementation of the interface, but you have to extend this class to get all interfacemembers implemented.
Roelf is offline   Reply With Quote
Old 03-26-2005, 05:49 AM   PM User | #8
kcussemanliame
New to the CF scene

 
Join Date: Mar 2005
Location: California
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kcussemanliame is an unknown quantity at this point
I'm glad you figured it out; now how about the rest of us.

I'm having the same exact problem. I work on applets at my school, none of the computers work when I try to use any Listeners, and no even my teacher knows what to do. Once, only once, we got it to work by changing the JDK Profile on an administrator account. Now we cant figure out what we did, why it worked, or why, no matter what we try, it still wont work. help, please. I need to figure this out to graduate.

-Peter
kcussemanliame is offline   Reply With Quote
Old 04-07-2005, 06:21 PM   PM User | #9
kcussemanliame
New to the CF scene

 
Join Date: Mar 2005
Location: California
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
kcussemanliame is an unknown quantity at this point
nevermind

forget it. i used his code to fix my own. i still dont know why my last code worked on one computer and not on any others, but my new code, and his code works fine. i'll just accept it now that i can make it work. thanks for posting, it helped me out.
kcussemanliame is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:21 AM.


Advertisement
Log in to turn off these ads.