1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52:
53: import ;
54:
55:
61: public class JFrame extends Frame
62: implements WindowConstants, RootPaneContainer
63: {
64: private static final long serialVersionUID = -3362141868504252139L;
65: private static boolean defaultLookAndFeelDecorated;
66: private int close_action = HIDE_ON_CLOSE;
67: protected AccessibleContext accessibleContext;
68: protected JRootPane rootPane;
69:
70:
73: protected boolean rootPaneCheckingEnabled = false;
74:
75:
80: private boolean initStageDone = false;
81:
82: public JFrame()
83: {
84: super("JFrame");
85: frameInit();
86: }
87:
88: public JFrame(String title)
89: {
90: super(title);
91: frameInit();
92: }
93:
94:
103: public JFrame(GraphicsConfiguration gc)
104: {
105: super(gc);
106: frameInit();
107: }
108:
109:
119: public JFrame(String title, GraphicsConfiguration gc)
120: {
121: super(title, gc);
122: frameInit();
123: }
124:
125: protected void frameInit()
126: {
127: super.setLayout(new BorderLayout(1, 1));
128: enableEvents(AWTEvent.WINDOW_EVENT_MASK);
129: getRootPane();
130:
131: initStageDone = true;
132: }
133:
134: public Dimension getPreferredSize()
135: {
136: return super.getPreferredSize();
137: }
138:
139: public JMenuBar getJMenuBar()
140: {
141: return getRootPane().getJMenuBar();
142: }
143:
144: public void setJMenuBar(JMenuBar menubar)
145: {
146: getRootPane().setJMenuBar(menubar);
147: }
148:
149: public void setLayout(LayoutManager manager)
150: {
151:
152:
153: if (initStageDone)
154: {
155: if (isRootPaneCheckingEnabled())
156: throw new Error("Cannot set layout. Use getContentPane().setLayout()"
157: + " instead.");
158: getContentPane().setLayout(manager);
159: }
160: else
161: super.setLayout(manager);
162: }
163:
164: public void setLayeredPane(JLayeredPane layeredPane)
165: {
166: getRootPane().setLayeredPane(layeredPane);
167: }
168:
169: public JLayeredPane getLayeredPane()
170: {
171: return getRootPane().getLayeredPane();
172: }
173:
174: public JRootPane getRootPane()
175: {
176: if (rootPane == null)
177: setRootPane(createRootPane());
178: return rootPane;
179: }
180:
181: protected void setRootPane(JRootPane root)
182: {
183: if (rootPane != null)
184: remove(rootPane);
185:
186: rootPane = root;
187: add(rootPane, BorderLayout.CENTER);
188: }
189:
190: protected JRootPane createRootPane()
191: {
192: return new JRootPane();
193: }
194:
195: public Container getContentPane()
196: {
197: return getRootPane().getContentPane();
198: }
199:
200: public void setContentPane(Container contentPane)
201: {
202: getRootPane().setContentPane(contentPane);
203: }
204:
205: public Component getGlassPane()
206: {
207: return getRootPane().getGlassPane();
208: }
209:
210: public void setGlassPane(Component glassPane)
211: {
212: getRootPane().setGlassPane(glassPane);
213: }
214:
215: protected void addImpl(Component comp, Object constraints, int index)
216: {
217:
218:
219: if (!initStageDone)
220: super.addImpl(comp, constraints, index);
221: else
222: {
223: if (isRootPaneCheckingEnabled())
224: throw new Error("rootPaneChecking is enabled - adding components "
225: + "disallowed.");
226: getContentPane().add(comp,constraints,index);
227: }
228: }
229:
230: public void remove(Component comp)
231: {
232:
233:
234: if (comp==rootPane)
235: super.remove(rootPane);
236: else
237: getContentPane().remove(comp);
238: }
239:
240: protected boolean isRootPaneCheckingEnabled()
241: {
242: return rootPaneCheckingEnabled;
243: }
244:
245: protected void setRootPaneCheckingEnabled(boolean enabled)
246: {
247: rootPaneCheckingEnabled = enabled;
248: }
249:
250: public void update(Graphics g)
251: {
252: paint(g);
253: }
254:
255: protected void processKeyEvent(KeyEvent e)
256: {
257: super.processKeyEvent(e);
258: }
259:
260: public static void setDefaultLookAndFeelDecorated(boolean decorated)
261: {
262: defaultLookAndFeelDecorated = decorated;
263: }
264:
265: public static boolean isDefaultLookAndFeelDecorated()
266: {
267: return defaultLookAndFeelDecorated;
268: }
269:
270: public AccessibleContext getAccessibleContext()
271: {
272: return accessibleContext;
273: }
274:
275: public int getDefaultCloseOperation()
276: {
277: return close_action;
278: }
279:
280: protected String paramString()
281: {
282: return "JFrame";
283: }
284:
285: protected void processWindowEvent(WindowEvent e)
286: {
287: super.processWindowEvent(e);
288: switch (e.getID())
289: {
290: case WindowEvent.WINDOW_CLOSING:
291: {
292: switch (close_action)
293: {
294: case EXIT_ON_CLOSE:
295: {
296: System.exit(0);
297: break;
298: }
299: case DISPOSE_ON_CLOSE:
300: {
301: dispose();
302: break;
303: }
304: case HIDE_ON_CLOSE:
305: {
306: setVisible(false);
307: break;
308: }
309: case DO_NOTHING_ON_CLOSE:
310: break;
311: }
312: break;
313: }
314: case WindowEvent.WINDOW_CLOSED:
315: case WindowEvent.WINDOW_OPENED:
316: case WindowEvent.WINDOW_ICONIFIED:
317: case WindowEvent.WINDOW_DEICONIFIED:
318: case WindowEvent.WINDOW_ACTIVATED:
319: case WindowEvent.WINDOW_DEACTIVATED:
320: break;
321: }
322: }
323:
324:
337: public void setDefaultCloseOperation(int operation)
338: {
339: SecurityManager sm = System.getSecurityManager();
340: if (sm != null && operation == EXIT_ON_CLOSE)
341: sm.checkExit(0);
342:
343: if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE
344: && operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE)
345: throw new IllegalArgumentException("defaultCloseOperation must be EXIT_ON_CLOSE, HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or DO_NOTHING_ON_CLOSE");
346:
347: close_action = operation;
348: }
349: }