-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainFrame.java
47 lines (40 loc) · 1.14 KB
/
MainFrame.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
/**
* @version 1.0.0, 8 May 2023
* @author Dylan Nguyen and Andrew Kim
*/
import java.awt.Dimension;
import java.awt.event.*;
import javax.swing.*;
public class MainFrame extends JFrame {
public MainFrame() {
loadConfig();
setVisible(true);
}
/**
* Loads the configuration for the frame
*/
public void loadConfig() {
setTitle("SSS: Stock Simulator on Steroids by Andrew Kim and Dylan Nguyen");
setMinimumSize(new Dimension(700, 600));
// https://stackoverflow.com/questions/6084039/create-custom-operation-for-setdefaultcloseoperation
WindowListener listener = new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// wait until safe to close
while (!Options.isSafeToClose() || !Broker.isSafeToClose()) {
System.out.println("Unsafe!");
try {
Thread.sleep(10);
} catch (InterruptedException e1) {
/* nyeh! */}
}
System.exit(0);
}
};
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
addWindowListener(listener);
}
public void setWindowTitle(String title) {
setTitle("SSS: Stock Simulator on Steroids by Andrew Kim and Dylan Nguyen - " + title);
}
}