-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwingPaint.java
More file actions
83 lines (72 loc) · 1.94 KB
/
SwingPaint.java
File metadata and controls
83 lines (72 loc) · 1.94 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
79
80
81
82
83
package csg;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SwingPaint extends JFrame implements KeyListener, ActionListener {
JTextArea displayArea;
JTextField typingArea;
static MainPanel mainPanel;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
public SwingPaint(String name) {
super(name);
}
private static void createAndShowGUI() {
SwingPaint f = new SwingPaint("CSG Demo");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setResizable(false);
mainPanel = new MainPanel();
f.add(mainPanel);
f.addComponentsToPane();
f.pack();
f.setVisible(true);
}
private void addComponentsToPane() {
typingArea = new JTextField(20);
typingArea.addKeyListener(this);
typingArea.setFocusTraversalKeysEnabled(false);
getContentPane().add(typingArea, BorderLayout.PAGE_START);
}
public void keyTyped(KeyEvent e) {
if (!mainPanel.addShape(e.getKeyChar()))
mainPanel.setOp(e.getKeyChar());
typingArea.setText("");
}
public void keyPressed(KeyEvent e) {
int keyCode = e.getKeyCode();
switch (keyCode) {
case 8: // DEL
mainPanel.pop();
break;
case 9: // TAB
mainPanel.next();
break;
case 32: // space
mainPanel.corner();
break;
case KeyEvent.VK_UP:
mainPanel.up();
break;
case KeyEvent.VK_DOWN:
mainPanel.down();
break;
case KeyEvent.VK_LEFT:
mainPanel.left();
break;
case KeyEvent.VK_RIGHT:
mainPanel.right();
break;
}
}
public void keyReleased(KeyEvent e) {
}
public void actionPerformed(ActionEvent e) {
typingArea.setText("");
typingArea.requestFocusInWindow();
}
}