1:
37:
38:
39: package ;
40:
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50: import ;
51: import ;
52:
53:
58: public class JApplet extends Applet
59: implements RootPaneContainer, Accessible
60: {
61:
64: protected class AccessibleJApplet extends Applet.AccessibleApplet
65: {
66:
69: public AccessibleJApplet()
70: {
71: super();
72:
73: }
74: }
75:
76:
79: protected AccessibleContext accessibleContext;
80:
81: private static final long serialVersionUID = 7269359214497372587L;
82:
83: protected JRootPane rootPane;
84:
85:
88: protected boolean rootPaneCheckingEnabled=false;
89:
90:
95: private boolean initStageDone = false;
96:
97: public JApplet()
98: {
99: super.setLayout(new BorderLayout(1, 1));
100: getRootPane();
101: initStageDone = true;
102: }
103:
104: public Dimension getPreferredSize()
105: {
106: return super.getPreferredSize();
107: }
108:
109: public void setLayout(LayoutManager manager)
110: {
111:
112:
113: if (initStageDone)
114: {
115: if (isRootPaneCheckingEnabled())
116: throw new Error("Cannot set layout. Use getContentPane().setLayout()"
117: + "instead.");
118: getContentPane().setLayout(manager);
119: }
120: else
121: super.setLayout(manager);
122: }
123:
124: public void setLayeredPane(JLayeredPane layeredPane)
125: {
126: getRootPane().setLayeredPane(layeredPane);
127: }
128:
129: public JLayeredPane getLayeredPane()
130: {
131: return getRootPane().getLayeredPane();
132: }
133:
134: public JRootPane getRootPane()
135: {
136: if (rootPane == null)
137: setRootPane(createRootPane());
138: return rootPane;
139: }
140:
141: protected void setRootPane(JRootPane root)
142: {
143: if (rootPane != null)
144: remove(rootPane);
145:
146: rootPane = root;
147: add(rootPane, BorderLayout.CENTER);
148: }
149:
150: protected JRootPane createRootPane()
151: {
152: return new JRootPane();
153: }
154:
155: public Container getContentPane()
156: {
157: return getRootPane().getContentPane();
158: }
159:
160: public void setContentPane(Container contentPane)
161: {
162: getRootPane().setContentPane(contentPane);
163: }
164:
165: public Component getGlassPane()
166: {
167: return getRootPane().getGlassPane();
168: }
169:
170: public void setGlassPane(Component glassPane)
171: {
172: getRootPane().setGlassPane(glassPane);
173: }
174:
175: protected void addImpl(Component comp, Object constraints, int index)
176: {
177:
178:
179: if (!initStageDone)
180: super.addImpl(comp, constraints, index);
181: else
182: {
183: if (isRootPaneCheckingEnabled())
184: throw new Error("Do not use add() on JApplet directly. Use "
185: + "getContentPane().add() instead");
186: getContentPane().add(comp, constraints, index);
187: }
188: }
189:
190: public AccessibleContext getAccessibleContext()
191: {
192: if (accessibleContext == null)
193: accessibleContext = new AccessibleJApplet();
194: return accessibleContext;
195: }
196:
197: public JMenuBar getJMenuBar()
198: {
199: return getRootPane().getJMenuBar();
200: }
201:
202: public void setJMenuBar(JMenuBar menubar)
203: {
204: getRootPane().setJMenuBar(menubar);
205: }
206:
207: protected String paramString()
208: {
209: return "JFrame";
210: }
211:
212: protected void processKeyEvent(KeyEvent e)
213: {
214: super.processKeyEvent(e);
215: }
216:
217: public void remove(Component comp)
218: {
219:
220:
221: if (comp == rootPane)
222: super.remove(rootPane);
223: else
224: getContentPane().remove(comp);
225: }
226:
227: protected boolean isRootPaneCheckingEnabled()
228: {
229: return rootPaneCheckingEnabled;
230: }
231:
232: protected void setRootPaneCheckingEnabled(boolean enabled)
233: {
234: rootPaneCheckingEnabled = enabled;
235: }
236:
237: public void update(Graphics g)
238: {
239: paint(g);
240: }
241: }