Java Action ACTION_COMMAND_KEY

Syntax

Action.ACTION_COMMAND_KEY has the following syntax.

static final String ACTION_COMMAND_KEY

Example

In the following code shows how to use Action.ACTION_COMMAND_KEY field.


import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
//from   www . ja  va2s.co  m
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JCheckBox;
import javax.swing.JFrame;

public class Main {
  public static void main(String[] a) {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    Action action = new ShowAction();
    JCheckBox button = new JCheckBox(action);

    frame.add(button, BorderLayout.CENTER);
    frame.setSize(350, 150);
    frame.setVisible(true);
  }
}

class ShowAction extends AbstractAction {
  public ShowAction() {
    super("About");
  
    putValue(Action.ACTION_COMMAND_KEY, "command");
    putValue(Action.NAME, "Go to number ");
    
  }

  public void actionPerformed(ActionEvent actionEvent) {
    System.out.println("About Swing");
  }
}