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