Example usage for javax.swing JButton addActionListener

List of usage examples for javax.swing JButton addActionListener

Introduction

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

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:com.emental.mindraider.ui.dialogs.FtsJDialog.java

public FtsJDialog() {
    super(Messages.getString("FtsJDialog.title"));

    JPanel dialogPanel = new JPanel();
    dialogPanel.setBorder(new EmptyBorder(5, 10, 0, 10));
    dialogPanel.setLayout(new BorderLayout());

    JPanel contentAndButtons = new JPanel(new GridLayout(2, 1));
    JPanel contentPanel = new JPanel(new BorderLayout());

    // 1a./*from   w w w  .  j a v a 2 s .co  m*/
    // TODO add help like in eclipse
    contentPanel.add(new JLabel(Messages.getString("FtsJDialog.searchString")), BorderLayout.NORTH);
    // 1b.
    String[] knownSearches = new String[] { "", "RDF", "mind", "concept", "China" };
    ftsCombo = new JComboBox(knownSearches);
    ftsCombo.setPreferredSize(new Dimension(200, 18));
    ftsCombo.setEditable(true);
    ftsCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if ("comboBoxEdited".equals(e.getActionCommand())) {
                search();
            }
        }
    });
    contentPanel.add(ftsCombo, BorderLayout.SOUTH);
    contentAndButtons.add(contentPanel);

    // 2.
    JPanel p = new JPanel();
    p.setLayout(new FlowLayout(FlowLayout.CENTER, 1, 5));
    JButton searchButton = new JButton(Messages.getString("FtsJDialog.searchButton"));
    searchButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            search();
        }
    });
    p.add(searchButton);

    JButton cancelButton = new JButton(Messages.getString("FtsJDialog.cancel"));
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    p.add(cancelButton);

    contentAndButtons.add(p);

    dialogPanel.add(contentAndButtons, BorderLayout.CENTER);

    getContentPane().add(dialogPanel, BorderLayout.CENTER);

    // show
    pack();
    Gfx.centerAndShowWindow(this);
}

From source file:PostTest.java

public PostTestFrame() {
    setTitle("PostTest");

    northPanel = new JPanel();
    add(northPanel, BorderLayout.NORTH);
    northPanel.setLayout(new GridLayout(0, 2));
    northPanel.add(new JLabel("Host: ", SwingConstants.TRAILING));
    final JTextField hostField = new JTextField();
    northPanel.add(hostField);/*from  w  ww  . j ava2  s.co  m*/
    northPanel.add(new JLabel("Action: ", SwingConstants.TRAILING));
    final JTextField actionField = new JTextField();
    northPanel.add(actionField);
    for (int i = 1; i <= 8; i++)
        northPanel.add(new JTextField());

    final JTextArea result = new JTextArea(20, 40);
    add(new JScrollPane(result));

    JPanel southPanel = new JPanel();
    add(southPanel, BorderLayout.SOUTH);
    JButton addButton = new JButton("More");
    southPanel.add(addButton);
    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            northPanel.add(new JTextField());
            northPanel.add(new JTextField());
            pack();
        }
    });

    JButton getButton = new JButton("Get");
    southPanel.add(getButton);
    getButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            result.setText("");
            final Map<String, String> post = new HashMap<String, String>();
            for (int i = 4; i < northPanel.getComponentCount(); i += 2) {
                String name = ((JTextField) northPanel.getComponent(i)).getText();
                if (name.length() > 0) {
                    String value = ((JTextField) northPanel.getComponent(i + 1)).getText();
                    post.put(name, value);
                }
            }
            new SwingWorker<Void, Void>() {
                protected Void doInBackground() throws Exception {
                    try {
                        String urlString = hostField.getText() + "/" + actionField.getText();
                        result.setText(doPost(urlString, post));
                    } catch (IOException e) {
                        result.setText("" + e);
                    }
                    return null;
                }
            }.execute();
        }
    });

    pack();
}

From source file:net.sf.jabref.external.push.AbstractPushToApplication.java

/**
 * Create a FormBuilder, fill it with a textbox for the path and store the JPanel in settings
 *//*from ww  w  .ja va  2s .com*/
protected void initSettingsPanel() {
    builder = FormBuilder.create();
    builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p"));
    StringBuilder label = new StringBuilder(Localization.lang("Path to %0", getApplicationName()));
    // In case the application name and the actual command is not the same, add the command in brackets
    if (getCommandName() == null) {
        label.append(':');
    } else {
        label.append(" (").append(getCommandName()).append("):");
    }
    builder.add(label.toString()).xy(1, 1);
    builder.add(path).xy(3, 1);
    BrowseAction action = BrowseAction.buildForFile(path);
    JButton browse = new JButton(Localization.lang("Browse"));
    browse.addActionListener(action);
    builder.add(browse).xy(5, 1);
    settings = builder.build();
}

From source file:SampleButton.java

public SampleButton() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel(new BorderLayout());
    p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    JButton b = new JButton("Test");
    b.setHorizontalTextPosition(SwingConstants.LEFT);
    b.setIcon(new ImageIcon("r.gif"));
    b.setRolloverIcon(new ImageIcon("b.gif"));
    b.setRolloverEnabled(true);//from   w w w . j a v  a2 s  .com

    b.setMnemonic('t');
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("Button pressed");
        }
    });
    p.add(b);
    getContentPane().add(p);
    pack();
}

From source file:gov.nih.nci.nbia.StandaloneDM.java

private JPanel constructLoginPanel() {
    JPanel contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(null);/*from   ww w  .j  av a2s  .com*/

    JLabel lblNewLabel_2 = new JLabel();
    lblNewLabel_2.setBounds(20, 11, 100, 100);
    contentPane.add(lblNewLabel_2);
    ImageIcon iconLogo = new ImageIcon("Images/global.logo");
    lblNewLabel_2.setIcon(iconLogo);
    statusLbl = new JLabel(
            "<html>Some or all of the images you are about to download are from<br>private collection(s). Please log in first.</html>");
    contentPane.add(statusLbl);
    statusLbl.setBounds(110, 11, 500, 42);
    JLabel lblNewLabel = new JLabel("User Name");
    contentPane.add(lblNewLabel);
    lblNewLabel.setBounds(110, 79, 77, 31);

    userNameFld = new JTextField();
    contentPane.add(userNameFld);
    userNameFld.setBounds(187, 75, 333, 36);
    userNameFld.setColumns(10);

    JButton submitBtn = new JButton(SubmitBtnLbl);
    submitBtn.addActionListener(new BtnListener());
    contentPane.add(submitBtn);
    submitBtn.setBounds(249, 200, 139, 36);

    passwdFld = new JPasswordField();
    contentPane.add(passwdFld);
    passwdFld.setBounds(187, 129, 333, 36);

    userNameFld.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            passwdFld.requestFocus();
        }
    });

    passwdFld.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            userId = userNameFld.getText();
            password = passwdFld.getText();
            if ((userId.length() < 1) || (password.length() < 1)) {
                statusLbl.setText("Please enter a valid user name and password.");
                statusLbl.setForeground(Color.red);
            } else
                submitUserCredential(userId, password);
        }
    });

    JLabel lblNewLabel_1 = new JLabel("Password");
    contentPane.add(lblNewLabel_1);
    lblNewLabel_1.setBounds(110, 129, 77, 36);

    return contentPane;
}

From source file:br.com.criativasoft.opendevice.samples.ui.SimpleChart.java

public SimpleChart(final String title, final StreamConnection connection) {
    super(title);

    dataset = new DynamicTimeSeriesCollection(SERIES, COUNT, new Second());
    dataset.setTimeBase(new Second(0, 0, 0, 1, 1, Calendar.getInstance().get(Calendar.YEAR)));

    // Init.//from  www  .j  a va2  s  . c  om
    //        for (int i = 0; i < SERIES; i++){
    //            dataset.addSeries(new float[]{0}, i, "Serie " + (i+1));
    //        }
    dataset.addSeries(new float[] { 0, 0, 0 }, 0, "Raw");
    dataset.addSeries(new float[] { 0, 0, 0 }, 1, "Software");
    dataset.addSeries(new float[] { 0, 0, 0 }, 2, "Hardware");

    this.connection = connection;

    // connection.setStreamReader(new FixedStreamReader(1));

    JFreeChart chart = createChart(dataset);

    final JButton run = new JButton(START);
    run.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            String cmd = e.getActionCommand();
            JButton source = (JButton) e.getSource();

            try {

                if (cmd.equals(START)) {
                    connection.addListener(SimpleChart.this);
                    if (!connection.isConnected())
                        connection.connect();

                    source.setText(STOP);
                    source.setActionCommand(STOP);
                } else {
                    connection.removeListener(SimpleChart.this);
                    source.setText(START);
                    source.setActionCommand(START);
                }

            } catch (ConnectionException e1) {
                e1.printStackTrace();
            }

        }
    });

    final JComboBox combo = new JComboBox();

    if (connection instanceof UsbConnection) {

        Collection<String> portNames = UsbConnection.listAvailablePortNames();
        for (String name : portNames) {
            combo.addItem(name);
        }

    }

    combo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {

            Object selectedItem = combo.getSelectedItem();

        }
    });

    this.add(new ChartPanel(chart), BorderLayout.CENTER);
    JPanel btnPanel = new JPanel(new FlowLayout());
    btnPanel.add(run);
    btnPanel.add(combo);
    this.add(btnPanel, BorderLayout.SOUTH);

}

From source file:com.ibm.watson.WatsonVRTraining.util.images.PhotoCaptureFrame.java

PhotoCaptureFrame() {
    jp = new JPanel();
    jp.setLayout(new BoxLayout(jp, BoxLayout.Y_AXIS));

    JScrollPane scrollPane = new JScrollPane(jp);
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    scrollPane.setPreferredSize(new Dimension(dim.width / 2 - 40, dim.height - 117));

    JButton btn = new JButton("Upload Image");

    btn.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser fc = new JFileChooser(System.getenv("user.home"));
            fc.setFileFilter(new JPEGImageFileFilter());
            int res = fc.showOpenDialog(null);
            // We have an image!
            try {
                if (res == JFileChooser.APPROVE_OPTION) {
                    File file = fc.getSelectedFile();
                    //SharedResources.sharedCache.getCapturedImageList().add(file);
                    File tmpf_name = File.createTempFile("tmp",
                            "." + FilenameUtils.getExtension(file.getName()));
                    System.out.println("cp " + file.getPath() + " " + AppConstants.vr_process_img_dir_path
                            + File.separator + tmpf_name.getName());
                    new CommandsUtils().executeCommand("bash", "-c", "cp " + file.getPath() + " "
                            + AppConstants.vr_process_img_dir_path + File.separator + tmpf_name.getName());
                }/*  w  w  w.ja v  a 2  s .  c o m*/
            } catch (Exception iOException) {
            }

        }
    });

    ImageRemainingProcessingLabel = new JLabel("REMAINIG IMAGES:0");
    ImageRemainingProcessingLabel.setHorizontalAlignment(SwingConstants.LEFT);
    ImageRemainingProcessingLabel.setFont(new Font("Arial", Font.BOLD, 13));

    ImagebeingProcessedLabel = new JLabel(" PROCESSING IMAGES:0");
    ImagebeingProcessedLabel.setHorizontalAlignment(SwingConstants.LEFT);
    ImagebeingProcessedLabel.setFont(new Font("Arial", Font.BOLD, 13));

    appIDLabel = new JLabel("APP-ID:" + AppConstants.unique_app_id);
    appIDLabel.setHorizontalAlignment(SwingConstants.LEFT);
    appIDLabel.setFont(new Font("Arial", Font.BOLD, 13));

    headerPanel = new JPanel(new FlowLayout());
    headerPanel.add(ImageRemainingProcessingLabel);
    headerPanel.add(ImagebeingProcessedLabel);
    headerPanel.add(btn);
    headerPanel.add(appIDLabel);
    headerPanel.setSize(new Dimension(getWidth(), 10));

    JPanel contentPane = new JPanel();
    contentPane.add(headerPanel);
    contentPane.add(scrollPane);
    f = new JFrame("IBM Watson Visual Prediction Window");
    f.setContentPane(contentPane);
    f.setSize(dim.width / 2 - 30, dim.height - 40);
    f.setLocation(dim.width / 2, 0);
    f.setResizable(false);
    f.setPreferredSize(new Dimension(dim.width / 2 - 30, dim.height - 60));
    f.setVisible(true);
}

From source file:io.datalayer.jung.SdpGraphMLDemo.java

/**
 * create an instance of a simple graph with controls to demo the zoom
 * features./*  ww w .j  ava  2  s . com*/
 * 
 * @throws SAXException
 * @throws ParserConfigurationException
 * @throws IOException
 */
public SdpGraphMLDemo(String filename) throws ParserConfigurationException, SAXException, IOException {

    Factory<Number> vertexFactory = new Factory<Number>() {

        int n = 0;

        public Number create() {

            return n++;
        }
    };
    Factory<Number> edgeFactory = new Factory<Number>() {

        int n = 0;

        public Number create() {

            return n++;
        }
    };

    GraphMLReader<DirectedGraph<Number, Number>, Number, Number> gmlr = new GraphMLReader<DirectedGraph<Number, Number>, Number, Number>(
            vertexFactory, edgeFactory);
    final DirectedGraph<Number, Number> graph = new DirectedSparseMultigraph<Number, Number>();
    gmlr.load(filename, graph);

    // create a simple graph for the demo
    vv = new VisualizationViewer<Number, Number>(new FRLayout<Number, Number>(graph));

    vv.addGraphMouseListener(new TestGraphMouseListener<Number>());
    vv.getRenderer().setVertexRenderer(new GradientVertexRenderer<Number, Number>(Color.white, Color.red,
            Color.white, Color.blue, vv.getPickedVertexState(), false));

    // add my listeners for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<Number>());
    vv.setEdgeToolTipTransformer(new Transformer<Number, String>() {

        public String transform(Number edge) {

            return "E" + graph.getEndpoints(edge).toString();
        }
    });

    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Number>());
    vv.getRenderer().getVertexLabelRenderer().setPositioner(new InsidePositioner());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Renderer.VertexLabel.Position.AUTO);

    // create a frome to hold the graph
    final JFrame frame = new JFrame();
    Container content = frame.getContentPane();
    final GraphZoomScrollPane panel = new GraphZoomScrollPane(vv);
    content.add(panel);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final AbstractModalGraphMouse graphMouse = new DefaultModalGraphMouse<Number, Number>();
    vv.setGraphMouse(graphMouse);
    vv.addKeyListener(graphMouse.getModeKeyListener());

    JMenuBar menubar = new JMenuBar();
    menubar.add(graphMouse.getModeMenu());
    panel.setCorner(menubar);

    vv.addKeyListener(graphMouse.getModeKeyListener());
    vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode");

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JPanel controls = new JPanel();
    controls.add(plus);
    controls.add(minus);
    content.add(controls, BorderLayout.SOUTH);

    frame.pack();
    frame.setVisible(true);
}

From source file:FontPicker.java

public FontPicker() {
    super("JColorChooser Test Frame");
    setSize(200, 100);// w w w. j  av a2 s.  c o m
    final JButton go = new JButton("Show FontChooser");
    go.addActionListener(new ActionListener() {
        final FontChooser chooser = new FontChooser(FontPicker.this);

        boolean first = true;

        public void actionPerformed(ActionEvent e) {
            chooser.setVisible(true);
            // If we got a real font choice, then update our go button
            if (chooser.getNewFont() != null) {
                go.setFont(chooser.getNewFont());
                go.setForeground(chooser.getNewColor());
            }
        }
    });
    getContentPane().add(go);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:MyViewChooser.java

public MyViewChooser() {
    super("File View Test Frame");
    setSize(350, 200);//from ww w  . j a  v a2s.  c o m
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    parent = this;

    Container c = getContentPane();
    c.setLayout(new FlowLayout());

    JButton openButton = new JButton("Open");
    final JLabel statusbar = new JLabel("Output of your selection will go here");

    openButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            JFileChooser chooser = new JFileChooser();

            // Ok, set up our own file view for the chooser
            chooser.setFileView(new ThumbNailFileView(MyViewChooser.this));

            int option = chooser.showOpenDialog(parent);
            if (option == JFileChooser.APPROVE_OPTION) {
                statusbar.setText("You chose " + chooser.getSelectedFile().getName());
            } else {
                statusbar.setText("You cancelled.");
            }
        }
    });

    c.add(openButton);
    c.add(statusbar);
}