Example usage for java.awt.event ActionEvent getSource

List of usage examples for java.awt.event ActionEvent getSource

Introduction

In this page you can find the example usage for java.awt.event ActionEvent getSource.

Prototype

public Object getSource() 

Source Link

Document

The object on which the Event initially occurred.

Usage

From source file:Main.java

public Main() {
    // Build a mapping from book titles to their entries
    for (int i = 0; i < items.length; i++) {
        itemMap.put(items[i].getTitle(), items[i]);
    }//from   w w w .  j a v  a2  s.co m

    setLayout(new BorderLayout());

    JComboBox bookCombo = new JComboBox(items);
    bookCombo.setEditable(true);
    bookCombo.setEditor(new MyComboBoxEditor(itemMap, items[0]));
    bookCombo.setMaximumRowCount(4);
    bookCombo.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.out.println("You chose " + ((JComboBox) e.getSource()).getSelectedItem() + "!");
        }
    });
    bookCombo.setActionCommand("Hello");
    add(bookCombo, BorderLayout.CENTER);
}

From source file:jcine.CineForm.java

void chairPressed(java.awt.event.ActionEvent evt) {
    if (evt.getSource() instanceof JButton) {
        JButton btn = (JButton) evt.getSource();
        if (btn.getBackground() == Color.white) {
            btn.setBackground(null);//from  ww  w . j a v a 2 s . c o m
        } else {
            btn.setBackground(Color.white);
        }
    }
}

From source file:SwingFileChooserDemo.java

public void actionPerformed(ActionEvent e) {

    //Handle open button action.
    if (e.getSource() == openButton) {
        int returnVal = fc.showOpenDialog(SwingFileChooserDemo.this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would open the file.
            log.append("Opening: " + file.getName() + "." + newline);
        } else {/*from   w  w  w.  ja  v a2  s . co  m*/
            log.append("Open command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());

        //Handle save button action.
    } else if (e.getSource() == saveButton) {
        int returnVal = fc.showSaveDialog(SwingFileChooserDemo.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would save the file.
            log.append("Saving: " + file.getName() + "." + newline);
        } else {
            log.append("Save command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());
    }
}

From source file:com.db2eshop.gui.menu.RightClickPopupMenu.java

/** {@inheritDoc} */
@Override//from w w  w  . jav  a  2  s  .c o m
public void actionPerformed(ActionEvent arg0) {
    if (show.equals(arg0.getSource())) {
        log.debug("Show");
        showDialog.showDialog(row, table, entity);
    }

    else if (add.equals(arg0.getSource())) {
        log.debug("Add");
        addDialog.showDialog(table);
    }

    else if (edit.equals(arg0.getSource())) {
        log.debug("Edit");
        editDialog.showDialog(row, table, entity);
    }

    else if (remove.equals(arg0.getSource())) {
        log.debug("Remove");
        removeDialog.showDialog(row, table, entity);
    }

    unsetVolatile();
}

From source file:org.encog.workbench.tabs.rbf.RadialBasisFunctionsTab.java

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == this.buttonClose) {
        this.dispose();
    } else if (e.getSource() == this.typeCombo) {
        int index = this.typeCombo.getSelectedIndex();

        double[] center = { 0.0 };

        switch (index) {
        case 0://from  w ww.j a v  a2 s .  c o  m
            this.rbf = new GaussianFunction(1.0, center, 1.0);
            break;
        case 1:
            this.rbf = new MultiquadricFunction(1.0, center, 1.0);
            break;
        case 2:
            this.rbf = new InverseMultiquadricFunction(1.0, center, 1.0);
            break;
        case 3:
            this.rbf = new MexicanHatFunction(1.0, center, 1.0);
            break;
        }

        XYDataset dataset = this.createDataset();
        JFreeChart chart = this.createChart(dataset);
        this.chartPanel.setChart(chart);
    }

}

From source file:com.heatonresearch.aifh.examples.rbf.LearnIrisAnnealROC.java

/**
 * Invoked when an action occurs.//from  ww  w  . j  a  v  a2s  .c  o  m
 *
 * @param e
 */
@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == this.buttonAnneal) {
        updateChart();
    } else if (e.getSource() == this.buttonReset) {
        this.network.reset(new MersenneTwisterGenerateRandom());
        updateChart();
    }
}

From source file:ImageDrawingComponent.java

public void buildUI() {
    final ImageDrawingComponent id = new ImageDrawingComponent(imageSrc);
    add("Center", id);
    JComboBox choices = new JComboBox(id.getDescriptions());
    choices.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JComboBox cb = (JComboBox) e.getSource();
            id.setOpIndex(cb.getSelectedIndex());
            id.repaint();/*  ww  w  . j a  v a2 s  .  c o m*/
        };
    });
    add("South", choices);
}

From source file:org.apache.shiro.samples.spring.ui.WebStartView.java

public void actionPerformed(ActionEvent e) {
    try {/* w  ww. j  a va  2s. c o m*/

        if (e.getSource() == saveButton) {
            sampleManager.setValue(valueField.getText());

        } else if (e.getSource() == refreshButton) {
            updateValueLabel();

        } else if (e.getSource() == secureMethod1Button) {
            sampleManager.secureMethod1();
            JOptionPane.showMessageDialog(frame, "Method #1 successfully called.", "Success",
                    JOptionPane.INFORMATION_MESSAGE);

        } else if (e.getSource() == secureMethod2Button) {
            sampleManager.secureMethod2();
            JOptionPane.showMessageDialog(frame, "Method #2 successfully called.", "Success",
                    JOptionPane.INFORMATION_MESSAGE);
        } else if (e.getSource() == secureMethod3Button) {
            sampleManager.secureMethod3();
            JOptionPane.showMessageDialog(frame, "Method #3 successfully called.", "Success",
                    JOptionPane.INFORMATION_MESSAGE);

        } else {
            throw new RuntimeException("Unexpected action event from source: " + e.getSource());
        }

    } catch (AuthorizationException ae) {
        JOptionPane.showMessageDialog(frame, "Unauthorized to perform action: " + ae.getMessage(),
                "Unauthorized", JOptionPane.WARNING_MESSAGE);
    }
}

From source file:com.santiagolizardo.madcommander.menu.FilesMenu.java

@Override
public void actionPerformed(ActionEvent ev) {
    Object source = ev.getSource();
    if (source == changeAttributesMenuItem) {
        ChangeAttributesDialog changeAttributesDialog = new ChangeAttributesDialog(mainWindow);
        changeAttributesDialog.setVisible(true);
    } else if (source == changeModificationDatetimeMenuItem) {
        ChangeModificationDateTimeDialog dialog = new ChangeModificationDateTimeDialog(mainWindow);
        dialog.setVisible(true);//from   w  w w  .j ava 2s  .com
    } else if (source == unpackMenuItem) {
        List<File> list = mainWindow.getSource().getSelectedFiles();
        if (list.size() == 1) {
            File file = list.get(0);
            StringBuilder buffer = new StringBuilder();
            buffer.append(mainWindow.getSource().getPath());
            buffer.append(File.separator);
            buffer.append(file.getName());
            UnpackDialog unpackDialog = new UnpackDialog(buffer.toString());
            unpackDialog.setVisible(true);
        } else {
            DialogFactory.showErrorMessage(mainWindow, "Only pick one file to unpack at time.");
        }
    } else if (source == printMenuItem) {
        FileListing listing = mainWindow.getSource();
        listing.print();
    } else if (source == quitMenuItem) {
        mainWindow.quit();
    } else if (source == compareByContent) {
        List<File> files1 = mainWindow.getSource().getSelectedFiles();
        List<File> files2 = mainWindow.getDestination().getSelectedFiles();
        if (files1.isEmpty() || files2.isEmpty()) {
            DialogFactory.showInformationMessage(mainWindow,
                    "Please select a file on each panel first to compare their contents.");
            return;
        }
        File file1 = files1.get(0);
        File file2 = files2.get(0);
        try {
            if (FileUtils.contentEquals(file1, file2) == true) {
                DialogFactory.showInformationMessage(mainWindow, "The content of the files is identical.");
            } else {
                DialogFactory.showInformationMessage(mainWindow, "The content of the files is not the same.");
            }
        } catch (IOException e) {
            DialogFactory.showErrorMessage(mainWindow, "Could not compare the contents of the files.");
        }
    }
}

From source file:org.wsm.database.tools.editor.ui.GraphPane.java

/**
 * Invoked when an action occurs./*w w w . j ava2s .c  o  m*/
 */
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == viewBarGraph) {
        JFreeChart chart = getChart(CHART_TYPE_BAR_3D);
        chart.setBackgroundPaint(Color.white);
        cp.setChart(chart);
    }
    if (e.getSource() == viewLineGraph) {
        JFreeChart chart = getChart(CHART_TYPE_LINE_3D);
        chart.setBackgroundPaint(Color.white);
        cp.setChart(chart);
    }

}