-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBtnDemo3.java
40 lines (40 loc) · 868 Bytes
/
BtnDemo3.java
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
//To find greatest of two numbers using button
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="BtnDemo3" width=100 height=100></applet>*/
public class BtnDemo3 extends Applet implements ActionListener
{
Label l1,l2,l3;
TextField t1,t2,t3;
Button b;
public void init()
{
l1=new Label("Number 1");
l2=new Label("Number 2");
l3=new Label("Greatest of two");
t1=new TextField(10);
t2=new TextField(10);
t3=new TextField(10);
b=new Button("Find greatest");
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
int n1=Integer.parseInt(t1.getText());
int n2=Integer.parseInt(t2.getText());
int gr_no;
if(n1>n2)
gr_no=n1;
else
gr_no=n2;
t3.setText(""+gr_no);
}
}