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: protected 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:
155: if (isDefaultLookAndFeelDecorated()
156: && UIManager.getLookAndFeel().getSupportsWindowDecorations())
157: {
158: setUndecorated(true);
159: getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
160: }
161:
162:
163: setRootPaneCheckingEnabled(true);
164: }
165:
166: public Dimension getPreferredSize()
167: {
168: return super.getPreferredSize();
169: }
170:
171: public JMenuBar getJMenuBar()
172: {
173: return getRootPane().getJMenuBar();
174: }
175:
176: public void setJMenuBar(JMenuBar menubar)
177: {
178: getRootPane().setJMenuBar(menubar);
179: }
180:
181: public void setLayout(LayoutManager manager)
182: {
183:
184:
185: if (isRootPaneCheckingEnabled())
186: getContentPane().setLayout(manager);
187: else
188: super.setLayout(manager);
189: }
190:
191: public void setLayeredPane(JLayeredPane layeredPane)
192: {
193: getRootPane().setLayeredPane(layeredPane);
194: }
195:
196: public JLayeredPane getLayeredPane()
197: {
198: return getRootPane().getLayeredPane();
199: }
200:
201: public JRootPane getRootPane()
202: {
203: if (rootPane == null)
204: setRootPane(createRootPane());
205: return rootPane;
206: }
207:
208: protected void setRootPane(JRootPane root)
209: {
210: if (rootPane != null)
211: remove(rootPane);
212:
213: rootPane = root;
214: add(rootPane, BorderLayout.CENTER);
215: }
216:
217: protected JRootPane createRootPane()
218: {
219: return new JRootPane();
220: }
221:
222: public Container getContentPane()
223: {
224: return getRootPane().getContentPane();
225: }
226:
227: public void setContentPane(Container contentPane)
228: {
229: getRootPane().setContentPane(contentPane);
230: }
231:
232: public Component getGlassPane()
233: {
234: return getRootPane().getGlassPane();
235: }
236:
237: public void setGlassPane(Component glassPane)
238: {
239: getRootPane().setGlassPane(glassPane);
240: }
241:
242: protected void addImpl(Component comp, Object constraints, int index)
243: {
244:
245:
246: if (isRootPaneCheckingEnabled())
247: getContentPane().add(comp,constraints,index);
248: else
249: super.addImpl(comp, constraints, index);
250: }
251:
252: public void remove(Component comp)
253: {
254:
255:
256: if (comp==rootPane)
257: super.remove(rootPane);
258: else
259: getContentPane().remove(comp);
260: }
261:
262: protected boolean isRootPaneCheckingEnabled()
263: {
264: return rootPaneCheckingEnabled;
265: }
266:
267: protected void setRootPaneCheckingEnabled(boolean enabled)
268: {
269: rootPaneCheckingEnabled = enabled;
270: }
271:
272: public void update(Graphics g)
273: {
274: paint(g);
275: }
276:
277: protected void processKeyEvent(KeyEvent e)
278: {
279: super.processKeyEvent(e);
280: }
281:
282: public static void setDefaultLookAndFeelDecorated(boolean decorated)
283: {
284: defaultLookAndFeelDecorated = decorated;
285: }
286:
287: public static boolean isDefaultLookAndFeelDecorated()
288: {
289: return defaultLookAndFeelDecorated;
290: }
291:
292: public AccessibleContext getAccessibleContext()
293: {
294: if (accessibleContext == null)
295: accessibleContext = new AccessibleJFrame();
296: return accessibleContext;
297: }
298:
299: public int getDefaultCloseOperation()
300: {
301: return close_action;
302: }
303:
304: protected String paramString()
305: {
306: return "JFrame";
307: }
308:
309: protected void processWindowEvent(WindowEvent e)
310: {
311: super.processWindowEvent(e);
312: switch (e.getID())
313: {
314: case WindowEvent.WINDOW_CLOSING:
315: {
316: switch (close_action)
317: {
318: case EXIT_ON_CLOSE:
319: {
320: System.exit(0);
321: break;
322: }
323: case DISPOSE_ON_CLOSE:
324: {
325: dispose();
326: break;
327: }
328: case HIDE_ON_CLOSE:
329: {
330: setVisible(false);
331: break;
332: }
333: case DO_NOTHING_ON_CLOSE:
334: break;
335: }
336: break;
337: }
338: case WindowEvent.WINDOW_CLOSED:
339: case WindowEvent.WINDOW_OPENED:
340: case WindowEvent.WINDOW_ICONIFIED:
341: case WindowEvent.WINDOW_DEICONIFIED:
342: case WindowEvent.WINDOW_ACTIVATED:
343: case WindowEvent.WINDOW_DEACTIVATED:
344: break;
345: }
346: }
347:
348:
361: public void setDefaultCloseOperation(int operation)
362: {
363: SecurityManager sm = System.getSecurityManager();
364: if (sm != null && operation == EXIT_ON_CLOSE)
365: sm.checkExit(0);
366:
367: if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE
368: && operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE)
369: throw new IllegalArgumentException("defaultCloseOperation must be EXIT_ON_CLOSE, HIDE_ON_CLOSE, DISPOSE_ON_CLOSE, or DO_NOTHING_ON_CLOSE");
370:
371: close_action = operation;
372: }
373: }