0% found this document useful (0 votes)
5 views2 pages

Java Swing Addition App Example

Uploaded by

noyohen336
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Java Swing Addition App Example

Uploaded by

noyohen336
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Practical No.

22 JTextField resultField = new


JTextField();
4.) import [Link].*;
[Link](50, 110,
import [Link].*;
100, 30);
[Link](false);
public class AdditionApp {
[Link](resultField);
public static void main(String[]
args) {
JButton addButton = new
JFrame frame = new
JButton("Add");
JFrame("Addition of Two
Numbers"); [Link](160, 50,
80, 30);
[Link](JFr [Link](addButton);
ame.EXIT_ON_CLOSE);
[Link](300, 200);
[Link](null); [Link](new
ActionListener() {
public void
JTextField num1Field = new
actionPerformed(ActionEvent e) {
JTextField();
try {
[Link](50, 30,
100, 30); double num1 =
[Link]([Link]
[Link](num1Field);
Text());
double num2 =
JTextField num2Field = new [Link]([Link]
JTextField(); Text());
[Link](50, 70, double result = num1 +
100, 30); num2;
[Link](num2Field);
[Link]([Link](re
sult));
} catch
(NumberFormatException ex) {

[Link](fr
ame, "Please enter valid numbers.",
"Error",
JOptionPane.ERROR_MESSAGE);
}
}
});

[Link](true);
}
}

You might also like