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:
52:
57: public class JApplet extends Applet
58: implements RootPaneContainer
59: {
60: private static final long serialVersionUID = 7269359214497372587L;
61:
62: protected JRootPane rootPane;
63:
64:
67: protected boolean rootPaneCheckingEnabled=false;
68:
69:
74: private boolean initStageDone = false;
75:
76: public JApplet()
77: {
78: super.setLayout(new BorderLayout(1, 1));
79: getRootPane();
80: initStageDone = true;
81: }
82:
83: public Dimension getPreferredSize()
84: {
85: return super.getPreferredSize();
86: }
87:
88: public void setLayout(LayoutManager manager)
89: {
90:
91:
92: if (initStageDone)
93: {
94: if (isRootPaneCheckingEnabled())
95: throw new Error("Cannot set layout. Use getContentPane().setLayout()"
96: + "instead.");
97: getContentPane().setLayout(manager);
98: }
99: else
100: super.setLayout(manager);
101: }
102:
103: public void setLayeredPane(JLayeredPane layeredPane)
104: {
105: getRootPane().setLayeredPane(layeredPane);
106: }
107:
108: public JLayeredPane getLayeredPane()
109: {
110: return getRootPane().getLayeredPane();
111: }
112:
113: public JRootPane getRootPane()
114: {
115: if (rootPane == null)
116: setRootPane(createRootPane());
117: return rootPane;
118: }
119:
120: protected void setRootPane(JRootPane root)
121: {
122: if (rootPane != null)
123: remove(rootPane);
124:
125: rootPane = root;
126: add(rootPane, BorderLayout.CENTER);
127: }
128:
129: protected JRootPane createRootPane()
130: {
131: return new JRootPane();
132: }
133:
134: public Container getContentPane()
135: {
136: return getRootPane().getContentPane();
137: }
138:
139: public void setContentPane(Container contentPane)
140: {
141: getRootPane().setContentPane(contentPane);
142: }
143:
144: public Component getGlassPane()
145: {
146: return getRootPane().getGlassPane();
147: }
148:
149: public void setGlassPane(Component glassPane)
150: {
151: getRootPane().setGlassPane(glassPane);
152: }
153:
154: protected void addImpl(Component comp, Object constraints, int index)
155: {
156:
157:
158: if (!initStageDone)
159: super.addImpl(comp, constraints, index);
160: else
161: {
162: if (isRootPaneCheckingEnabled())
163: throw new Error("Do not use add() on JApplet directly. Use "
164: + "getContentPane().add() instead");
165: getContentPane().add(comp, constraints, index);
166: }
167: }
168:
169: public AccessibleContext getAccessibleContext()
170: {
171: return null;
172: }
173:
174: public JMenuBar getJMenuBar()
175: {
176: return getRootPane().getJMenuBar();
177: }
178:
179: public void setJMenuBar(JMenuBar menubar)
180: {
181: getRootPane().setJMenuBar(menubar);
182: }
183:
184: protected String paramString()
185: {
186: return "JFrame";
187: }
188:
189: protected void processKeyEvent(KeyEvent e)
190: {
191: super.processKeyEvent(e);
192: }
193:
194: public void remove(Component comp)
195: {
196:
197:
198: if (comp == rootPane)
199: super.remove(rootPane);
200: else
201: getContentPane().remove(comp);
202: }
203:
204: protected boolean isRootPaneCheckingEnabled()
205: {
206: return rootPaneCheckingEnabled;
207: }
208:
209: protected void setRootPaneCheckingEnabled(boolean enabled)
210: {
211: rootPaneCheckingEnabled = enabled;
212: }
213:
214: public void update(Graphics g)
215: {
216: paint(g);
217: }
218: }