Example usage for javax.swing JButton getActionCommand

List of usage examples for javax.swing JButton getActionCommand

Introduction

In this page you can find the example usage for javax.swing JButton getActionCommand.

Prototype

public String getActionCommand() 

Source Link

Document

Returns the action command for this button.

Usage

From source file:Main.java

void addTab() {
    JEditorPane ep = new JEditorPane();
    ep.setEditable(false);/*w ww  . java 2s .  co  m*/
    tp.addTab(null, new JScrollPane(ep));

    JButton tabCloseButton = new JButton("Close");
    tabCloseButton.setActionCommand("" + tabCounter);

    ActionListener al;
    al = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JButton btn = (JButton) ae.getSource();
            String s1 = btn.getActionCommand();
            for (int i = 1; i < tp.getTabCount(); i++) {
                JPanel pnl = (JPanel) tp.getTabComponentAt(i);
                btn = (JButton) pnl.getComponent(0);
                String s2 = btn.getActionCommand();
                if (s1.equals(s2)) {
                    tp.removeTabAt(i);
                    break;
                }
            }
        }
    };
    tabCloseButton.addActionListener(al);

    if (tabCounter != 0) {
        JPanel pnl = new JPanel();
        pnl.setOpaque(false);
        pnl.add(tabCloseButton);
        tp.setTabComponentAt(tp.getTabCount() - 1, pnl);
        tp.setSelectedIndex(tp.getTabCount() - 1);
    }

    tabCounter++;
}

From source file:com.game.ui.views.MapEditor.java

@Override
public void actionPerformed(ActionEvent ae) {
    if (ae.getActionCommand().equalsIgnoreCase("Save Map")) {
        UserDialog dialog = new UserDialog("Pls Enter the Map Name.", this);
        String mapName = dialog.getValue();
        if (StringUtils.isNotBlank(mapName)) {
            GameBean.mapInfo.setMapName(mapName);
            File file = new File(Configuration.PATH_FOR_MAP);
            MapInformationWrapper wrapper = null;
            if (file.exists()) {
                try {
                    wrapper = GameUtils.readMapInformation(Configuration.PATH_FOR_MAP);
                } catch (Exception ex) {
                    ex.printStackTrace();
                }/*from  www  . j  a  v a 2s.c  o  m*/
            } else {
                wrapper = new MapInformationWrapper();
            }
            if (wrapper != null) {
                try {
                    wrapper.getMapList().add(GameBean.mapInfo);
                    GameUtils.writeMapInformation(wrapper, Configuration.PATH_FOR_MAP);
                    JOptionPane.showMessageDialog(this, "Saved Successfully..");
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
    } else {
        JButton src = (JButton) ae.getSource();
        String location = src.getActionCommand();
        GameBean.mapInfo.getPathMap().put(Integer.parseInt(location), null);
        GameBean.mapInfo.getStartPointInfo().remove(new Integer(location));
        new ComplexDialog(location);
        TileInformation info = GameBean.mapInfo.getPathMap().get(Integer.parseInt(location));
        if (info != null) {
            if (info.isStartTile()) {
                src.setBackground(Configuration.startPointColor);
            } else if (info.isEndTile()) {
                src.setBackground(Configuration.endPointColor);
            } else if (info.getEnemy() != null) {
                src.setBackground(Configuration.enemyColor);
            } else {
                src.setBackground(Configuration.pathColor);
            }
        } else {
            Color color = UIManager.getColor("Button.background");
            src.setBackground(color);
        }
    }
}

From source file:com.ssn.event.controller.SSNShareController.java

@Override
public void actionPerformed(ActionEvent e) {
    Object actionEventObj = e.getSource();
    if (actionEventObj != null && actionEventObj instanceof JButton) {
        JButton button = (JButton) actionEventObj;
        String actionCommand = button.getActionCommand();
        if (actionCommand != null && actionCommand.equals("Cancel")) {
            shareForm.dispose();/*from   w ww  .j a  va 2  s . c  o m*/
            HttpServer httpserver = SSNHttpServer.getHttpServer();
            if (httpserver != null) {
                httpserver.stop(1);
            }
        }
    }

}

From source file:com.ssn.event.controller.SSNUntaggedMediaController.java

@Override
public void actionPerformed(ActionEvent e) {
    Object actionEventObj = e.getSource();
    if (actionEventObj != null && actionEventObj instanceof JButton) {
        JButton button = (JButton) actionEventObj;
        String actionCommand = button.getActionCommand();
        if (actionCommand != null && actionCommand.equals("Cancel")) {
            SSNHomeController.isUnTaggedOpen = false;
            untaggedMediaForm.dispose();
        }//from  w w w.j av a 2s.  com
    }

}

From source file:org.openmicroscopy.shoola.agents.metadata.editor.EditorControl.java

/**
 * Removes the tags or files.//from w  w w.  j a v a2s . c o  m
 * @see MouseListener#mouseReleased(MouseEvent)
 */
public void mouseReleased(MouseEvent e) {
    JButton src = (JButton) e.getSource();
    if (!src.isEnabled())
        return;
    int index = Integer.parseInt(src.getActionCommand());
    Point p = e.getPoint();
    switch (index) {
    case REMOVE_TAGS:
        view.removeTags(src, p);
        break;
    case REMOVE_DOCS:
        view.removeAttachedFiles(src, p);
        break;
    case REMOVE_OTHER_ANNOTATIONS:
        view.removeOtherAnnotations(src, p);
    }
}