-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFramecalculator.java
More file actions
86 lines (84 loc) · 2.82 KB
/
Framecalculator.java
File metadata and controls
86 lines (84 loc) · 2.82 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
import java.awt.*;
import java.awt.event.*;
public class Framecalculator extends Frame implements ActionListener
{
TextField first,second,result;
Button add,sub,mul,div,mod,clear;
Framecalculator()
{
setVisible(true);
setLayout(new GridLayout(6,2));
setTitle("Calculator");
setSize(400,400);
Label firstlabel=new Label("FIRST NO:",Label.LEFT);
Label secondlabel=new Label("SECOND NO:",Label.LEFT);
Label thirdlabel=new Label("RESULT",Label.LEFT);
first=new TextField();
second=new TextField();
result=new TextField("");result.setEditable(false);
add(firstlabel);add(first);add(secondlabel);add(second);add(thirdlabel);add(result);
add=new Button("ADD");sub=new Button("SUB");mul=new Button("MUL");div=new Button("DIV");
mod=new Button("MOD");clear=new Button("CLEAR");
add(add);add(sub);add(mul);add(div);add(mod);add(clear);
first.addActionListener(this);
second.addActionListener(this);
result.addActionListener(this);
add.addActionListener(this);
sub.addActionListener(this);
mul.addActionListener(this);
div.addActionListener(this);
mod.addActionListener(this);
clear.addActionListener(this);
mywindowadapter w=new mywindowadapter(this);addWindowListener(w);
}
public class mywindowadapter extends WindowAdapter
{
Framecalculator framecalculator;
mywindowadapter (Framecalculator framecalculator)
{
this.framecalculator=framecalculator;
}
public void windowClosing(WindowEvent we)
{
framecalculator.setVisible(false);
}
}
public void actionPerformed(ActionEvent ae)
{
String str=ae.getActionCommand();
int a,b;double r;
if(str.equals("ADD"))
{
a=Integer.parseInt(first.getText());b=Integer.parseInt(second.getText());
r=a+b;result.setText(Double.toString(r));
}
else if(str.equals("SUB"))
{
a=Integer.parseInt(first.getText());b=Integer.parseInt(second.getText());
r=a-b;result.setText(Double.toString(r));
}
else if(str.equals("MUL"))
{
a=Integer.parseInt(first.getText());b=Integer.parseInt(second.getText());
r=a*b;result.setText(Double.toString(r));
}
else if(str.equals("DIV"))
{
a=Integer.parseInt(first.getText());b=Integer.parseInt(second.getText());
r=a/b;result.setText(Double.toString(r));
}
else if(str.equals("MOD"))
{
a=Integer.parseInt(first.getText());b=Integer.parseInt(second.getText());
r=a%b;result.setText(Double.toString(r));
}
else
{
first.setText("");second.setText("");result.setText("");
}
}
public static void main(String args[])
{
Framecalculator A=new Framecalculator();
}
}