-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextFieldTry.java
More file actions
50 lines (49 loc) · 1.14 KB
/
TextFieldTry.java
File metadata and controls
50 lines (49 loc) · 1.14 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
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class TextFieldTry extends Applet implements ActionListener{
int ans = 0;
TextField t1 = new TextField(10);
TextField t2 = new TextField(10);
public void init() {
Button b1 = new Button("+");
Button b2 = new Button("-");
Button b3 = new Button("*");
Button b4 = new Button("/");
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
b4.addActionListener(this);
add(new Label("ENTER A : "));
add(t1);
add(new Label("ENTER B : "));
add(t2);
add(b1);
add(b2);
add(b3);
add(b4);
}
public void paint(Graphics g) {
g.drawString("ANS = " + ans, 20, 100);
}
public void actionPerformed(ActionEvent ae) {
int a = Integer.parseInt(t1.getText());
int b = Integer.parseInt(t2.getText());
if(ae.getActionCommand() == "+") {
ans = a + b;
repaint();
}
if(ae.getActionCommand() == "-") {
ans = a - b;
repaint();
}
if(ae.getActionCommand() == "*") {
ans = a * b;
repaint();
}
if(ae.getActionCommand() == "/") {
ans = a / b;
repaint();
}
}
}