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

public static void searchForPorts() {
    portSubMenu.removeAll();// w w  w  .  ja v a2 s.  c  om

    Enumeration ports = CommPortIdentifier.getPortIdentifiers();
    ActionListener mPortListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectedPortName = e.getActionCommand();
        }
    };
    ButtonGroup sensorGroup = new ButtonGroup();

    while (ports.hasMoreElements()) {
        CommPortIdentifier curPort = (CommPortIdentifier) ports.nextElement();

        //get only serial ports
        if (curPort.getPortType() == CommPortIdentifier.PORT_SERIAL) {
            JRadioButtonMenuItem tmpRadioButton = new JRadioButtonMenuItem(curPort.getName());
            sensorGroup.add(tmpRadioButton);
            portSubMenu.add(tmpRadioButton);
            tmpRadioButton.addActionListener(mPortListener);

            portMap.put(curPort.getName(), curPort);
        }
    }
}

From source file:levelBuilder.DialogMaker.java

/**
 * Provides other action buttons.//from ww w .j  av  a  2s .co  m
 */
private static void actionWindow() {
    //Performs actions based on button pushes.
    class ActionHandler implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (e.getActionCommand()) {
            case "edge":
                if (addedEdgeID != 0.0) {
                    DialogNode n = g.getSource(addedEdgeID);
                    int length;
                    if (n.getChildren().length == 0)
                        length = 0;
                    else
                        length = n.getChildren().length;
                    DialogNode[] newChildren = new DialogNode[length + 1];
                    for (int c = 0; c < newChildren.length - 1; c++)
                        newChildren[c] = n.getChildren()[c];
                    newChildren[newChildren.length - 1] = nodeMap.get(g.getDest(addedEdgeID).getText());
                    n.setChildren(newChildren);
                    addedEdgeID = 0.0;
                }
            case "save":
                saveGraph();
            case "check":
                //Checks for errors and displays them if they exist.
                ArrayList<String> errorList = new ArrayList<String>();
                errorList = dg.check();
                if (errorList.isEmpty()) {
                    JOptionPane.showMessageDialog(null, "No errors!", null, JOptionPane.PLAIN_MESSAGE);
                } else {
                    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));
                    for (String error : errorList)
                        panel.add(new JLabel(error));
                    JOptionPane.showMessageDialog(null, panel, "Errors. Fix these to continue.",
                            JOptionPane.PLAIN_MESSAGE);
                }
            case "reload":
                loadGraph(false);
            }
        }
    }

    JPanel panel = new JPanel(new GridLayout(0, 1, 0, 0));

    //Buttons
    JButton button3 = new JButton("New edge");
    button3.setActionCommand("edge");
    button3.addActionListener(new ActionHandler());
    panel.add(button3);

    JButton button6 = new JButton("Save");
    button6.setActionCommand("save");
    button6.addActionListener(new ActionHandler());
    panel.add(button6);

    JButton button7 = new JButton("Check");
    button7.setActionCommand("check");
    button7.addActionListener(new ActionHandler());
    panel.add(button7);

    JButton button1 = new JButton("Reload");
    button1.setActionCommand("reload");
    button1.addActionListener(new ActionHandler());
    panel.add(button1);

    JFrame frame = new JFrame("Other Input");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setContentPane(panel);
    frame.pack();
    frame.setLocation(windowWidth + horizontalWindowPlacement, 0);
    frame.setVisible(true);
}

From source file:levelBuilder.DialogMaker.java

/**
 * First window to interact with. Offers options of load graph or new graph.
 *//* w w w .java  2s.  c o m*/
private static void splashWindow() {
    final JFrame frame = new JFrame("Dialog Maker");

    //Handles button pushes.
    class SplashActionHandler implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            frame.dispose();
            if (e.getActionCommand().equals("loadGraph"))
                loadFilePopup();
            else
                loadGraph(true);
        }
    }

    //Loads and sets background image.
    BufferedImage img = null;
    try {
        img = ImageIO.read(new File(imgDir + "splash.png"));
    } catch (IOException e) {
        e.printStackTrace();
    }
    final BufferedImage img2 = img;
    JPanel panel = new JPanel() {
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(img2, 0, 0, null);
        }
    };

    panel.setOpaque(true);
    panel.setLayout(new BorderLayout());
    panel.setPreferredSize(new Dimension(800, 600));
    panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 300, 0));

    JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    buttonPanel.setOpaque(false);

    //Buttons
    JButton loadMap = new JButton("Load Graph");
    loadMap.setActionCommand("loadGraph");
    loadMap.addActionListener(new SplashActionHandler());
    buttonPanel.add(loadMap);

    JButton newMap = new JButton("New Graph");
    newMap.setActionCommand("newGraph");
    newMap.addActionListener(new SplashActionHandler());
    buttonPanel.add(newMap);

    panel.add(buttonPanel, BorderLayout.SOUTH);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.add(panel);
    frame.pack();
    frame.setVisible(true);
}

From source file:levelBuilder.DialogMaker.java

/**
 * Displays properties of the currently selected node.
 * Also allows changing of most node properties. 
 *///w w  w.  j a  va 2s. c  o m
private static void nodePropertiesWindow() {
    //Performs actions based on button pushes.
    class ActionHandler implements ActionListener {
        @Override
        public void actionPerformed(ActionEvent e) {
            switch (e.getActionCommand()) {
            case "probSet":
                //parsing new probSet string to double[]
                ArrayList<double[]> probSets = selectedNode.getProbSets();
                if (probSetField.getText().equals(""))
                    probSets.remove(strategy);
                else {
                    String[] probSetInput = probSetField.getText().split(",");
                    int numChildren = probSetInput.length;
                    double[] newProbSet = new double[numChildren];
                    for (int c = 0; c < numChildren; c++)
                        newProbSet[c] = Double.parseDouble(probSetInput[c]);
                    if (probSets.size() > strategy)//TODO is this right?
                        probSets.add(strategy, newProbSet);
                    else
                        probSets.set(strategy, newProbSet);
                }
                selectedNode.setProbSets(probSets);
            case "npc":
                if (isNPCBoxChecked)
                    selectedNode.setNPC();
                else
                    selectedNode.setPC();
            case "text":
                dg.changeNodeText(selectedNode, textField.getText());
            case "strategy":
                strategy = Integer.parseInt(strategyField.getText());
            }
        }
    }

    JPanel fieldPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel labelPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel buttonPanel = new JPanel(new GridLayout(0, 1, 0, 0));
    JPanel masterPanel = new JPanel(new GridLayout(0, 3, 0, 0));

    //Buttons, ckeckboxes, textboxes, and labels
    textField = new JTextField("May I buy your wand?", 10);
    fieldPanel.add(textField);
    labelPanel.add(new JLabel("Node Text"));
    JButton button1 = new JButton("Change");
    button1.setActionCommand("text");
    button1.addActionListener(new ActionHandler());
    buttonPanel.add(button1);

    npcBox = new JCheckBox();
    npcBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.DESELECTED)
                isNPCBoxChecked = false;
            else
                isNPCBoxChecked = true;
        }
    });
    fieldPanel.add(npcBox);
    labelPanel.add(new JLabel("NPC"));
    JButton button2 = new JButton("Change");
    button2.setActionCommand("npc");
    button2.addActionListener(new ActionHandler());
    buttonPanel.add(button2);

    childrenField = new JTextField("child1,child2", 10);
    fieldPanel.add(childrenField);
    labelPanel.add(new JLabel("Children"));
    JButton button3 = new JButton("");
    buttonPanel.add(button3);

    probSetField = new JTextField("0.1,0.9", 10);
    fieldPanel.add(probSetField);
    labelPanel.add(new JLabel("Probability set"));
    JButton button4 = new JButton("Change");
    button4.setActionCommand("probSet");
    button4.addActionListener(new ActionHandler());
    buttonPanel.add(button4);

    strategyField = new JTextField("0", 10);
    fieldPanel.add(strategyField);
    labelPanel.add(new JLabel("Strategy"));
    JButton button5 = new JButton("Change");
    button5.setActionCommand("strategy");
    button5.addActionListener(new ActionHandler());
    buttonPanel.add(button5);

    masterPanel.add(buttonPanel);
    masterPanel.add(fieldPanel);
    masterPanel.add(labelPanel);

    JFrame frame = new JFrame("Node Properties");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    fieldPanel.setOpaque(true);
    frame.setContentPane(masterPanel);
    frame.pack();
    frame.setLocation(windowWidth, verticalWindowPlacement);
    frame.setVisible(true);

    verticalWindowPlacement += frame.getBounds().height;
}

From source file:ButtonListener.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals("Button1")) {
        System.out.println("Button1 has been clicked");
    }/*  ww w .jav  a  2  s. c o  m*/
}

From source file:Main.java

public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equals("TF")) {
        System.out.println("ENTER key pressed: " + jtf.getText());
    } else {//from   ww w  .  j  ava2 s . com
        String str = jtf.getText().toUpperCase();
        System.out.println("Button pressed: " + str);
    }
}

From source file:MyActionListener.java

public void actionPerformed(ActionEvent e) {
    System.out.println("Command: " + e.getActionCommand());
    Object source = e.getSource();
    if (source instanceof JButton) {
        JButton jb = (JButton) source;
        System.out.println("JButton: " + jb.getText());
    }//from w ww  .ja v a2 s  .  c o  m
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand() != null) {
        String command = e.getActionCommand();
        if (command != null) {
            command = command.toUpperCase();
        }//from   ww  w. ja v a 2 s .com
        e = new ActionEvent(e.getSource(), e.getID(), command, e.getModifiers());
    }

    if (defAction != null) {
        defAction.actionPerformed(e);
    }
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    textArea.append(e.getActionCommand() + "\n");
}

From source file:ButtonDemo.java

public void actionPerformed(ActionEvent ae) {
    String ac = ae.getActionCommand();

    if (ac.equals("Alpha")) {
        if (jbtnB.isEnabled()) {
            System.out.println("Alpha pressed. Beta is disabled.");
            jbtnB.setEnabled(false);// w  w  w . ja  v a2  s  . c  o m
        } else {
            System.out.println("Alpha pressed. Beta is enabled.");
            jbtnB.setEnabled(true);
        }
    } else if (ac.equals("Beta"))
        System.out.println("Beta pressed.");
}