Example usage for java.awt.event ActionEvent getActionCommand

List of usage examples for java.awt.event ActionEvent getActionCommand

Introduction

In this page you can find the example usage for java.awt.event ActionEvent getActionCommand.

Prototype

public String getActionCommand() 

Source Link

Document

Returns the command string associated with this action.

Usage

From source file:SimpleApp3.java

public void actionPerformed(ActionEvent ev) {
    System.out.println("You clicked " + ev.getActionCommand());
}

From source file:ActionDisabled.java

public ActionDisabled() {
    this.setJMenuBar(menuBar);
    menuBar.add(testMenu);//from   w  w w .  ja  v a 2 s.  c  om

    testMenu.add(theAction);
    toolBar.add(theAction);

    disableActionItem.setActionCommand(DISABLE);
    testMenu.add(disableActionItem);
    disableActionItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (e.getActionCommand().equals(DISABLE)) {
                theAction.setEnabled(false);
                disableActionItem.setText("Enable the Action");
                disableActionItem.setActionCommand(ENABLE);
            } else {
                theAction.setEnabled(true);
                disableActionItem.setText("Disable the Action");
                disableActionItem.setActionCommand(DISABLE);
            }
        }
    });
    this.getContentPane().add(toolBar, BorderLayout.NORTH);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.getContentPane().setBackground(Color.red);
    this.setSize(320, 200);
    this.setVisible(true);
}

From source file:SimpleDraw.java

public void actionPerformed(ActionEvent ae) {
    shapeType = ae.getActionCommand().toString();
}

From source file:com.quiltplayer.controller.ImageController.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(EVENT_CHANGE_COVER)) {
        final Album album = (Album) e.getSource();

        int imageCount = e.getID();

        // This should be set as primary
        LocalImage toFrontImage = album.getImages().get(imageCount);
        album.changeFrontImage(album, toFrontImage);

        frame.updateUI();/* www . j a  v  a  2s.  co  m*/
    }
}

From source file:SecretTest.java

public SecretTest() {
    super("EventListenerList Demo");
    setSize(200, 100);/*from ww w.  j  a v  a2s.  co  m*/
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    SecretLabel secret = new SecretLabel("Try Clicking Me");
    final JLabel reporter = new JLabel("Event reports will show here...");
    secret.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            reporter.setText("Got it: " + ae.getActionCommand());
        }
    });
    getContentPane().add(secret, BorderLayout.NORTH);
    getContentPane().add(reporter, BorderLayout.SOUTH);
}

From source file:ToolbarFrame2.java

public ToolbarFrame2() {
    setSize(450, 250);//from w w  w. j ava  2s.  c  om

    ActionListener printListener = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            System.out.println(ae.getActionCommand());
        }
    };

    // JPanel works similarly to Panel, so we'll use it
    JPanel toolbar = new JPanel();
    toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));

    cutButton = new JButton("Cut");
    cutButton.addActionListener(printListener);
    toolbar.add(cutButton);

    copyButton = new JButton("Copy");
    copyButton.addActionListener(printListener);
    toolbar.add(copyButton);

    pasteButton = new JButton("Paste");
    pasteButton.addActionListener(printListener);
    toolbar.add(pasteButton);

    add(toolbar, BorderLayout.NORTH); // The new BorderLayout add

    JPanel lnfPanel = new JPanel();
    macButton = new JButton("Mac");
    macButton.addActionListener(printListener);
    lnfPanel.add(macButton);
    javaButton = new JButton("Metal");
    javaButton.addActionListener(printListener);
    lnfPanel.add(javaButton);
    motifButton = new JButton("Motif");
    motifButton.addActionListener(printListener);
    lnfPanel.add(motifButton);
    winButton = new JButton("Windows");
    winButton.addActionListener(printListener);
    lnfPanel.add(winButton);
    add(lnfPanel, BorderLayout.SOUTH);
}

From source file:MainClass.java

public void actionPerformed(ActionEvent evt) {
    String cmd = evt.getActionCommand();

    if (cmd.equals("copy")) {
        // Implement Copy operation
        String srcData = srcText.getText();
        if (srcData != null) {
            StringSelection contents = new StringSelection(srcData);
            clipboard.setContents(contents, this);
            pasteButton.setEnabled(true);
        }/*from w ww . ja  va2  s  . c  o m*/
    } else if (cmd.equals("paste")) {
        // Implement Paste operation
        Transferable content = clipboard.getContents(this);
        if (content != null) {
            try {
                String dstData = (String) content.getTransferData(DataFlavor.stringFlavor);
                dstText.append(dstData);
            } catch (Exception e) {
                System.out.println("Couldn't get contents in format: "
                        + DataFlavor.stringFlavor.getHumanPresentableName());
            }
        }
    }
}

From source file:WebBrowserBasedOnJEditorPane.java

public WebBrowserBasedOnJEditorPane() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel pnlURL = new JPanel();
    pnlURL.setLayout(new BorderLayout());
    pnlURL.add(new JLabel("URL: "), BorderLayout.WEST);
    pnlURL.add(txtURL, BorderLayout.CENTER);
    getContentPane().add(pnlURL, BorderLayout.NORTH);
    getContentPane().add(ep, BorderLayout.CENTER);

    getContentPane().add(lblStatus, BorderLayout.SOUTH);

    ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                String url = ae.getActionCommand().toLowerCase();
                if (url.startsWith("http://"))
                    url = url.substring(7);
                ep.setPage("http://" + IDN.toASCII(url));
            } catch (Exception e) {
                e.printStackTrace();/*w w  w. j  a  v  a  2  s . co  m*/
                JOptionPane.showMessageDialog(WebBrowserBasedOnJEditorPane.this,
                        "Browser problem: " + e.getMessage());
            }
        }
    };
    txtURL.addActionListener(al);

    setSize(300, 300);
    setVisible(true);
}

From source file:org.jfree.chart.demo.Graph.java

/**
 * Handles a click on the button by adding new (random) data.
 *
 * @param e  the action event./* w ww  . jav a2 s.c o  m*/
 */
public void actionPerformed(final ActionEvent e) {
    if (e.getActionCommand().equals("ADD_DATA")) {

        final double factor = 0.90 + 0.2 * Math.random();
        this.lastValue = this.lastValue * factor;
        final Millisecond now = new Millisecond();
        System.out.println("Now = " + now.toString());
        this.series.add(new Millisecond(), this.lastValue);
    }
}

From source file:Main.java

public Main() {
    menuBar = new JMenuBar();
    JMenu justifyMenu = new JMenu("Justify");
    ActionListener actionPrinter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Action [" + e.getActionCommand() + "] performed!\n");
        }//from   w ww  .  jav a 2 s.  c  o m
    };
    JCheckBoxMenuItem leftJustify = new JCheckBoxMenuItem("Left", new ImageIcon("1.gif"));
    leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    leftJustify
            .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    leftJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem rightJustify = new JCheckBoxMenuItem("Right", new ImageIcon("2.gif"));
    rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    rightJustify
            .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    rightJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem centerJustify = new JCheckBoxMenuItem("Center", new ImageIcon("3.gif"));
    centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    centerJustify
            .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    centerJustify.addActionListener(actionPrinter);
    JCheckBoxMenuItem fullJustify = new JCheckBoxMenuItem("Full", new ImageIcon("4.gif"));
    fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    fullJustify
            .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fullJustify.addActionListener(actionPrinter);

    justifyMenu.add(leftJustify);
    justifyMenu.add(rightJustify);
    justifyMenu.add(centerJustify);
    justifyMenu.add(fullJustify);

    menuBar.add(justifyMenu);
    menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));

}