-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathButtonTrackEvent.java
More file actions
77 lines (55 loc) · 1.66 KB
/
ButtonTrackEvent.java
File metadata and controls
77 lines (55 loc) · 1.66 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package gui;
/**
* RUN:
* javac gui/ButtonTrackEvent.java && java gui.ButtonTrackEvent
* OUTPUT:
*
*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import net.mindview.util.*;
public class ButtonTrackEvent extends JFrame {
private static final int WIDTH = 400;
private static final int HEIGHT = 300;
private JButton button = new JButton("Button 0");
private JTextField field = new JTextField(40);
private JTextArea area = new JTextArea(40, 65);
FocusListener fl = new FocusListener() {
public void focusGained(FocusEvent e) {
log(e.paramString());
}
public void focusLost(FocusEvent e) {
log(e.paramString());
}
};
KeyListener kl = new KeyListener() {
public void keyPressed(KeyEvent e) {
log(e.paramString());
}
public void keyReleased(KeyEvent e) {
log(e.paramString());
}
public void keyTyped(KeyEvent e) {
log(e.paramString());
}
};
private void log(String message) {
area.append(message+"\n");
}
public ButtonTrackEvent() {
addComponentsToPane(getContentPane());
}
public void addComponentsToPane(Container pane) {
button.addFocusListener(fl);
button.addKeyListener(kl);
JPanel panel = new JPanel();
panel.add(button);
pane.add(BorderLayout.SOUTH, panel);
pane.add(new JScrollPane(area));
}
public static void main(String[] args) {
SwingConsole.run(new ButtonTrackEvent(), WIDTH, HEIGHT);
}
}