-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab25.java
More file actions
101 lines (95 loc) · 2.69 KB
/
Copy pathjavalab25.java
File metadata and controls
101 lines (95 loc) · 2.69 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.PrivateKey;
import javax.swing.*;
import java.util.Scanner;
class myCalculator extends JFrame implements ActionListener{
private JTextField t1;
private JTextField t2;
private JTextField t3;
private JButton b1;
private JButton b2;
private JButton b3;
private JButton b4;
private JButton b5;
private JButton b6;
public myCalculator(){
createView();
setTitle("Vowel COunter");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 400);
setLocationRelativeTo(null);
setResizable(true);
setVisible(true);
}
private void createView(){
JPanel panel = new JPanel();
getContentPane().add(panel);
panel.setLayout(new GridLayout(6,1,5,5));
JLabel l1 = new JLabel("Number 1: ");
t1 = new JTextField(100);
JLabel l2 = new JLabel("Number 2: ");
t2 = new JTextField(100);
JLabel l3 = new JLabel("Result: ");
t3 = new JTextField(100);
b1 = new JButton("+");
b2 = new JButton("-");
b3 = new JButton("*");
b4 = new JButton("/");
b5 = new JButton("Reset");
b6 = new JButton("Exit");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
panel.add(l1);
panel.add(t1);
panel.add(l2);
panel.add(t2);
panel.add(l3);
panel.add(t3);
panel.add(b1);
panel.add(b2);
panel.add(b3);
panel.add(b4);
panel.add(b5);
panel.add(b6);
}
public void actionPerformed(ActionEvent ae){
int n1 = Integer.parseInt(t1.getText());
int n2 = Integer.parseInt(t2.getText());
int res;
if(ae.getSource()==b1){
res = n1 + n2;
t3.setText(res + "");
}
else if(ae.getSource()==b2){
res = n1 - n2;
t3.setText(res + "");
}
else if(ae.getSource()==b3){
res = n1 * n2;
t3.setText(res + "");
}
else if(ae.getSource()==b4){
t3.setText((double)(n1/n2) + "");
}
else if(ae.getSource()==b5){
t1.setText("");
t2.setText("");
t3.setText("");
t1.requestFocus();
}
else if(ae.getSource()==b6){
System.exit(0);
}
}
}
public class javalab25 {
public static void main(String[] args) {
myCalculator ob = new myCalculator();
}
}