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:it.unibas.spicygui.controllo.provider.composition.MyPopupProviderConnectionMergeComposition.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(DELETE)) {
        deleteConnection();/*  www.ja  va2  s . c  o  m*/
    } else {
        StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(Costanti.class, Costanti.GENERIC_ERROR));
    }
}

From source file:FileViewer.java

/**
 * Handle button clicks/*www  . j a  v  a 2 s.  c  o m*/
 */
public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    if (cmd.equals("open")) { // If user clicked "Open" button
        // Create a file dialog box to prompt for a new file to display
        FileDialog f = new FileDialog(this, "Open File", FileDialog.LOAD);
        f.setDirectory(directory); // Set the default directory

        // Display the dialog and wait for the user's response
        f.show();

        directory = f.getDirectory(); // Remember new default directory
        setFile(directory, f.getFile()); // Load and display selection
        f.dispose(); // Get rid of the dialog box
    } else if (cmd.equals("close")) // If user clicked "Close" button
        this.dispose(); // then close the window
}

From source file:net.chaosserver.timelord.swingui.JCalendarDialog.java

/**
 * Listens for the user selecting a button.
 *
 * @param evt the event performed./*from ww w. ja va2s  . c  o  m*/
 */
public void actionPerformed(ActionEvent evt) {
    if (actionSelect.equals(evt.getActionCommand())) {
        choosenDate = calendar.getDate();

        if (log.isDebugEnabled()) {
            log.debug("JCalendar returned a date of [" + choosenDate + "]");
        }

        this.setVisible(false);
    } else if (actionCancel.equals(evt.getActionCommand())) {
        choosenDate = null;
        this.setVisible(false);
    }
}

From source file:Main.java

@Override
public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (ADD_COMMAND.equals(command)) {
        treePanel.addObject("New Node " + newNodeSuffix++);
    } else if (REMOVE_COMMAND.equals(command)) {
        treePanel.removeCurrentNode();//w w  w.  j  a va2  s  .c o m
    } else if (CLEAR_COMMAND.equals(command)) {
        treePanel.clear();
    }
}

From source file:DynamiskDemo2.java

/**
 * Handles a click on the button by adding new (random) data.
 *
 * @param e  the action event.//w  w  w.j  av a  2  s.  co 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:LayeredPaneDemo.java

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

    if (ON_TOP_COMMAND.equals(cmd)) {
        if (onTop.isSelected())
            layeredPane.moveToFront(dukeLabel);
        else/*  ww  w  . j a  va  2  s .  c o  m*/
            layeredPane.moveToBack(dukeLabel);

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

From source file:IntroExample.java

public IntroExample() {

    JMenu fileMenu = new JMenu("File");
    JMenu editMenu = new JMenu("Edit");
    JMenu otherMenu = new JMenu("Other");
    JMenu subMenu = new JMenu("SubMenu");
    JMenu subMenu2 = new JMenu("SubMenu2");

    //  Assemble the File menus with mnemonics
    ActionListener printListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Menu item [" + event.getActionCommand() + "] was pressed.");
        }/*from w  w  w . j  av a  2 s . com*/
    };
    for (int i = 0; i < fileItems.length; i++) {
        JMenuItem item = new JMenuItem(fileItems[i], fileShortcuts[i]);
        item.addActionListener(printListener);
        fileMenu.add(item);
    }

    //  Assemble the File menus with keyboard accelerators
    for (int i = 0; i < editItems.length; i++) {
        JMenuItem item = new JMenuItem(editItems[i]);
        item.setAccelerator(KeyStroke.getKeyStroke(editShortcuts[i],
                Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false));
        item.addActionListener(printListener);
        editMenu.add(item);
    }

    //  Insert a separator in the Edit Menu in Position 1 after "Undo"
    editMenu.insertSeparator(1);

    //  Assemble the submenus of the Other Menu
    JMenuItem item;
    subMenu2.add(item = new JMenuItem("Extra 2"));
    item.addActionListener(printListener);
    subMenu.add(item = new JMenuItem("Extra 1"));
    item.addActionListener(printListener);
    subMenu.add(subMenu2);

    //  Assemble the Other Menu itself
    otherMenu.add(subMenu);
    otherMenu.add(item = new JCheckBoxMenuItem("Check Me"));
    item.addActionListener(printListener);
    otherMenu.addSeparator();
    ButtonGroup buttonGroup = new ButtonGroup();
    otherMenu.add(item = new JRadioButtonMenuItem("Radio 1"));
    item.addActionListener(printListener);
    buttonGroup.add(item);
    otherMenu.add(item = new JRadioButtonMenuItem("Radio 2"));
    item.addActionListener(printListener);
    buttonGroup.add(item);
    otherMenu.addSeparator();
    otherMenu.add(item = new JMenuItem("Potted Plant", new ImageIcon("image.gif")));
    item.addActionListener(printListener);

    //  Finally, add all the menus to the menu bar
    add(fileMenu);
    add(editMenu);
    add(otherMenu);
}

From source file:SwingToolBarDemo.java

public void actionPerformed(ActionEvent e) {
    String cmd = e.getActionCommand();
    String description = null;//w w  w  .ja  va2s . com

    // Handle each button.
    if (PREVIOUS.equals(cmd)) { //first button clicked
        description = "taken you to the previous <something>.";
    } else if (UP.equals(cmd)) { // second button clicked
        description = "taken you up one level to <something>.";
    } else if (NEXT.equals(cmd)) { // third button clicked
        description = "taken you to the next <something>.";
    }

    displayResult("If this were a real app, it would have " + description);
}

From source file:components.PasswordDemo.java

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

    if (OK.equals(cmd)) { //Process the password.
        char[] input = passwordField.getPassword();
        if (isPasswordCorrect(input)) {
            JOptionPane.showMessageDialog(controllingFrame, "Success! You typed the right password.");
        } else {/*from w w w. j av  a 2 s. co  m*/
            JOptionPane.showMessageDialog(controllingFrame, "Invalid password. Try again.", "Error Message",
                    JOptionPane.ERROR_MESSAGE);
        }

        //Zero out the possible password, for security.
        Arrays.fill(input, '0');

        passwordField.selectAll();
        resetFocus();
    } else { //The user has asked for help.
        JOptionPane.showMessageDialog(controllingFrame,
                "You can get the password by searching this example's\n"
                        + "source code for the string \"correctPassword\".\n"
                        + "Or look at the section How to Use Password Fields in\n"
                        + "the components section of The Java Tutorial.");
    }
}

From source file:net.chaosserver.timelord.swingui.AnnoyTimeDialog.java

/**
 * Captures the action and processes and closes the dialog.
 *
 * @param evt the action event triggering the method
 *//*from  w w  w .j  a  va 2  s. c om*/
public void actionPerformed(ActionEvent evt) {
    if (ACTION_OK.equals(evt.getActionCommand())) {
        int minuteValue = minuteSlider.getValue();
        double fractionValue = minuteValue / 60d;
        if (log.isDebugEnabled()) {
            log.debug("Got back minute value [" + minuteValue + "] as fraction value [" + fractionValue + "]");
        }

        Preferences preferences = Preferences.userNodeForPackage(Timelord.class);

        preferences.putDouble(Timelord.TIME_INCREMENT, fractionValue);
        this.setVisible(false);

    } else if (ACTION_CANCEL.equals(evt.getActionCommand())) {
        this.setVisible(false);
    }
}