Results 1 to 3 of 3
- 03-01-2009, 08:29 AM #1
Member
- Join Date
- Mar 2009
- Posts
- 1
- Rep Power
- 0
what's wrong with my code? please help me...


when you clicked the display button it must display the remarks but nothing happen instead an error occurs please help me find out what's wrong?
here is my code...
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class Area extends Applet implements ItemListener,ActionListener
{Label arlbl = new Label("AREA");
Choice archc = new Choice();
Label extlbl = new Label("EXPENDITURE TYPE");
CheckboxGroup extchk = new CheckboxGroup();
Checkbox fchk = new Checkbox("FOOD",extchk,true);
Checkbox schk = new Checkbox("SHELTER",extchk,false);
Checkbox echk = new Checkbox("EDUCATION",extchk,false);
Checkbox uchk = new Checkbox("UTILITIES",extchk,false);
Label exalbl = new Label("EXPENDITURE AMOUNT");
TextField exatf = new TextField("",20);
Label remlbl = new Label("REMARKS");
TextField remtf = new TextField("",30);
Button disbtn = new Button("DISPLAY");
Button resbtn = new Button("RESET");
String display;
public void init()
{add(arlbl);
archc.add("MANILA");
archc.add("MAKATI");
archc.add("QUEZON");
archc.add("PASAY");
add(archc);
archc.addItemListener(this);
add(extlbl);
add(fchk);
fchk.addItemListener(this);
add(schk);
schk.addItemListener(this);
add(echk);
echk.addItemListener(this);
add(uchk);
uchk.addItemListener(this);
add(exalbl);
add(exatf);
add(remlbl);
add(remtf);
add(disbtn);
disbtn.addActionListener(this);
add(resbtn);
resbtn.addActionListener(this);
}
public void itemStateChanged(ItemEvent ex)
{int n = archc.getSelectedIndex();
if(n==0)
{if(fchk.getState())
{exatf.setText("10000.00");
display = archc.getSelectedItem();
}
if(schk.getState())
{exatf.setText("15000.00");
display = archc.getSelectedItem();
}
if(echk.getState())
{exatf.setText("24000.00");
display = archc.getSelectedItem();
}
if(uchk.getState())
{exatf.setText("8500.00");
display = archc.getSelectedItem();
}
}
if(n==1)
{if(fchk.getState())
{exatf.setText("5000.00");
display = archc.getSelectedItem();
}
if(schk.getState())
{exatf.setText("11000.00");
display = archc.getSelectedItem();
}
if(echk.getState())
{exatf.setText("7500.00");
display = archc.getSelectedItem();
}
if(uchk.getState())
{exatf.setText("24000.00");
display = archc.getSelectedItem();
}
}
if(n==2)
{if(fchk.getState())
{exatf.setText("13000.00");
display = archc.getSelectedItem();
}
if(schk.getState())
{exatf.setText("7000.00");
display = archc.getSelectedItem();
}
if(echk.getState())
{exatf.setText("27000.00");
display = archc.getSelectedItem();
}
if(uchk.getState())
{exatf.setText("6000.00");
display = archc.getSelectedItem();
}
}
if(n==3)
{if(fchk.getState())
{exatf.setText("6000.00");
display = archc.getSelectedItem();
}
if(schk.getState())
{exatf.setText("9000.00");
display = archc.getSelectedItem();
}
if(echk.getState())
{exatf.setText("15000.00");
display = archc.getSelectedItem();
}
if(uchk.getState())
{exatf.setText("19000.00");
display = archc.getSelectedItem();
}
}
}
public void actionPerformed(ActionEvent e)
{if(e.getSource() == disbtn)
{String amtstr = exatf.getText();
int amt = Integer.parseInt(amtstr);
{if(amt > 8000)
{remtf.setText(display + " IS ABOVE BUDGET");
}
else
{remtf.setText(display + " IS BELOW BUDGET");
}
}
}
if(e.getSource() == resbtn)
{archc.select(0);
fchk.setState(true);
schk.setState(false);
echk.setState(false);
uchk.setState(false);
exatf.setText("");
remtf.setText("");
}
}
}
-
The exception will tell you where the error occurred (which line of code) and why. Yours is occurring in your actionPerformed method where you appear to be trying to parse a number String that's really a double as an int (again, the error will tell you even what String you're trying to parse).
Best of luck.
-
Edit: thanks for cross-posting this question on another forum. I now see that I wasted my time trying to study your code to help you with an answer that had already been answered elsewhere. Do you realize that we are volunteers, that our time is as valuable as yours? Apparently not. Cross-post again and many here will not help you again.
Similar Threads
-
What's wrong with this code?
By Doctor Cactus in forum New To JavaReplies: 4Last Post: 11-29-2008, 05:44 PM -
What is wrong with this code
By rosh72851 in forum New To JavaReplies: 13Last Post: 10-31-2008, 01:50 AM -
what's wrong with this code?
By agenteleven in forum Advanced JavaReplies: 5Last Post: 10-07-2008, 11:26 AM -
what is wrong with this code
By masaka in forum New To JavaReplies: 5Last Post: 04-16-2008, 08:27 AM -
What's wrong with this code?
By Wizard wusa in forum New To JavaReplies: 14Last Post: 01-22-2008, 11:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks