Results 1 to 3 of 3
  1. #1
    lovely23 is offline Member
    Join Date
    Mar 2009
    Posts
    1
    Rep Power
    0

    Default what's wrong with my code? please help me...

    what's wrong with my code? please help me...-untitled1.1.jpg
    what's wrong with my code? please help me...-untitled1.2.jpg
    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("");
    }
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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

  1. What's wrong with this code?
    By Doctor Cactus in forum New To Java
    Replies: 4
    Last Post: 11-29-2008, 05:44 PM
  2. What is wrong with this code
    By rosh72851 in forum New To Java
    Replies: 13
    Last Post: 10-31-2008, 01:50 AM
  3. what's wrong with this code?
    By agenteleven in forum Advanced Java
    Replies: 5
    Last Post: 10-07-2008, 11:26 AM
  4. what is wrong with this code
    By masaka in forum New To Java
    Replies: 5
    Last Post: 04-16-2008, 08:27 AM
  5. What's wrong with this code?
    By Wizard wusa in forum New To Java
    Replies: 14
    Last Post: 01-22-2008, 11:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •