Results 1 to 4 of 4
Thread: Simple Java program
- 10-26-2009, 03:33 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 1
- Rep Power
- 0
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.
I appreciate all help, thank you!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;
- 10-26-2009, 03:47 PM #2
What do you expect to get here?
You're trying to parse a JTextField's toString() output. Have another look at the JTextField API.Java Code:Integer.parseInt( textInput1 );
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 10-26-2009, 04:02 PM #3
Use like this below.
int value1 = Integer.parseInt( textInput1.getText() );Ramya:cool:
- 10-26-2009, 04:05 PM #4
Nice spoon feeding. :rolleyes:
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
Similar Threads
-
Help needed very simple java program
By pavez in forum New To JavaReplies: 3Last Post: 08-22-2009, 03:05 PM -
[SOLVED] Need help with simple Java program
By hungdukie in forum New To JavaReplies: 5Last Post: 11-26-2008, 03:17 AM -
Simple Java probablitity program?
By nothing4me in forum New To JavaReplies: 6Last Post: 11-12-2008, 06:16 AM -
help with simple program in java
By katie in forum New To JavaReplies: 2Last Post: 08-06-2007, 08:03 PM -
help with simple java program
By leonard in forum New To JavaReplies: 3Last Post: 07-30-2007, 09:40 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks