It's won't work WHY!!!

It compiles but I can't convert Strings to Integers
Heres the code the classes involved work as I've tested them.
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import StudentMarks;
class StudentGrades extends JFrame implements ActionListener
     private JTextField field1;
     private JTextField field2;
     private JTextField field3;
     private JTextField field4;
     private JLabel word1;
     private JLabel word2;
     private JLabel word3;
     private JLabel word4;
     private JPanel main;
     private JPanel panel;
     private JPanel button;
     private JPanel output;
     private JButton EnterStudent;
     private JButton DisplayGrade;
     private JButton ClearFields;
     private JButton Quit;
     private JTextField displayField;
     private StudentMarks sml;
     public StudentGrades()
          setTitle("Student Grades");     //Title
          setSize (500,600);     //Size
          addWindowListener (new WindowAdapter()
          { public void windowClosing(WindowEvent e)
               {System.exit(0);  //halt the program
               //Word and Fields
               word1= new JLabel ("Enter Student ID");
               word1.setHorizontalAlignment(JLabel.RIGHT);
               field1=new JTextField(" ");
               field1.addActionListener(this);
               word2 = new JLabel ("Enter Student Name");
               word2.setHorizontalAlignment(JLabel.RIGHT);
               field2= new JTextField(" ");
               field2.addActionListener(this);
               word3 = new JLabel ("Enter Mark 1");
               word3.setHorizontalAlignment(JLabel.RIGHT);
               field3 = new JTextField (" ");
               field3.addActionListener(this);
               word4= new JLabel ("Enter Mark 2");
               word4.setHorizontalAlignment(JLabel.RIGHT);
               field4 = new JTextField(" ");
               field4.addActionListener(this);
               //Add to panel the words and fields
               panel= new JPanel(new GridLayout (4,2,5,5));
               panel.add(word1);
               panel.add(field1);
               panel.add(word2);
               panel.add(field2);
               panel.add(word3);
               panel.add(field3);
               panel.add(word4);
               panel.add(field4);
               button = new JPanel();
               button.setBackground(Color.white);
               EnterStudent = new JButton("Enter Student");
               DisplayGrade = new JButton("DisplayGrade");
               ClearFields = new JButton("Clear Fields");
               Quit = new JButton("Quit");
               button.add(EnterStudent);
               button.add(DisplayGrade);
               button.add(ClearFields);
               button.add(Quit);
               EnterStudent.addActionListener(this);
               DisplayGrade.addActionListener(this);
               ClearFields.addActionListener(this);
               Quit.addActionListener(this);
               //The display field
               displayField = new JTextField(" ");
               displayField.setEditable(false);
               displayField.setHorizontalAlignment(JTextField.CENTER);
               output = new JPanel();
               output.add(displayField,BorderLayout.SOUTH);
          //addWindowListener();
          //infield.addActionListener(this)     
          main = new JPanel(new GridLayout(6,4,5,5));
          main.add(panel,BorderLayout.NORTH);
          main.add(button,BorderLayout.CENTER);
          main.add(displayField,BorderLayout.SOUTH);
          Container contentPane = getContentPane();
          contentPane.add(main);
          public void actionPerformed (ActionEvent evt)
          Object source = evt.getSource();
                    if(source == Quit) System.exit(0);
                    else if (source == EnterStudent)
                              //StudentMarks butt1;
                              //String x = field1.getText();
                              //String name = field2.getText();
                              //String mak1 = field3.getText();
                              //String mak2 = field4.getText();
                              //Integer id = new Integer(field1.getText());
                              //Integer mark1 = new Integer(field3.getText());
                              //Integer mark2 = new Integer(field4.getText());
                              //sml = new StudentMarks(1,"Baza",25,45);
                              sml = new StudentMarks(Integer.parseInt(field1.getText()),field2.getText(),Integer.parseInt(field3.getText()),Integer.parseInt(field4.getText()));
                              displayField.setText("Student " + sml.getID() + " marks have been entered");
                         else if (source == DisplayGrade)
                         //{sml = new StudentMarks(Integer.parseInt(field1.getText()),field2.getText(),Integer.parseInt(field3.getText()),Integer.parseInt(field4.getText()));
                         displayField.setText(sml + "\n" + sml.getGrade());
                         //StudentMarks butt2;
                         //String x = field1.getText();
                         //String name = field2.getText();
                         //String mak1 = field3.getText();
                         //String mak2 = field4.getText();
                         //int id, mark1, mark2;
                         //id = Integer.parseInt(x);
                         //mark1 = Integer.parseInt(mak1);
                         //mark2 = Integer.parseInt(mak2);
                         //butt2 = new StudentMarks(id,name,mark1,mark2);
                         //displayField.setText(butt2.getGrade());
else if (source == ClearFields)
                              field1.setText(" ");
                              field2.setText(" ");
                              field3.setText(" ");
                              field4.setText(" ");
                              displayField.setText(" ");
     public class StudentGradesTest
     {     public static void main (String[] args)
          {     StudentGrades s = new StudentGrades();
               s.show();
     }

Try getText().trim()
This will remove spaces from the text & avoid NumberFormatException being thrown
Warm regards
Aswin Asokan

Similar Messages

  • Keyboard Shortcuts in PSExtended CS6 won't work - why?

    Hi, any idea why lots of my shortcuts won't work or very little shortcuts are registered in my keyboard shortcut menu and when you use them they seem to be mixed up. Pls help.....
    Best, Bee

    thanks for the list of all shortcut keys -
    exemple for MixUp: I click Shift+F5 in order to get the unsharp mask and end up with the Fill window...
    Most of the simple shortcut work just fine - and now I have even figured out how to add my own shortcuts to the list So I might be even able to fix my MIXUP......
    Thanks, you helped me a lot.
    Best, Bee.

  • Flash Player won't work , why ?

    I updated Flash Player on my Laptop with Win 7 & IE 11 & it won't work . I also have a Desktop with Win 7 & IE 11 , it updated & works fine . What's going on ?

    http://forums.adobe.com/message/4041846
    http://forums.adobe.com/thread/885448
    http://forums.adobe.com/thread/867968

  • System Exec+ "CMD /C START DESK.CPL" won't work--why?

    I've seen previous posts stating that the System Exec is the equivalent of the run box in windows (explaining why you can't execute commands like "dir").
    However, I can run a line like this...
    CMD /C START C:\WINNT\SYSTEM32\DESK.CPL
    or
    CMD /C START C:\WINNT\SYSTEM32\NIPORTS.CPL
    ..from the run menu, but not with System Exec+. CPL files of course are executables that load in the control panel and a WinNT shortcut will not show you the path.
    The workaround is to create a batch file on the fly and execute the text above (since porting the application to a different computer means there might not be an existing batch file). The batch file looks like:
    @CMD /C START C:\WINNT\SYSTEM32\DESK.CPL
    @EXIT
    I don't like having to generate a batch file inasmuch as it does get the job done, there is still the clunky dos box that flashes onto the screen for a brief second. Does anyone know what causes the above discrepancy? ...why it will run from the windows run box, but not with System Exec+? I'm guessing it has something to do with using the START command but I have never had to use it before in this fashion. Any ideas?

    Arg! You're right!
    I originally tried this with NIPORTS.CPL and used DESK.CPL in the above example (without testing it) because everyone has desktop properties but not necessarily the port properties for the E-NET/RS-485 converter. I'm guessing there was a spelling or path error somewhere that wouldn't let my original attempt execute--it works now.
    Also: I didn't realize that any time you execute CMD that it will show a dos box, not just for batch files. Oh well...
    Thanks for your input...

  • I am filling out a pdf but the send button won't work. why?

    I created a fillable PDF in Acrobat 9 pro and sent it out as a test to my email. I filled it out and pressed the send button but it does not work. I updated Adobe reader to version 10. Still nothing... anyone know what's wrong?

    - Make sure have something entered in the Subject fied.
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - iOS: Troubleshooting Messages

  • Intercom Service Won't work :( Why not? - FIXED IT THANKS

    Hi guys new to the Group,
    I have been playing with the Latest SDK. I have managed to get Hootie to work but I am unable to get Intercom to work correctly.
    When I set up the Service I add the IP Address of the phone I want to connect to. I then press the Services button and then the Intercom Service Option the phone I am wanting to speak with Enters the Intercom mode but my phone Shows a <!DOCTYPE HTML PUBLIC"-//W3C/DTD HTML 3.2 Final//EN"> Error Page.
    Anybody got any Idea where I am going wrong?
    Many Thanks
    Dave :)

    Have you edited the source as specified???
    <%
    // - Required COM Servers: Microsoft MSXML
    // - The 'includes' file(s) listed in the beginning of this file MUST be reachable
    // at the specified web path.
    // - When creating the Intercom Phone Service on CallManager, you MUST specify a
    // a Phone Service Parameter for the IP address of the destination intercom
    // phone. The Parameter Name must be 'phoneIP' and the parameter should
    // be marked as 'Required'.
    var pushuserid = "sdkapps";
    var pushpassword = "sdkapps";

  • CS3 fireworks trial download won't work, why?

    when i try to launch the trial it gives me this message.
    a problem was encountered while trying to load the trial
    period for adobe fireworks cs3
    click quit to see if restarting your computer or reinstalling
    the software fixes the problem. otherwise click continue to display
    a screen where you can enter a valid serial number to begin using
    the product without trial.
    i tried it twice and resarted my computer. are the cs3 trials
    still working? thanks

    Hi
    You need MAC OS 10.7 or higher to install Muse CC 2014. Release notes | Adobe Muse CC

  • BRUSH STROKE in/out configuration WON't WORK why ?

    I use photoshop for years now, I'm not a noob.
    I've been trying to fix this problems since I started to use it, but I HAVEN't found a single solution to it !
    I customized the brush strokes to have a thin STROKE out/in but every time i get these bumps at the end of a stroke
    I reinstalled the program a couple of times, and it's not only photoshop CS6, every photoshop has this problem.
    But when I try another drawing program, there it works fine. SO I DON't KNOW WHAT TO DO.
    PLEASE HELP ME !!!

    thanks for the list of all shortcut keys -
    exemple for MixUp: I click Shift+F5 in order to get the unsharp mask and end up with the Fill window...
    Most of the simple shortcut work just fine - and now I have even figured out how to add my own shortcuts to the list So I might be even able to fix my MIXUP......
    Thanks, you helped me a lot.
    Best, Bee.

  • I installed Firefox for Mobile on my HTC Droid Eris but it won't work. Why?

    I have an HTC Droid Eris and it runs the Android 2.0 operating system. When I attempt to open it I receive a message that says: "This device does not meet the minimum system requirements for Firefox".
    The website states: "Firefox 4 Beta is available for Android 2.0 or higher" so I do not understand why it won't work on my phone.

    See this web page for system requirements, and an experimental version that might work on the Droid Eris: https://wiki.mozilla.org/Mobile/Platforms/Android#System_Requirements

  • Since iOS 7.1 my phone won't turn on and is asking me to connect to iTunes. I connect to itunes and it says it needs to be restored. Not sure why. I try to restore it and then it says something went wrong and it won't work. So I've been without my phone

    Since iOS 7.1 my phone won't turn on and is asking me to connect to iTunes. I connect to itunes and it says it needs to be restored. Not sure why. I try to restore it and then it says something went wrong and it won't work. So I've been without my phone for a couple days now. It gives me error code (29). The phone almost reboots and then 3/4 of the way through it gives me the error message.

    If using windows...
    Temporarily disable your firewall and antivirus software and try again...
    http://support.apple.com/kb/TS1379
    See iTunes Connection Issues here...
    iTunes for Windows: Troubleshooting security software issues
    NOTE:
    Make sure you have the Latest Version of iTunes (v11.1.5) Installed on your computer
    iTunes free download from www.itunes.com/download

  • Why is it that each time I upgrade my iPad, half of my apps won't work properly but worst of all my email won't send after the latest "patch" today, wake up Apple I am a new user and getting sick of this problems

    WHy is it that each time I get an upgrade some of my Apps won't work when they did with the previous version. I have just upgraded to v7.01 and now I cannot send email, wake up Apple and get it right as I am a new user of Apple technology and not impressed.

    That's one of the weird things.. it recognizes it maybe 10% of the time. And usually, only after I do the two-button reset. Problem is.. since it won't charge above 2%, anytime I try to do a restore or anything like that using iTunes, my device shuts off and I lose whatever progress I'd made.
    So, an update... after reading through a bunch of similar complaints (there are literally 1000's of them so there's NO WAY this isn't somehow ios7 related, thanks a lot APPLE ) I decided to try a restore in recovery mode. After 3 hours and several disconnections... I ended up having to just set it up as a new iPad, as the restore did nothing. Weirdly though... as I was doing the restore in recovery mode.. I noticed I'd gotten up to a 10% charge.. higher than it's been since September, so after setting it up as a new device, I turned it off and plugged it in using the wall charger. 2 hours later and I was up to 38%. Still not great, as my iPad, before ios7 could've fully charged twice in the amount of time it took for me to now get 28% more of a charge. And that's with a fully cleaned out device.. so that really ***** and I'm now more confused than ever.
    But I'm gonna leave it overnight charging and see what I come up with tomorrow. Sadly, when I paid $600 for it in February, I never expected to have to play "wait and see" with it...

  • Why Apple Thunderbolt Display won't work on BootCamp Win7 64-bit while being plugged to MBA?

    Hello,
    I have MBA (latest) & installed win7 64-bit in BootCamp, I do also have Apple Thunderbolt 27" Display.
    When I disconnect the ATD and re-connect it in Mac OS X, it works fine like a charm, but when I disconnect then re-connect in BootCamp, it doesn't work at all whatsoever, in fact, I have to restart my MBA (while thunderbolt is connected) to make it work in BC, this is the only way to make it work.
    So, my question is; If I disconnected ATD in BootCamp then re-connected it, why it won't work?
    I've googled everywhere about this issue, but no luck.
    Any idea?

    to calculate how much video ram is needed one
    take
    the vertical number of pixels and * with horisontal number of pixels and * with 32bit colour which is 4 bytes
    so if it's the 13" macbook air
    1440 * 900 * 4 = 5.184MB for main display
    +
    2560 *1440 *4 = 14.75MB for second display
    sounds like the intel hd 5000 would have that as dedicated memory even if the windows driver did not allow to use shared system mem as extra
    could be a problem with the driver for windows
    maybe a person who ran a setup like yours would have more to contribute with
    my setup is an imac 21" with amd video card and a 24" dvi dell monitor and that works fine in windows so it's a different animal altogether

  • HT204291 Why don't I see the airplay icon in my settings? I have the ios7 installed now my netflix won't work as need to turn off mirroring..... And the airplay device is not installed.... Anyone help on this?.

    Why don't I see the airplay icon in my settings? I have the ios7 installed now my netflix won't work as need to turn off mirroring..... And the airplay device is not installed.... Anyone help on this?.

    Reboot your router. The icon only shows when connected to wifi and Apple TV or similar device. Same thing happened with my phone and the icon appeared in control center after router reboot.

  • Garageband  4.1.2 won't work in Snow Leopard.  Why? Please help.

    Garageband 4.1.2 won't work in Snow Leopard. Why? Please help.

    It might be a PPC application. You may need the optional Rosetta install.

  • I have seen on this community that the earpods do not work on iPod shuffle gen 3 but when I was using on them it worked the control panel thing that is but only until I turned it off I don't understand why it won't work again and why it did in the first p

    I have seen on this community that the earpods do not work on iPod shuffle gen 3 but when I was using on them it worked the control panel thing that is but only until I turned it off I don't understand why it won't work again and why it did in the first place can someone please explain and tell me how to make it work again

    Sorry first time asking question didn't mean to write same thing twice well copy paste

Maybe you are looking for