|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
capella.GUI.ButtonImage
public class ButtonImage
A button class which use an image instead of a string label. Clicking
(press + release) the mouse button triggers an actionEvent
in a way similar to the standard java.awt.Button (Java 1.1).
Here is an example of its use:
public class Test extends Frame implements ActionListener {
public static void main(String argv[]) {
Test t = new Test();
}
public Test() {
setLayout(new BorderLayout());
try {
ButtonImage button = new ButtonImage(INSERT_AN_URL_HERE));
add("North",button);
button.addActionListener(this);
button.setActionCommand("First Button");
button = new ButtonImage(INSERT_A_FILENAME_HERE);
add("South",button);
button.addActionListener(this);
}
catch (Exception e) {}
doLayout();
pack();
show();
}
public void actionPerformed(ActionEvent e) {
System.out.println("ACTION PERFORMED "+e);
}
}
| Nested Class Summary |
|---|
| Nested classes/interfaces inherited from class java.awt.Component |
|---|
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy |
| Field Summary | |
|---|---|
static Color |
BORDER_COLOR
The default color used for border rendering. |
static int |
BORDER_SIZE
The default border size. |
| Fields inherited from class java.awt.Component |
|---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
| Fields inherited from interface java.awt.image.ImageObserver |
|---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
| Constructor Summary | |
|---|---|
ButtonImage(String path)
|
|
ButtonImage(URL url)
|
|
| Method Summary | |
|---|---|
void |
addActionListener(ActionListener al)
Adds the specified action listener to receive action events from this button. |
String |
getActionCommand()
gets the command name. |
Color |
getBorderColor()
|
int |
getBorderSize()
|
int |
getHeight()
|
Dimension |
getPreferredSize()
gets the Dimension size for layouts |
int |
getWidth()
|
boolean |
isUp()
|
void |
paint(Graphics g)
used to redraw the button if needed. |
protected void |
processActionEvent(ActionEvent e)
process actionEvent on this button. |
protected void |
processEvent(AWTEvent e)
process events on this button. |
void |
removeActionListener(ActionListener al)
Removes the specified action listener so that it no longer receives action events from this button. |
void |
setActionCommand(String actionCommand)
sets the command name. |
void |
setBorderColor(Color color)
|
void |
setBorderSize(int size)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final Color BORDER_COLOR
public static final int BORDER_SIZE
| Constructor Detail |
|---|
public ButtonImage(URL url)
url - the URL of an image to be used as a labelpublic ButtonImage(String path)
path - the pathname of an image to be used as a label| Method Detail |
|---|
public boolean isUp()
true if this button is actually raised.
false if not.public String getActionCommand()
setActionCommand(java.lang.String)public int getBorderSize()
setBorderSize(int)public int getWidth()
getWidth in class Componentpublic int getHeight()
getHeight in class Componentpublic Dimension getPreferredSize()
Dimension size for layouts
getPreferredSize in class Componentpublic Color getBorderColor()
setBorderColor(java.awt.Color),
BORDER_COLORpublic void setBorderSize(int size)
size - the new size for the border. If negative,
BORDER_SIZE is used.getBorderSize(),
BORDER_SIZEpublic void setBorderColor(Color color)
color - the new color for the border. If null
BORDER_COLOR is used.getBorderColor(),
BORDER_COLORpublic void paint(Graphics g)
repaint on this widget.
Don't forget to call this one if you plan to subclass this class
and want its standard image rendering.
paint in class Componentg - used to carry drawing requests.public void setActionCommand(String actionCommand)
actionCommand - A String used to set the button's action
commandprotected void processEvent(AWTEvent e)
ActionEvent.
processEvent on the superclass.
processEvent in class Componente - an AWTEvent to process.AWTEvent,
processActionEvent(java.awt.event.ActionEvent)protected void processActionEvent(ActionEvent e)
actionEvent on this button.
Actually calls actionPerformed through a multicaster object.
e - an ActionEvent to process.ActionEvent,
processEvent(java.awt.AWTEvent)public void addActionListener(ActionListener al)
al - the action listener.public void removeActionListener(ActionListener al)
al - the action listener.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||