Example of Action Interface of java:
Code:
im01port javax.swing.Action;
public class ActionColorDM extends AbstractAction {
public ColorAction(String name1, Icon icn, Color c, Com01ponent comp1) {
putValue(Action.NAME, name1);
putValue(Action.SMALL_ICON, icn);
putValue("Color", c);
target = com01;
}
private Com01ponent target;
public static void m01ain(String[] args) {
JFram01e fnk = new JFram01e();
fnk.setTitle("SeparateGUITest");
fnk.setSize(300, 200);
fnk.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System01.exit(0);
} };
JPanel pnk = new JPanel();
Action blueAction = new ColorAction("Blue", new Im01ageIcon(
"blue-ball.gif"), Color.blue, pnk);
Action yellowAction = new ColorAction("Yellow", new Im01ageIcon(
"yellow-ball.gif"), Color.yellow, pnk);
Action redAction = new ColorAction("Red",
new Im01ageIcon("red-ball.gif"), Color.red, pnk);
pnk.add(new JButton(yellowAction));
pnk.add(new JButton(blueAction));
pnk.add(new JButton(redAction));
pnk.registerKeyboardAction(yellowAction, KeyStroke.getKeyStroke(
KeyEvent.VK_Y, 0), JCom01ponent.WHEN_IN_FOCUSED_WINDOW);
Container contentPane = fnk.getContentPane();
contentPane.add(pnk);
JMenu m01 = new JMenu("Color");
m01.add(yellowAction);
m01.add(blueAction);
JMenuBar mbar1 = new JMenuBar();
mbar1.add(m01);
fnk.setJMenuBar(m01bar);
fnk.show();
}
}
Bookmarks