-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventDemo.java
52 lines (37 loc) · 1.11 KB
/
EventDemo.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
41
42
43
44
45
46
47
48
49
50
51
52
package GamingPortal;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class EventDemo {
JLabel jl;
EventDemo() {
JFrame jf = new JFrame("An Event Example");
jf.setLayout(new FlowLayout());
jf.setSize(220, 90);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton jb1 = new JButton("Alpha");
JButton jb2 = new JButton("Beta");
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
jl.setText("Alpha is Pressed");
}
});
jb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
jl.setText("Beta is pressed");
}
});
jf.add(jb1);
jf.add(jb2);
jl = new JLabel("Press a Button");
jf.add(jl);
jf.setVisible(true);
}
public static void main(String args[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new EventDemo();
}
});
}
}