Class Graphics2DTestPlusButton

java.lang.Object
  extended byGraphics2DTest
      extended byGraphics2DTestPlusButton

public class Graphics2DTestPlusButton
extends Graphics2DTest

This is an extension of the Graphics2DTest example that adds a movable JButton to the canvas. The inner class MovableButtonMouseListener is the most interesting part.


Nested Class Summary
static class Graphics2DTestPlusButton.MovableButtonMouseListener
          Class MovableButtonMouseListener extends JFC's MouseInputAdpater to provide handlers for three mouse events: mouse pressed, mouse dragged, and mouse released.
 
Nested classes inherited from class Graphics2DTest
Graphics2DTest.DrawingCanvas, Graphics2DTest.MousePressedListener, Graphics2DTest.RectShape
 
Field Summary
protected static javax.swing.JButton button
          A movable button on the canvas
protected static boolean buttonEnabled
          Current state of the movable button
protected static Graphics2DTestPlusButton.MovableButtonMouseListener mouseHandler
          The button mouse handler when it's in the moveable state
protected static java.awt.event.ActionListener savedButtonActionListener
          The saved action listener for the movable button
protected static java.awt.event.MouseListener savedButtonMouseListener
          The saved mouse listener for the movable button
 
Fields inherited from class Graphics2DTest
addButton, buttonBox, canvas, delButton, frame, numButton, shapeList, vbox, x, y
 
Constructor Summary
Graphics2DTestPlusButton()
           
 
Method Summary
protected static void addButtonListener(javax.swing.JButton enableButtonButton)
          Implement the mouse listener for the "Enable Button" button to toggle the enabled/disabled state of the movable button.
static void compose2()
          Construct and compose the add-ons to the parent class -- the movable button and the enable/disable button.
static void main(java.lang.String[] args)
          Call the parent compose method, then the local compose method.
 
Methods inherited from class Graphics2DTest
addButtonListeners, compose
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

button

protected static javax.swing.JButton button
A movable button on the canvas


mouseHandler

protected static Graphics2DTestPlusButton.MovableButtonMouseListener mouseHandler
The button mouse handler when it's in the moveable state


savedButtonActionListener

protected static java.awt.event.ActionListener savedButtonActionListener
The saved action listener for the movable button


savedButtonMouseListener

protected static java.awt.event.MouseListener savedButtonMouseListener
The saved mouse listener for the movable button


buttonEnabled

protected static boolean buttonEnabled
Current state of the movable button

Constructor Detail

Graphics2DTestPlusButton

public Graphics2DTestPlusButton()
Method Detail

compose2

public static void compose2()
Construct and compose the add-ons to the parent class -- the movable button and the enable/disable button.


addButtonListener

protected static void addButtonListener(javax.swing.JButton enableButtonButton)
Implement the mouse listener for the "Enable Button" button to toggle the enabled/disabled state of the movable button. The JComponent.setEnabled method is not used here, since we want to retain the normal visual appearance of the button. Therefore, we perform disable/enable by removing/restoring the action and mouse listeners to the button. New in 1.4 -- when the button is enabled, the call to removeMouseListener(mouseHandler) must be performed, since evidently the general mouse listener overrides (i.e., covers up) the action listener. This was not the case in 1.3. Arghhh :(


main

public static void main(java.lang.String[] args)
Call the parent compose method, then the local compose method. Then repack the top-level frame.