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