156 * Button aButton = new Button(); 157 * 158 * static class MyActionListener implements ActionListener 159 * { 160 * public void actionPerformed(ActionEvent e) 161 * { 162 * System.out.println("Hello There"); 163 * } 164 * } 165 * 166 * MyApp() 167 * { 168 * aButton.addActionListener(new MyActionListener()); 169 * } 170 * } 171 * </pre> 172 * <p> 173 * <b>Note</b>: For more information on the paint mechanisms utilitized 174 * by AWT and Swing, including information on how to write the most 175 * efficient painting code, see 176 * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. 177 * <p> 178 * For details on the focus subsystem, see 179 * <a href="http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html"> 180 * How to Use the Focus Subsystem</a>, 181 * a section in <em>The Java Tutorial</em>, and the 182 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a> 183 * for more information. 184 * 185 * @author Arthur van Hoff 186 * @author Sami Shaio 187 */ 188 public abstract class Component implements ImageObserver, MenuContainer, 189 Serializable 190 { 191 192 private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component"); 193 private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component"); 194 private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component"); 195 private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component"); 196 197 /** 198 * The peer of the component. The peer implements the component's 199 * behavior. The peer is set when the <code>Component</code> is 3188 } 3189 3190 /** 3191 * Paints this component. 3192 * <p> 3193 * This method is called when the contents of the component should 3194 * be painted; such as when the component is first being shown or 3195 * is damaged and in need of repair. The clip rectangle in the 3196 * <code>Graphics</code> parameter is set to the area 3197 * which needs to be painted. 3198 * Subclasses of <code>Component</code> that override this 3199 * method need not call <code>super.paint(g)</code>. 3200 * <p> 3201 * For performance reasons, <code>Component</code>s with zero width 3202 * or height aren't considered to need painting when they are first shown, 3203 * and also aren't considered to need repair. 3204 * <p> 3205 * <b>Note</b>: For more information on the paint mechanisms utilitized 3206 * by AWT and Swing, including information on how to write the most 3207 * efficient painting code, see 3208 * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. 3209 * 3210 * @param g the graphics context to use for painting 3211 * @see #update 3212 * @since JDK1.0 3213 */ 3214 public void paint(Graphics g) { 3215 } 3216 3217 /** 3218 * Updates this component. 3219 * <p> 3220 * If this component is not a lightweight component, the 3221 * AWT calls the <code>update</code> method in response to 3222 * a call to <code>repaint</code>. You can assume that 3223 * the background is not cleared. 3224 * <p> 3225 * The <code>update</code> method of <code>Component</code> 3226 * calls this component's <code>paint</code> method to redraw 3227 * this component. This method is commonly overridden by subclasses 3228 * which need to do additional work in response to a call to 3229 * <code>repaint</code>. 3230 * Subclasses of Component that override this method should either 3231 * call <code>super.update(g)</code>, or call <code>paint(g)</code> 3232 * directly from their <code>update</code> method. 3233 * <p> 3234 * The origin of the graphics context, its 3235 * (<code>0</code>, <code>0</code>) coordinate point, is the 3236 * top-left corner of this component. The clipping region of the 3237 * graphics context is the bounding rectangle of this component. 3238 * 3239 * <p> 3240 * <b>Note</b>: For more information on the paint mechanisms utilitized 3241 * by AWT and Swing, including information on how to write the most 3242 * efficient painting code, see 3243 * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. 3244 * 3245 * @param g the specified context to use for updating 3246 * @see #paint 3247 * @see #repaint() 3248 * @since JDK1.0 3249 */ 3250 public void update(Graphics g) { 3251 paint(g); 3252 } 3253 3254 /** 3255 * Paints this component and all of its subcomponents. 3256 * <p> 3257 * The origin of the graphics context, its 3258 * (<code>0</code>, <code>0</code>) coordinate point, is the 3259 * top-left corner of this component. The clipping region of the 3260 * graphics context is the bounding rectangle of this component. 3261 * 3262 * @param g the graphics context to use for painting 3263 * @see #paint 3284 } 3285 3286 /** 3287 * Paints all the heavyweight subcomponents. 3288 */ 3289 void paintHeavyweightComponents(Graphics g) { 3290 } 3291 3292 /** 3293 * Repaints this component. 3294 * <p> 3295 * If this component is a lightweight component, this method 3296 * causes a call to this component's <code>paint</code> 3297 * method as soon as possible. Otherwise, this method causes 3298 * a call to this component's <code>update</code> method as soon 3299 * as possible. 3300 * <p> 3301 * <b>Note</b>: For more information on the paint mechanisms utilitized 3302 * by AWT and Swing, including information on how to write the most 3303 * efficient painting code, see 3304 * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. 3305 3306 * 3307 * @see #update(Graphics) 3308 * @since JDK1.0 3309 */ 3310 public void repaint() { 3311 repaint(0, 0, 0, width, height); 3312 } 3313 3314 /** 3315 * Repaints the component. If this component is a lightweight 3316 * component, this results in a call to <code>paint</code> 3317 * within <code>tm</code> milliseconds. 3318 * <p> 3319 * <b>Note</b>: For more information on the paint mechanisms utilitized 3320 * by AWT and Swing, including information on how to write the most 3321 * efficient painting code, see 3322 * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. 3323 * 3324 * @param tm maximum time in milliseconds before update 3325 * @see #paint 3326 * @see #update(Graphics) 3327 * @since JDK1.0 3328 */ 3329 public void repaint(long tm) { 3330 repaint(tm, 0, 0, width, height); 3331 } 3332 3333 /** 3334 * Repaints the specified rectangle of this component. 3335 * <p> 3336 * If this component is a lightweight component, this method 3337 * causes a call to this component's <code>paint</code> method 3338 * as soon as possible. Otherwise, this method causes a call to 3339 * this component's <code>update</code> method as soon as possible. 3340 * <p> 3341 * <b>Note</b>: For more information on the paint mechanisms utilitized 3342 * by AWT and Swing, including information on how to write the most 3343 * efficient painting code, see 3344 * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. 3345 * 3346 * @param x the <i>x</i> coordinate 3347 * @param y the <i>y</i> coordinate 3348 * @param width the width 3349 * @param height the height 3350 * @see #update(Graphics) 3351 * @since JDK1.0 3352 */ 3353 public void repaint(int x, int y, int width, int height) { 3354 repaint(0, x, y, width, height); 3355 } 3356 3357 /** 3358 * Repaints the specified rectangle of this component within 3359 * <code>tm</code> milliseconds. 3360 * <p> 3361 * If this component is a lightweight component, this method causes 3362 * a call to this component's <code>paint</code> method. 3363 * Otherwise, this method causes a call to this component's 3364 * <code>update</code> method. 3365 * <p> 3366 * <b>Note</b>: For more information on the paint mechanisms utilitized 3367 * by AWT and Swing, including information on how to write the most 3368 * efficient painting code, see 3369 * <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html">Painting in AWT and Swing</a>. 3370 * 3371 * @param tm maximum time in milliseconds before update 3372 * @param x the <i>x</i> coordinate 3373 * @param y the <i>y</i> coordinate 3374 * @param width the width 3375 * @param height the height 3376 * @see #update(Graphics) 3377 * @since JDK1.0 3378 */ 3379 public void repaint(long tm, int x, int y, int width, int height) { 3380 if (this.peer instanceof LightweightPeer) { 3381 // Needs to be translated to parent coordinates since 3382 // a parent native container provides the actual repaint 3383 // services. Additionally, the request is restricted to 3384 // the bounds of the component. 3385 if (parent != null) { 3386 if (x < 0) { 3387 width += x; 3388 x = 0; 3389 } | 156 * Button aButton = new Button(); 157 * 158 * static class MyActionListener implements ActionListener 159 * { 160 * public void actionPerformed(ActionEvent e) 161 * { 162 * System.out.println("Hello There"); 163 * } 164 * } 165 * 166 * MyApp() 167 * { 168 * aButton.addActionListener(new MyActionListener()); 169 * } 170 * } 171 * </pre> 172 * <p> 173 * <b>Note</b>: For more information on the paint mechanisms utilitized 174 * by AWT and Swing, including information on how to write the most 175 * efficient painting code, see 176 * <a href="http://www.oracle.com/technetwork/java/index.html">Painting in AWT and Swing</a>. 177 * <p> 178 * For details on the focus subsystem, see 179 * <a href="http://docs.oracle.com/javase/tutorial/uiswing/misc/focus.html"> 180 * How to Use the Focus Subsystem</a>, 181 * a section in <em>The Java Tutorial</em>, and the 182 * <a href="../../java/awt/doc-files/FocusSpec.html">Focus Specification</a> 183 * for more information. 184 * 185 * @author Arthur van Hoff 186 * @author Sami Shaio 187 */ 188 public abstract class Component implements ImageObserver, MenuContainer, 189 Serializable 190 { 191 192 private static final PlatformLogger log = PlatformLogger.getLogger("java.awt.Component"); 193 private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.Component"); 194 private static final PlatformLogger focusLog = PlatformLogger.getLogger("java.awt.focus.Component"); 195 private static final PlatformLogger mixingLog = PlatformLogger.getLogger("java.awt.mixing.Component"); 196 197 /** 198 * The peer of the component. The peer implements the component's 199 * behavior. The peer is set when the <code>Component</code> is 3188 } 3189 3190 /** 3191 * Paints this component. 3192 * <p> 3193 * This method is called when the contents of the component should 3194 * be painted; such as when the component is first being shown or 3195 * is damaged and in need of repair. The clip rectangle in the 3196 * <code>Graphics</code> parameter is set to the area 3197 * which needs to be painted. 3198 * Subclasses of <code>Component</code> that override this 3199 * method need not call <code>super.paint(g)</code>. 3200 * <p> 3201 * For performance reasons, <code>Component</code>s with zero width 3202 * or height aren't considered to need painting when they are first shown, 3203 * and also aren't considered to need repair. 3204 * <p> 3205 * <b>Note</b>: For more information on the paint mechanisms utilitized 3206 * by AWT and Swing, including information on how to write the most 3207 * efficient painting code, see 3208 * <a href="http://www.oracle.com/technetwork/java/index.html">Painting in AWT and Swing</a>. 3209 * 3210 * @param g the graphics context to use for painting 3211 * @see #update 3212 * @since JDK1.0 3213 */ 3214 public void paint(Graphics g) { 3215 } 3216 3217 /** 3218 * Updates this component. 3219 * <p> 3220 * If this component is not a lightweight component, the 3221 * AWT calls the <code>update</code> method in response to 3222 * a call to <code>repaint</code>. You can assume that 3223 * the background is not cleared. 3224 * <p> 3225 * The <code>update</code> method of <code>Component</code> 3226 * calls this component's <code>paint</code> method to redraw 3227 * this component. This method is commonly overridden by subclasses 3228 * which need to do additional work in response to a call to 3229 * <code>repaint</code>. 3230 * Subclasses of Component that override this method should either 3231 * call <code>super.update(g)</code>, or call <code>paint(g)</code> 3232 * directly from their <code>update</code> method. 3233 * <p> 3234 * The origin of the graphics context, its 3235 * (<code>0</code>, <code>0</code>) coordinate point, is the 3236 * top-left corner of this component. The clipping region of the 3237 * graphics context is the bounding rectangle of this component. 3238 * 3239 * <p> 3240 * <b>Note</b>: For more information on the paint mechanisms utilitized 3241 * by AWT and Swing, including information on how to write the most 3242 * efficient painting code, see 3243 * <a href="http://www.oracle.com/technetwork/java/index.html">Painting in AWT and Swing</a>. 3244 * 3245 * @param g the specified context to use for updating 3246 * @see #paint 3247 * @see #repaint() 3248 * @since JDK1.0 3249 */ 3250 public void update(Graphics g) { 3251 paint(g); 3252 } 3253 3254 /** 3255 * Paints this component and all of its subcomponents. 3256 * <p> 3257 * The origin of the graphics context, its 3258 * (<code>0</code>, <code>0</code>) coordinate point, is the 3259 * top-left corner of this component. The clipping region of the 3260 * graphics context is the bounding rectangle of this component. 3261 * 3262 * @param g the graphics context to use for painting 3263 * @see #paint 3284 } 3285 3286 /** 3287 * Paints all the heavyweight subcomponents. 3288 */ 3289 void paintHeavyweightComponents(Graphics g) { 3290 } 3291 3292 /** 3293 * Repaints this component. 3294 * <p> 3295 * If this component is a lightweight component, this method 3296 * causes a call to this component's <code>paint</code> 3297 * method as soon as possible. Otherwise, this method causes 3298 * a call to this component's <code>update</code> method as soon 3299 * as possible. 3300 * <p> 3301 * <b>Note</b>: For more information on the paint mechanisms utilitized 3302 * by AWT and Swing, including information on how to write the most 3303 * efficient painting code, see 3304 * <a href="http://www.oracle.com/technetwork/java/index.html">Painting in AWT and Swing</a>. 3305 3306 * 3307 * @see #update(Graphics) 3308 * @since JDK1.0 3309 */ 3310 public void repaint() { 3311 repaint(0, 0, 0, width, height); 3312 } 3313 3314 /** 3315 * Repaints the component. If this component is a lightweight 3316 * component, this results in a call to <code>paint</code> 3317 * within <code>tm</code> milliseconds. 3318 * <p> 3319 * <b>Note</b>: For more information on the paint mechanisms utilitized 3320 * by AWT and Swing, including information on how to write the most 3321 * efficient painting code, see 3322 * <a href="http://www.oracle.com/technetwork/java/index.html">Painting in AWT and Swing</a>. 3323 * 3324 * @param tm maximum time in milliseconds before update 3325 * @see #paint 3326 * @see #update(Graphics) 3327 * @since JDK1.0 3328 */ 3329 public void repaint(long tm) { 3330 repaint(tm, 0, 0, width, height); 3331 } 3332 3333 /** 3334 * Repaints the specified rectangle of this component. 3335 * <p> 3336 * If this component is a lightweight component, this method 3337 * causes a call to this component's <code>paint</code> method 3338 * as soon as possible. Otherwise, this method causes a call to 3339 * this component's <code>update</code> method as soon as possible. 3340 * <p> 3341 * <b>Note</b>: For more information on the paint mechanisms utilitized 3342 * by AWT and Swing, including information on how to write the most 3343 * efficient painting code, see 3344 * <a href="http://www.oracle.com/technetwork/java/index.html">Painting in AWT and Swing</a>. 3345 * 3346 * @param x the <i>x</i> coordinate 3347 * @param y the <i>y</i> coordinate 3348 * @param width the width 3349 * @param height the height 3350 * @see #update(Graphics) 3351 * @since JDK1.0 3352 */ 3353 public void repaint(int x, int y, int width, int height) { 3354 repaint(0, x, y, width, height); 3355 } 3356 3357 /** 3358 * Repaints the specified rectangle of this component within 3359 * <code>tm</code> milliseconds. 3360 * <p> 3361 * If this component is a lightweight component, this method causes 3362 * a call to this component's <code>paint</code> method. 3363 * Otherwise, this method causes a call to this component's 3364 * <code>update</code> method. 3365 * <p> 3366 * <b>Note</b>: For more information on the paint mechanisms utilitized 3367 * by AWT and Swing, including information on how to write the most 3368 * efficient painting code, see 3369 * <a href="http://www.oracle.com/technetwork/java/index.html">Painting in AWT and Swing</a>. 3370 * 3371 * @param tm maximum time in milliseconds before update 3372 * @param x the <i>x</i> coordinate 3373 * @param y the <i>y</i> coordinate 3374 * @param width the width 3375 * @param height the height 3376 * @see #update(Graphics) 3377 * @since JDK1.0 3378 */ 3379 public void repaint(long tm, int x, int y, int width, int height) { 3380 if (this.peer instanceof LightweightPeer) { 3381 // Needs to be translated to parent coordinates since 3382 // a parent native container provides the actual repaint 3383 // services. Additionally, the request is restricted to 3384 // the bounds of the component. 3385 if (parent != null) { 3386 if (x < 0) { 3387 width += x; 3388 x = 0; 3389 } |