Simple Java program
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.
I appreciate all help, thank you!
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;
What do you expect to get here?
You're trying to parse a JTextField's toString() output. Have another look at the JTextField API.
Integer.parseInt( textInput1 );
Use like this below.
int value1 = Integer.parseInt( textInput1.getText() );
Nice spoon feeding. :rolleyes: