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:components.TablePrintDemo.java

public TablePrintDemo() {
    super();/*from   w  w w .j  av a 2  s.  c o m*/
    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

    table = new JTable(new MyTableModel());
    table.setPreferredScrollableViewportSize(new Dimension(500, 70));
    table.setFillsViewportHeight(true);

    //Create the scroll pane and add the table to it.
    JScrollPane scrollPane = new JScrollPane(table);

    //Add the scroll pane to this panel.
    add(scrollPane);

    //Add a print button.
    JButton printButton = new JButton("Print");
    printButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    printButton.addActionListener(this);
    add(printButton);

}

From source file:com.polivoto.vistas.Editor.java

/**
 * Ventana Editor - configura el color de las preguntas.
 *///from  w ww .j av  a2  s. c  o m
public Editor(JSONArray js) {
    initComponents();
    for (int i = 0; i < js.length(); i++) {
        try {
            JPanel panel = new JPanel(new GridLayout(0, 2, 10, 10));
            panel.setBackground(new Color(255, 255, 255));
            jTabbedPane.add(panel, "Pregunta " + (i + 1));
            JLabel lab1 = new JLabel(
                    "Pregunta " + (i + 1) + ": " + ((JSONObject) js.get(i)).getString("pregunta"), JLabel.LEFT);
            lab1.setFont(new Font("Roboto", 1, 18));
            lab1.setForeground(new Color(134, 36, 31));
            panel.add(lab1);
            panel.add(new JLabel(""));
            JSONArray jarr = ((JSONObject) js.get(i)).getJSONArray("opciones");
            for (int j = 0; j < jarr.length(); j++) {
                JLabel lab2 = new JLabel("Opcin " + (j + 1) + ": " + jarr.getString(j), JLabel.LEFT);
                JButton colBut = new JButton("Seleccionar color de la opcin");
                colBut.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        jFrame1.setVisible(true);
                    }
                });
                lab2.setFont(new Font("Roboto", 1, 15));
                lab2.setForeground(new Color(0, 0, 0));
                panel.add(lab2);
                panel.add(colBut);
            }

        } catch (JSONException ex) {
            Logger.getLogger(AnalistaLocal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:com.streamhub.StreamHubLicenseGenerator.java

private JPanel createActionsRow() {
    JPanel actionsRow = new JPanel(new FlowLayout());
    File baseFolder = new File(DEFAULT_CUSTOMERS_DIRECTORY);
    JButton generate = new JButton("Generate");
    generate.addActionListener(new ActionListener() {
        @Override/*w  w w.  ja  v a  2 s .c om*/
        public void actionPerformed(ActionEvent e) {
            for (JPanel row : macAddressPanels) {
                try {
                    String macAddress = ((JTextField) row.getComponent(1)).getText();
                    if (macAddress.length() > 0) {
                        String startDate = ((JTextField) row.getComponent(3)).getText();
                        String expiryDate = ((JTextField) row.getComponent(5)).getText();
                        String edition = ((JComboBox) row.getComponent(6)).getSelectedItem().toString();
                        macAddress = macAddress.replaceAll("-", ":").trim();
                        String name = ((JTextField) row.getComponent(8)).getText().trim();
                        String numUsers = ((JTextField) row.getComponent(10)).getText();
                        String licenseString = startDate + "-" + expiryDate + "-" + numUsers + "-" + macAddress
                                + "-" + edition + ":" + name;
                        String hashInput = licenseString + USELESS_KEY;
                        MessageDigest m = MessageDigest.getInstance("SHA-512");
                        m.update(hashInput.getBytes(), 0, hashInput.length());
                        String hash = "==" + new BigInteger(1, m.digest()).toString(16) + "==";
                        StringBuilder licenseText = new StringBuilder();
                        licenseText.append("--").append(licenseString).append("--");
                        licenseText.append(CRLF);
                        licenseText.append(hash);
                        licenseText.append(CRLF);
                        System.out.println(name + ":");
                        System.out.println();
                        System.out.println(licenseText);

                        File licenseDir = new File(folderChooser.getSelectedFile(), name);
                        if (!licenseDir.isDirectory() && !licenseDir.exists()) {
                            licenseDir.mkdir();
                        }
                        File licenseFile = new File(licenseDir, "license.txt");
                        System.out.println("writing to " + licenseFile.getAbsolutePath());
                        FileUtils.writeStringToFile(licenseFile, licenseText.toString());
                    }
                } catch (Exception exception) {
                    System.out.println("Could not generate license");
                    exception.printStackTrace();
                }
            }
        }
    });
    final JButton chooseFolder = new JButton("Choose Folder");
    final JTextField folderDisplay = new JTextField(baseFolder.getAbsolutePath());
    folderChooser = new JFileChooser(baseFolder);
    folderChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    folderChooser.setSelectedFile(baseFolder);
    chooseFolder.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == chooseFolder) {
                int returnVal = folderChooser.showOpenDialog(StreamHubLicenseGenerator.this);

                if (returnVal == JFileChooser.APPROVE_OPTION) {
                    File folder = folderChooser.getSelectedFile();
                    folderDisplay.setText(folder.getAbsolutePath());
                }
            }
        }
    });

    actionsRow.add(folderDisplay);
    actionsRow.add(chooseFolder);
    actionsRow.add(generate);
    return actionsRow;
}

From source file:eu.delving.sip.actions.ImportAction.java

private void prepareDialog() {
    JButton cancel = new JButton("Cancel");
    cancel.addActionListener(new ActionListener() {
        @Override// www.  j av  a 2s . c  o m
        public void actionPerformed(ActionEvent actionEvent) {
            dialog.setVisible(false);
        }
    });
    JPanel bp = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    bp.add(cancel);
    JPanel p = new JPanel(new GridLayout(1, 0, 15, 15));
    p.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
    p.add(new JButton(chooseFileAction));
    p.add(new JButton(harvestAction));
    dialog.getContentPane().add(p, BorderLayout.CENTER);
    dialog.getContentPane().add(bp, BorderLayout.SOUTH);
    dialog.pack();
}

From source file:DynamicDataDemo.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./*from   w w  w.  ja va  2  s .c  om*/
 */
public DynamicDataDemo(final String title, String xcoor, String ycoor, String data) {

    super(title);
    this.series = new TimeSeries(data, Millisecond.class);
    final TimeSeriesCollection dataset = new TimeSeriesCollection(this.series);
    final JFreeChart chart = createChart(dataset, title, xcoor, ycoor);

    final ChartPanel chartPanel = new ChartPanel(chart);
    final JButton button = new JButton("Add New Data Item");
    button.setActionCommand("ADD_DATA");
    button.addActionListener(this);

    content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    //setContentPane(content);

}

From source file:fi.smaa.jsmaa.gui.views.ResultsView.java

@SuppressWarnings("serial")
private Component buildExportButton() {
    JButton exportButton = new JideButton("Export figure dataset as GNUPlot script",
            ImageFactory.IMAGELOADER.getIcon(scriptIcon));
    exportButton.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            PlotConverter c = PlotConverterFactory
                    .getConverter((SMAADataSet<?>) ((CategoryPlot) chart.getPlot()).getDataset());
            GNUPlotDialog d = new GNUPlotDialog(null, c);
            GUIHelper.centerWindow(d, parent);
            d.setVisible(true);// www  . ja v  a 2  s .c  o m
        }
    });
    return exportButton;
}

From source file:hr.restart.util.chart.ChartXYZ2.java

public void initFrame() throws Exception {

    super.initFrame();

    if (optionPanel != null)
        return;//from  ww w  .ja  v  a 2 s .c o  m

    optionPanel = new JPanel(new BorderLayout());
    JButton btOptions = new JButton("Opcije prikaza");
    btOptions.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (optionPanel != null && optionPanel.isVisible())
                showOptions();
        }
    });
    optionPanel.add(btOptions);
    buttonsPanel.add(optionPanel);
}

From source file:org.apache.commons.httpclient.contrib.proxy.PluginProxyTestApplet.java

@Override
public void init() {
    Container content = getContentPane();
    content.setLayout(new BorderLayout());

    // Proxy info table
    grid = getPanel(new GridLayout(2, 3, 2, 2));
    grid.add(getHeaderLabel("URL"));
    grid.add(getHeaderLabel("Proxy Host"));
    grid.add(getHeaderLabel("Proxy Port"));
    grid.add(urlTextField);//from   w  ww. ja v  a2s . co m
    hostLabel = getLabel("");
    portLabel = getLabel("");
    grid.add(hostLabel);
    grid.add(portLabel);
    grid.validate();
    content.add(grid, BorderLayout.CENTER);

    // Button panel - SOUTH
    JPanel buttonPanel = getPanel(new FlowLayout());
    JButton button = new JButton("Detect Proxy");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    detectProxy();
                }
            });
        }
    });
    buttonPanel.add(button);
    content.add(buttonPanel, BorderLayout.SOUTH);

    // version panel - NORTH
    JPanel versionPanel = getPanel(new FlowLayout());
    String javaVersion = System.getProperty("java.runtime.version");
    JLabel versionLabel = getLabel("Java Version: " + javaVersion);
    versionPanel.add(versionLabel);
    content.add(versionPanel, BorderLayout.NORTH);
    validate();

    super.setSize(400, 100);
}

From source file:org.simbrain.plot.piechart.PieChartGui.java

/**
 * Construct the GUI Pie Chart.//from w  ww  .  j a  v  a2  s  .  co m
 *
 * @param frame Generic Frame
 * @param component Pie chart component
 */
public PieChartGui(final GenericFrame frame, final PieChartComponent component) {
    super(frame, component);
    setPreferredSize(PREFERRED_SIZE);
    actionManager = new PlotActionManager(this);
    setLayout(new BorderLayout());

    JButton deleteButton = new JButton("Delete");
    deleteButton.setActionCommand("Delete");
    deleteButton.addActionListener(this);
    JButton addButton = new JButton("Add");
    addButton.setActionCommand("Add");
    addButton.addActionListener(this);

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(deleteButton);
    buttonPanel.add(addButton);

    createAttachMenuBar();

    add("Center", chartPanel);
    add("South", buttonPanel);
}

From source file:DynamiskDemo2.java

/**
 * Constructs a new demonstration application.
 *
 * @param title  the frame title./* w  w  w .  j  av a2 s . c  o m*/
 */
public DynamiskDemo2(final String title) {

    super(title);
    this.series = new XYSeries(title, false, false);
    final XYSeriesCollection dataset = new XYSeriesCollection(this.series);
    final JFreeChart chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);
    final JButton button = new JButton("Add New Data Item");
    button.setActionCommand("ADD_DATA");
    button.addActionListener(this);

    final JPanel content = new JPanel(new BorderLayout());
    content.add(chartPanel);
    content.add(button, BorderLayout.SOUTH);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(content);
    String fil = "C:" + File.separator + "Users" + File.separator + "madso" + File.separator + "Documents"
            + File.separator + "!Privat" + File.separator + "DTU 2016-2020" + File.separator + "MATLAB";
    String filnavn = "EKGdata";
    try {
        Scanner sc = new Scanner(new FileReader(fil + File.separator + filnavn));

        Timer timer = new Timer();
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                if (sc.hasNext()) {
                    final double newItem = Double.parseDouble(sc.next());
                    series.add(x, newItem);
                    x += 10;
                }
            }

        }, 100, 2);
    } catch (IOException e) {
        e.printStackTrace();
    }
}