PictureButtonpublic class PictureButton extends Component
Fields Summary |
---|
private Image | image | boolean | pressed | ActionListener | actionListener | String | actionCommand |
Constructors Summary |
---|
PictureButton(Image image)
this.image = image;
MediaTracker mt = new MediaTracker(this);
mt.addImage( image, 0 );
try { mt.waitForAll(); } catch (InterruptedException e) { /* error */ };
setSize( image.getWidth(null), image.getHeight(null) );
enableEvents( AWTEvent.MOUSE_EVENT_MASK );
|
Methods Summary |
---|
public void | addActionListener(java.awt.event.ActionListener l)
actionListener = AWTEventMulticaster.add(actionListener, l);
| private void | fireEvent()
if (actionListener != null) {
ActionEvent event = new ActionEvent( this,
ActionEvent.ACTION_PERFORMED, actionCommand );
actionListener.actionPerformed( event );
}
| public java.awt.Dimension | getPreferredSize()
return getSize();
| public void | paint(java.awt.Graphics g)
g.setColor(Color.white);
int width = getSize().width, height = getSize().height;
int offset = pressed ? -2 : 0; // fake depth
g.drawImage( image, offset, offset, width, height, this );
g.draw3DRect(0, 0, width-1, height-1, !pressed);
g.draw3DRect(1, 1, width-3, height-3, !pressed);
| public void | processEvent(java.awt.AWTEvent e)
if ( e.getID() == MouseEvent.MOUSE_PRESSED ) {
pressed = true;
repaint();
} else
if ( e.getID() == MouseEvent.MOUSE_RELEASED ) {
pressed = false;
repaint();
fireEvent();
}
super.processEvent(e);
| public void | removeActionListener(java.awt.event.ActionListener l)
actionListener = AWTEventMulticaster.remove(actionListener, l);
| public void | setActionCommand(java.lang.String actionCommand)
this.actionCommand = actionCommand;
|
|