forked from JFulgoni/Java-Practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.java
More file actions
78 lines (63 loc) · 1.52 KB
/
Copy pathGUI.java
File metadata and controls
78 lines (63 loc) · 1.52 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
78
package john_test;
import java.awt.BorderLayout;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
public class GUI implements KeyListener, Runnable{
private JFrame myFrame;
private JLabel myText;
private boolean done;
private int displayNum;
public GUI(){
done = false;
displayNum = 0;
myFrame = new JFrame("Test GUI");
initialize();
}
public void run(){
while(!done){
update();
}
}
public void update(){
myText.setText(String.valueOf(displayNum));
myFrame.getContentPane().add(myText, BorderLayout.CENTER);
}
public void initialize(){
myFrame.setVisible(true);
myFrame.setBounds(300, 200, 700, 400);
myText = new JLabel("I'm a label in the window",
SwingConstants.CENTER);
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
if(e.getKeyCode() == KeyEvent.VK_C){
done = true;
}
else{
++displayNum;
}
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
public static void main(String[] args){
// javax.swing.SwingUtilities.invokeLater(new Runnable() {
// public void run() {
// GUI frame = new GUI();
// frame.initialize();
// }
// });
GUI frame = new GUI();
//frame.initialize();
frame.run();
}
}