Results 1 to 5 of 5
Thread: Java Swing Simple Addition help
- 04-27-2010, 03:02 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Java Swing Simple Addition help
I'm using netbeans then i design 3 jTextField and 1 jButton.
the jTextField1 and jTextField2 are inputting numbers. and last the jTextField3 is the result sum of the two inputted numbers.
When i click the jButton should be show the sum of two inputted numbers in the jTextField3.
So the problem is how could i code this?
Im new at java swing.
do you have sample code for this so that i can study it.
thanks
-
I've seen the answer for this very question. You can find it here:
Java Programming - Java swing simple addition help
- 04-27-2010, 04:36 AM #3
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
i want to convert this into a gui type. which i want to happenedJava Code:import java.io.*; public class SimpleAdd { public static void main(String[]args)throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); System.out.print("Enter First Number: "); int num1 = Integer.parseInt(input.readLine()); System.out.print("Enter Second Number: "); int num2 = Integer.parseInt(input.readLine()); int sum = num1+num2; System.out.println("The Sum of Two Numbers is: "+sum); } }
- 04-27-2010, 10:23 AM #4
Member
- Join Date
- Jan 2010
- Posts
- 80
- Rep Power
- 0
I will give you a simple example of how we can activate the button.
In the next code, if the user enters his/her name in the textField, the name will be shown in the label.
Try to figure out how I could make the button works !Java Code:import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Print extends JApplet implements ActionListener{ private JTextField textField; private JLabel label; private JButton button; public void init(){ textField = new JTextField(10); label = new JLabel("Your name"); button = new JButton("Enter"); button.addActionListener(this); Container contentPane = getContentPane(); contentPane.setLayout(new FlowLayout()); contentPane.add(textField); contentPane.add(label); contentPane.add(button); } public void actionPerformed(ActionEvent eve){ label.setText(textField.getText()); } }
- 04-27-2010, 01:26 PM #5
Member
- Join Date
- Apr 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
java binary addition
By rockdude in forum New To JavaReplies: 1Last Post: 03-18-2009, 03:01 PM -
Addition java program
By tabrez_k81 in forum New To JavaReplies: 5Last Post: 12-15-2008, 10:08 AM -
Java Swing JTable Simple Doubt
By hemanthjava in forum AWT / SwingReplies: 1Last Post: 11-26-2008, 01:46 PM -
Simple Addition Program Outputting Wrong Value
By carlodelmundo in forum New To JavaReplies: 4Last Post: 08-05-2008, 03:37 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks