-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathController.java
85 lines (61 loc) · 2.37 KB
/
Controller.java
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
84
85
import javax.swing.SwingUtilities;
import java.awt.*;
public class Controller {
private SettingsFrame settingsFrame;
private ToolsFrame toolsFrame;
private PaintFrame paintFrame;
private Controller controller;
private static Controller instance;
private int mouseX, mouseY;
private Color targetColor;
public Controller( PaintFrame paintFrame, SettingsFrame settingsFrame) {
toolsFrame = new ToolsFrame(this, paintFrame);
this.settingsFrame = settingsFrame;
this.paintFrame = paintFrame;
settingsFrame.setVisible(true);
settingsFrame.getContinueButton().addActionListener(e -> {
int width = settingsFrame.getEnteredWidth();
int height = settingsFrame.getEnteredHeight();
if (width > 0 && height > 0) {
openDrawingFrames(width, height);
}
});
}
public void setTargetColor(Color color) {
this.targetColor = color;
}
private void openDrawingFrames(int width, int height) {
paintFrame.initializeCanvas(width, height);
paintFrame.setSize(width, height);
toolsFrame.setVisible(true);
paintFrame.setVisible(true);
settingsFrame.setVisible(false);
}
public void changePenSize(int size) {
paintFrame.setPenSize(size);
}
public static Controller getInstance(PaintFrame paintFrame, SettingsFrame settingsFrame) {
if (instance == null) {
instance = new Controller(paintFrame, settingsFrame);
}
return instance;
}
public void changePenColor(Color chosenColor) {
if (paintFrame != null) {
paintFrame.setPenColor(chosenColor);
}
}
public static void main(String[] args) {
PaintFrame paintFrame = new PaintFrame();
SettingsFrame settingsFrame = new SettingsFrame();
Controller controller = Controller.getInstance(paintFrame, settingsFrame);
System.out.println("Controller in MainApplication: " + controller);
ToolsFrame toolsFrame = new ToolsFrame(controller, paintFrame);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new Controller(paintFrame, settingsFrame);
}
});
}
}