-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathButtonExample.java
More file actions
38 lines (34 loc) · 969 Bytes
/
ButtonExample.java
File metadata and controls
38 lines (34 loc) · 969 Bytes
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
import java.awt.*;
import java.awt.event.*;
public class ButtonExample {
public static void main(String[] args) {
Frame f=new Frame("Button Example");
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);}});
TextField tf=new TextField();
tf.setBounds(50,50, 150,20);
Button b=new Button("Click Here");
b.setBounds(50,100,60,30);
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf.setText("Welcome SIR");
f.setBackground(Color.GREEN);
Frame f2=new Frame();
f2.setSize(250,200);
Button b1=new Button("CLOSE");
b1.setBounds(50,100,60,30);
b1.setBackground(Color.RED);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
f2.setVisible(false);
}});
f2.add(b1);
f2.setVisible(true);
}});
f.add(b);f.add(tf);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
}