-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGui3.java
More file actions
59 lines (46 loc) · 1.45 KB
/
Copy pathGui3.java
File metadata and controls
59 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package Lab4;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Gui3 extends JFrame
{
JTextField jta1 = new JTextField(10);
JTextField jta2 = new JTextField(10);
JButton button = new JButton("Add them up");
Font fnt = new Font("Arial",Font.BOLD,11);
Gui3()
{
super("Example");
setLayout(new FlowLayout());
setSize(300,150);
add(new JLabel("1st Number"));
add(jta1);
add(new JLabel("2nd Number"));
add(jta2);
add(button);
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent
ae)
{
try
{
double x1 =
Double.parseDouble(jta1.getText().trim());
double x2 =
Double.parseDouble(jta2.getText().trim());
JOptionPane.showMessageDialog(null, "Result = "+(x1+x2),"Alert",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "Error in Numbers!","alert" , JOptionPane.ERROR_MESSAGE);
}
}
});
setVisible(true);
}
public static void main(String[]args)
{
new Gui3();
}
}