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:QandE.Beeper2.java

public void actionPerformed(ActionEvent e) {
    if (BUTTON_CMD.equals(e.getActionCommand())) {
        startBeeping(beepsModel.getNumber().intValue());
    } else { //called by the Timer
        Toolkit.getDefaultToolkit().beep();
        if (--beepsRemaining < 1) {
            timer.stop();//from w w w  . j a  v a2  s. co m
        }
    }
}

From source file:CardLayoutDemo.java

public void actionPerformed(ActionEvent evt) {
    CardLayout cl = (CardLayout) (cards.getLayout());
    cl.show(cards, (String) evt.getActionCommand());
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    int retVal;// ww w.  j  a v a  2  s . c  om

    JFileChooser fc = new JFileChooser();

    if (e.getActionCommand().equals("Open ...")) {
        fc.addChoosableFileFilter(new TextFilter());
        retVal = fc.showOpenDialog(this);
    } else
        retVal = fc.showSaveDialog(this);

    if (retVal == JFileChooser.APPROVE_OPTION)
        System.out.println(fc.getSelectedFile().getName());
}

From source file:Main.java

@Override
public void actionPerformed(ActionEvent e) {
    if ("Start" == null ? e.getActionCommand() == null : "Start".equals(e.getActionCommand())) {
        startButton.setEnabled(false);/*from   www. java 2  s . c  o m*/
        stopButton.setEnabled(true);
        (swingWorker = new mySwingWorker()).execute();
    } else if ("Stop" == null ? e.getActionCommand() == null : "Stop".equals(e.getActionCommand())) {
        startButton.setEnabled(true);
        stopButton.setEnabled(false);
        swingWorker.cancel(true);
        swingWorker = null;
    }
}

From source file:SimpleInternalFrameDemo.java

public void actionPerformed(ActionEvent e) {
    String lnfName = null;/*from   w  ww . ja  va2 s  .  com*/
    if (e.getActionCommand().equals("Mac")) {
        lnfName = "com.apple.mrj.swing.MacLookAndFeel";
    } else if (e.getActionCommand().equals("Metal")) {
        lnfName = "javax.swing.plaf.metal.MetalLookAndFeel";
    } else if (e.getActionCommand().equals("Motif")) {
        lnfName = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";
    } else if (e.getActionCommand().equals("Windows")) {
        lnfName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    } else {
        System.err.println("Unrecognized L&F request action: " + e.getActionCommand());
        return;
    }
    try {
        UIManager.setLookAndFeel(lnfName);
        SwingUtilities.updateComponentTreeUI(frame);
    } catch (UnsupportedLookAndFeelException ex1) {
        System.err.println("Unsupported LookAndFeel: " + lnfName);
    } catch (ClassNotFoundException ex2) {
        System.err.println("LookAndFeel class not found: " + lnfName);
    } catch (InstantiationException ex3) {
        System.err.println("Could not load LookAndFeel: " + lnfName);
    } catch (IllegalAccessException ex4) {
        System.err.println("Cannot use LookAndFeel: " + lnfName);
    }
}

From source file:components.InternalFrameDemo.java

public void actionPerformed(ActionEvent e) {
    if ("new".equals(e.getActionCommand())) { //new
        createFrame();/*ww w. j  a  v a2 s. c o m*/
    } else { //quit
        quit();
    }
}

From source file:Main.java

public Main() {
    popup = new JPopupMenu();
    ActionListener menuListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed.");
        }//from  w ww .  ja  v a 2s  .  co  m
    };
    JMenuItem item;
    popup.add(item = new JMenuItem(new ImageIcon("left.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.addSeparator();
    popup.add(item = new JMenuItem("Settings . . ."));
    item.addActionListener(menuListener);

    popup.setLabel("Justification");
    popup.setBorder(new BevelBorder(BevelBorder.RAISED));
    popup.addPopupMenuListener(new PopupPrintListener());

    addMouseListener(new MousePopupListener());
}

From source file:MainClass.java

public MainClass() {
    popup = new JPopupMenu();
    ActionListener menuListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed.");
        }/*www. j  av  a 2  s  .  co m*/
    };
    JMenuItem item;
    popup.add(item = new JMenuItem("Left", new ImageIcon("left.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.addSeparator();
    popup.add(item = new JMenuItem("Settings . . ."));
    item.addActionListener(menuListener);

    popup.setLabel("Justification");
    popup.setBorder(new BevelBorder(BevelBorder.RAISED));
    popup.addPopupMenuListener(new PopupPrintListener());

    addMouseListener(new MousePopupListener());
}

From source file:Main.java

public Main() {
    popup = new JPopupMenu();
    ActionListener menuListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed.");
        }// w  w w .j  ava2  s  . co  m
    };
    JMenuItem item;
    popup.add(item = new JMenuItem("Left", new ImageIcon("left.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.addSeparator();
    popup.add(item = new JMenuItem("Settings . . ."));
    item.addActionListener(menuListener);

    popup.setLabel("Justification");
    popup.setBorder(new BevelBorder(BevelBorder.RAISED));
    popup.addPopupMenuListener(new PopupPrintListener());

    addMouseListener(new MousePopupListener());
}

From source file:Main.java

public Main() {
    popup = new JPopupMenu();
    ActionListener menuListener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            System.out.println("Popup menu item [" + event.getActionCommand() + "] was pressed.");
        }//from ww w .ja  va  2  s  .  co m
    };
    JMenuItem item;
    popup.add(item = new JMenuItem("Left"));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Center", new ImageIcon("center.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Right", new ImageIcon("right.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.add(item = new JMenuItem("Full", new ImageIcon("full.gif")));
    item.setHorizontalTextPosition(JMenuItem.RIGHT);
    item.addActionListener(menuListener);
    popup.addSeparator();
    popup.add(item = new JMenuItem("Settings . . ."));
    item.addActionListener(menuListener);

    popup.setLabel("Justification");
    popup.setBorder(new BevelBorder(BevelBorder.RAISED));
    popup.addPopupMenuListener(new PopupPrintListener());

    addMouseListener(new MousePopupListener());
}