Results 1 to 4 of 4
  1. #1
    Rolle is offline Member
    Join Date
    Oct 2009
    Posts
    1
    Rep Power
    0

    Question Simple Java program

    Hi!

    I'm very new to Java, basicly all I know is how the classes and variables work. I wanted to do a simple program in Swing in NetBeans.

    The idea is very simple. I have 4 input text boxes. Each box has a different multiplier (let's call it amount of gold (G)). They all start out with value 0.

    User inputs some numbers into these boxes and presses the "Count" button (that's the part I don't know how to do at all). Sum of all the values comes in the fifth box at the bottom of the window. Reset button resets all the values back to 0.

    I build design of the program in NetBeans, now I need to code the functionality. So far I have this, but I don't have neither one of the buttons and some strange error when trying to parseInt the values.

    Java Code:
    package app;
    import javax.swing.*;
    
    private javax.swing.JTextField textInput1;
    private javax.swing.JTextField textInput2;
    private javax.swing.JTextField textInput3;
    private javax.swing.JTextField textInput4;
    private javax.swing.JTextPane suma;
    
    private int value1 = Integer.parseInt( textInput1 );
    private int value2 = Integer.parseInt( textInput2 );
    private int value3 = Integer.parseInt( textInput3 );
    private int value4 = Integer.parseInt( textInput4 );
    
    // 1 = 30G, 2 = 8G, 3 = 5G, 4 = 3G
    suma = value1 * 30 + value2 * 8 + value3 * 5 + value4 * 3;
    I appreciate all help, thank you!

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    What do you expect to get here?
    Java Code:
    Integer.parseInt( textInput1 );
    You're trying to parse a JTextField's toString() output. Have another look at the JTextField API.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    832
    Rep Power
    6

    Default

    Use like this below.

    int value1 = Integer.parseInt( textInput1.getText() );
    Ramya:cool:

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    Nice spoon feeding. :rolleyes:
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. Help needed very simple java program
    By pavez in forum New To Java
    Replies: 3
    Last Post: 08-22-2009, 03:05 PM
  2. [SOLVED] Need help with simple Java program
    By hungdukie in forum New To Java
    Replies: 5
    Last Post: 11-26-2008, 03:17 AM
  3. Simple Java probablitity program?
    By nothing4me in forum New To Java
    Replies: 6
    Last Post: 11-12-2008, 06:16 AM
  4. help with simple program in java
    By katie in forum New To Java
    Replies: 2
    Last Post: 08-06-2007, 08:03 PM
  5. help with simple java program
    By leonard in forum New To Java
    Replies: 3
    Last Post: 07-30-2007, 09:40 AM

Posting Permissions

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