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