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