-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathButton3.java
More file actions
44 lines (36 loc) · 1003 Bytes
/
Button3.java
File metadata and controls
44 lines (36 loc) · 1003 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
39
40
41
42
43
44
package gui;
/**
* RUN:
* javac gui/Button3.java && java gui.Button3
* OUTPUT:
*
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import net.mindview.util.*;
public class Button3 extends JFrame {
private JButton b1 = new JButton("Button 1");
private JButton b2 = new JButton("Button 2");
private JButton b3 = new JButton("Button 3");
private JTextField txt = new JTextField(10);
private ActionListener bl = new ActionListener() {
public void actionPerformed(ActionEvent e) {
String name = ((JButton)e.getSource()).getText();
txt.setText(name);
}
};
public Button3() {
b1.addActionListener(bl);
b2.addActionListener(bl);
b3.addActionListener(bl);
setLayout(new FlowLayout());
add(b1);
add(b2);
add(b3);
add(txt);
}
public static void main(String[] args) {
SwingConsole.run(new Button3(), 200, 150);
}
}