-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLauncher.java
More file actions
92 lines (81 loc) · 2.85 KB
/
Launcher.java
File metadata and controls
92 lines (81 loc) · 2.85 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
84
85
86
87
88
89
90
91
92
import java.applet.Applet;
import java.applet.AppletContext;
import java.applet.AppletStub;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URL;
import javax.swing.JFrame;
public final class Launcher {
private static final int DEFAULT_WIDTH = 800;
private static final int DEFAULT_HEIGHT = 510;
public static void main(String[] args) throws Exception {
System.setProperty("java.awt.headless", "false");
Class<?> clazz = Class.forName("Model2");
Object instance = clazz.getDeclaredConstructor().newInstance();
JFrame frame = new JFrame("LEGI Mechanism");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLayout(new BorderLayout());
if (instance instanceof Applet) {
Applet applet = (Applet) instance;
applet.setStub(new BasicAppletStub());
applet.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
applet.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
frame.add(applet, BorderLayout.CENTER);
frame.pack();
frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
applet.addNotify();
applet.init();
applet.start();
applet.doLayout();
applet.validate();
frame.validate();
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
applet.stop();
applet.destroy();
}
});
} else if (instance instanceof Component) {
Component comp = (Component) instance;
comp.setPreferredSize(new Dimension(DEFAULT_WIDTH, DEFAULT_HEIGHT));
frame.add(comp, BorderLayout.CENTER);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
} else {
throw new IllegalStateException("Model2 is not an Applet or Component");
}
}
private static final class BasicAppletStub implements AppletStub {
@Override
public boolean isActive() {
return true;
}
@Override
public URL getDocumentBase() {
return null;
}
@Override
public URL getCodeBase() {
return null;
}
@Override
public String getParameter(String name) {
return null;
}
@Override
public AppletContext getAppletContext() {
return null;
}
@Override
public void appletResize(int width, int height) {
// Let the frame manage sizing.
}
}
}