-
Notifications
You must be signed in to change notification settings - Fork 1
/
Launcher.java
83 lines (72 loc) · 2.01 KB
/
Launcher.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
import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
@SuppressWarnings("serial")
public class Launcher extends JFrame implements ComponentListener
{
private boolean startFullScreen;
private boolean defaultLookAndFeel;
private float widthRatio;
private float heightRatio;
private Dimension size;
private JPanel currentScene;
public static void main(String[] args) throws InterruptedException
{
Voter.loadData();
Candidate.loadInitData();
new Launcher();
}
public Launcher() throws InterruptedException
{
size = Toolkit.getDefaultToolkit().getScreenSize();
widthRatio = 2/3f;
heightRatio = 2/3f;
startFullScreen = false;
defaultLookAndFeel = true;
if(!defaultLookAndFeel)
{
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
}
this.setSize((int)(size.getWidth()*widthRatio),(int)(size.getHeight()*heightRatio));
if(startFullScreen)
{
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(true);
this.setLocationRelativeTo(null);
this.addComponentListener(this);
currentScene = new HomeView(this);
currentScene.setPreferredSize(new Dimension(500,500));
this.add(currentScene);
this.setVisible(true);
}
//Each class will be passed an object of this driver so it can call this method and pass it the next window
public void switchScene(JPanel p)
{
this.remove(currentScene);
currentScene = p;
this.add(currentScene);
this.setVisible(true);
this.repaint();
}
@Override
public void componentResized(ComponentEvent arg0)
{
currentScene.repaint();
}
@Override
public void componentHidden(ComponentEvent arg0) {}
@Override
public void componentMoved(ComponentEvent arg0) {}
@Override
public void componentShown(ComponentEvent arg0) {}
}