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:MenuShortcuts.java

/** Handle action events. */
public void actionPerformed(ActionEvent evt) {
    // System.out.println("Event " + evt);
    String cmd;//from  ww  w .  j a va 2s  .com
    if ((cmd = evt.getActionCommand()) == null)
        System.out.println("You chose a menu shortcut");
    else
        System.out.println("You chose " + cmd);
    Object cmp = evt.getSource();
    // System.out.println("Source " + cmp);
    if (cmp == exitItem)
        System.exit(0);
}

From source file:Main.java

public Main() {
    menuBar = new JMenuBar();
    JMenu justifyMenu = new JMenu("Justify");
    ActionListener actionPrinter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                pane.getStyledDocument().insertString(0, "Action [" + e.getActionCommand() + "] performed!\n",
                        null);//  w w w .  java 2s .c om
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
    JRadioButtonMenuItem leftJustify = new JRadioButtonMenuItem("Left", new ImageIcon("1.gif"));
    leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    leftJustify
            .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    leftJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem rightJustify = new JRadioButtonMenuItem("Right", new ImageIcon("2.gif"));
    rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    rightJustify
            .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    rightJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem centerJustify = new JRadioButtonMenuItem("Center", new ImageIcon("3.gif"));
    centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    centerJustify
            .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    centerJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem fullJustify = new JRadioButtonMenuItem("Full", new ImageIcon("4.gif"));
    fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    fullJustify
            .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fullJustify.addActionListener(actionPrinter);

    ButtonGroup group = new ButtonGroup();
    group.add(leftJustify);
    group.add(rightJustify);
    group.add(centerJustify);
    group.add(fullJustify);

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

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

From source file:RadioButtonDemo.java

/** Listens to the radio buttons. */
public void actionPerformed(ActionEvent e) {
    picture.setIcon(createImageIcon("images/" + e.getActionCommand() + ".gif"));
}

From source file:components.RootLayeredPaneDemo.java

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

    if (ON_TOP_COMMAND.equals(cmd)) {
        if (onTop.isSelected())
            layeredPane.moveToFront(dukeLabel);
        else//from  w w  w.j  ava2  s.  c o  m
            layeredPane.moveToBack(dukeLabel);

    } else if (LAYER_COMMAND.equals(cmd)) {
        int position = onTop.isSelected() ? 0 : -1;
        layeredPane.setLayer(dukeLabel, layers[layerList.getSelectedIndex()], position);
    }
}

From source file:RadioButtonMenuItemExample.java

public RadioButtonMenuItemExample() {
    menuBar = new JMenuBar();
    JMenu justifyMenu = new JMenu("Justify");
    ActionListener actionPrinter = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                pane.getStyledDocument().insertString(0, "Action [" + e.getActionCommand() + "] performed!\n",
                        null);// w  w w  . j  a v  a 2  s  . c  om
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    };
    JRadioButtonMenuItem leftJustify = new JRadioButtonMenuItem("Left", new ImageIcon("1.gif"));
    leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    leftJustify
            .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    leftJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem rightJustify = new JRadioButtonMenuItem("Right", new ImageIcon("2.gif"));
    rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    rightJustify
            .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    rightJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem centerJustify = new JRadioButtonMenuItem("Center", new ImageIcon("3.gif"));
    centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    centerJustify
            .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    centerJustify.addActionListener(actionPrinter);
    JRadioButtonMenuItem fullJustify = new JRadioButtonMenuItem("Full", new ImageIcon("4.gif"));
    fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT);
    fullJustify
            .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
    fullJustify.addActionListener(actionPrinter);

    ButtonGroup group = new ButtonGroup();
    group.add(leftJustify);
    group.add(rightJustify);
    group.add(centerJustify);
    group.add(fullJustify);

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

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

From source file:events.ContainerEventDemo.java

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();

    if (ADD.equals(command)) {
        JButton newButton = new JButton("JButton #" + (buttonList.size() + 1));
        buttonList.addElement(newButton);
        buttonPanel.add(newButton);/* ww  w .  j  ava 2 s.  c  om*/
        buttonPanel.revalidate(); //Make the button show up.

    } else if (REMOVE.equals(command)) {
        int lastIndex = buttonList.size() - 1;
        try {
            JButton nixedButton = buttonList.elementAt(lastIndex);
            buttonPanel.remove(nixedButton);
            buttonList.removeElementAt(lastIndex);
            buttonPanel.revalidate(); //Make the button disappear.
            buttonPanel.repaint(); //Make the button disappear.
        } catch (ArrayIndexOutOfBoundsException exc) {
        }
    } else if (CLEAR.equals(command)) {
        display.setText("");
    }
}

From source file:org.simbrain.plot.piechart.PieChartGui.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equalsIgnoreCase("Add")) {
        this.getWorkspaceComponent().getModel().addDataSource();
    } else if (e.getActionCommand().equalsIgnoreCase("dialog")) {
        ReflectivePropertyEditor editor = (new ReflectivePropertyEditor(getWorkspaceComponent().getModel()));
        JDialog dialog = editor.getDialog();
        dialog.setModal(true);/*from  www .j  av a 2 s . co  m*/
        dialog.pack();
        dialog.setLocationRelativeTo(null);
        dialog.setVisible(true);
    } else if (e.getActionCommand().equalsIgnoreCase("Delete")) {
        this.getWorkspaceComponent().getModel().removeDataSource();
    }
}

From source file:FocusTraversalDemo.java

public void actionPerformed(ActionEvent e) {
    if ("toggle".equals(e.getActionCommand())) {
        frame.setFocusTraversalPolicy(togglePolicy.isSelected() ? newPolicy : null);
    }//from w  w  w  .  j  ava2  s  .  c om
}

From source file:appletComponentArch.DynamicTreePanel.java

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();

    if (ADD_COMMAND.equals(command)) {
        //Add button clicked
        treePanel.addObject("New Node " + newNodeSuffix++);
    } else if (REMOVE_COMMAND.equals(command)) {
        //Remove button clicked
        treePanel.removeCurrentNode();//from  www  .j  a v a2  s.c  o m
    } else if (CLEAR_COMMAND.equals(command)) {
        //Clear button clicked.
        treePanel.clear();
    }
}

From source file:epsi.i5.frame.JFrame.java

private void jFileChooser1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jFileChooser1ActionPerformed

    if (evt.getActionCommand().equals("CancelSelection")) {

        setVisible(false); //you can't see me!
        dispose(); //Destroy the JFrame object

    } else {//from   ww  w. j  a  v a  2 s  .com

        Treatment tr = new Treatment();

        try {
            tr.treatment(jFileChooser1.getSelectedFile());
        } catch (IOException | RepustateException | ParseException ex) {
            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
        Weka arff = new Weka();
        try {
            arff.chargementData(tr.dataEnter);
            arff.generationArff();
            arff.generationArffFilter();
            arff.excutionAlgo();
        } catch (Exception ex) {
            Logger.getLogger(JFrame.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

}