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

public MessageDigestFrame() {
    setTitle("MessageDigestTest");
    setSize(400, 200);/*w  ww .j a v a 2  s  . c  o m*/
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    });

    JPanel panel = new JPanel();
    ButtonGroup group = new ButtonGroup();
    ActionListener listener = new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            JCheckBox b = (JCheckBox) event.getSource();
            setAlgorithm(b.getText());
        }
    };
    addCheckBox(panel, "SHA-1", group, true, listener);
    addCheckBox(panel, "MD5", group, false, listener);

    Container contentPane = getContentPane();

    contentPane.add(panel, "North");
    contentPane.add(new JScrollPane(message), "Center");
    contentPane.add(digest, "South");
    digest.setFont(new Font("Monospaced", Font.PLAIN, 12));

    setAlgorithm("SHA-1");

    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("File");
    JMenuItem fileDigestItem = new JMenuItem("File digest");
    fileDigestItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            loadFile();
        }
    });
    menu.add(fileDigestItem);
    JMenuItem textDigestItem = new JMenuItem("Text area digest");
    textDigestItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            String m = message.getText();
            computeDigest(m.getBytes());
        }
    });
    menu.add(textDigestItem);
    menuBar.add(menu);
    setJMenuBar(menuBar);
}

From source file:lockers.FrameCobro.java

private void getRates() {
    JSONArray array = Utils.getJSONArrayFromURL("http://127.0.0.1:8000/Rates/?format=json");

    if (array.size() == 0) {
        this.jLblAvailableLockers.setText("No hay disponibilidad");
    } else {/*from  ww  w . j  a  v a 2 s .c  om*/
        for (Object array1 : array) {
            JButton nuevo = new JButton();
            JSONObject obj2 = (JSONObject) array1;
            System.out.println(obj2.size());
            nuevo.setText(obj2.get("rate_name") + ": " + obj2.get("rate_rate"));
            nuevo.setVisible(true);
            nuevo.setSize(200, 50);
            nuevo.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Object source = e.getSource();

                    if (source instanceof JButton) {
                        JButton btn = (JButton) source;
                        System.out.println("You clicked the button " + btn.getText());
                    }
                }
            });
            this.jPanel1.add(nuevo);
        }

    }

}

From source file:BouncingBall.java

public void actionPerformed(ActionEvent e) {
    // start timer when button is pressed
    if (e.getSource() == go) {
        if (!timer.isRunning()) {
            timer.start();//from ww  w  .j a  v a  2  s .c  o m
        }
    } else {
        height += .1 * sign;
        if (Math.abs(height * 2) >= 1)
            sign = -1.0f * sign;
        if (height < -0.4f) {
            trans.setScale(new Vector3d(1.0, .8, 1.0));
        } else {
            trans.setScale(new Vector3d(1.0, 1.0, 1.0));
        }
        trans.setTranslation(new Vector3f(xloc, height, 0.0f));
        objTrans.setTransform(trans);
    }
}

From source file:InternalFrameListenerDemo.java

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == m_newFrame)
        newFrame();/*from  w ww  .ja  v a 2 s. c om*/
    else if (e.getSource() == m_eventTimer) {
        m_ifEventCanvas.render(getCounts());
        clearCounts();
    } else if (e.getSource() == m_UIBox) {
        try {
            m_UIBox.hidePopup(); //BUG WORKAROUND
            UIManager.setLookAndFeel(m_infos[m_UIBox.getSelectedIndex()].getClassName());
            SwingUtilities.updateComponentTreeUI(this);
        } catch (Exception ex) {
            System.out.println("Could not load " + m_infos[m_UIBox.getSelectedIndex()].getClassName());
        }
    }
}

From source file:SimpleTransform.java

/**
 * This processes the AWT events and performs the appropriate operations.
 * The exit button causes the program to terminate, the left button causes a
 * rotation to be applied to the shape's transformation to spin it to the
 * left and the right has the similar effect but to the right button.
 * /*from w w w  .j a  v a 2  s  . com*/
 * @param e
 *            ActionEvent that has been performed
 */
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == exitButton) {
        dispose();
        System.exit(0);
    } else if (e.getSource() == leftButton) {
        //Create a temporary transform
        Transform3D temp = new Transform3D();
        //Read the transform from the shape
        rotationGroup.getTransform(temp);
        //Create a rotation that will be applied
        Transform3D tempDelta = new Transform3D();
        tempDelta.rotY(-0.3);
        //Apply the rotation
        temp.mul(tempDelta);
        //Write the value back into the scene graph
        rotationGroup.setTransform(temp);
    } else if (e.getSource() == rightButton) {
        //Do the same for the right rotation
        Transform3D temp = new Transform3D();
        rotationGroup.getTransform(temp);
        Transform3D tempDelta = new Transform3D();
        tempDelta.rotY(0.3);
        temp.mul(tempDelta);
        rotationGroup.setTransform(temp);
    }
}

From source file:Main.java

public TestPane() {
    label = new JLabel("...");
    setLayout(new GridBagLayout());
    add(label);/* w  w  w .  j a  v  a  2 s .  c  o m*/
    timer = new Timer(500, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            count++;
            if (count < 100000) {
                label.setText(Integer.toString(count));
            } else {
                ((Timer) (e.getSource())).stop();
            }
        }
    });
    timer.setInitialDelay(0);
    timer.start();
}

From source file:FillViewportHeightDemo.java

public void actionPerformed(ActionEvent ae) {
    if (ae.getSource() == fillBox) {
        table.setFillsViewportHeight(fillBox.isSelected());
    } else {/*  w  ww.ja v a  2s  . com*/
        tableModel.setRowCount(0);
        count = 0;
        model.removeAllElements();
        model.insertElementAt(getNextString(count++), 0);
    }
}

From source file:MainClass.java

public void actionPerformed(ActionEvent actionEvent) {
    try {//  ww w .ja va 2 s.  c om
        undoManager.undo();
    } catch (CannotUndoException cannotUndoException) {
        showMessage(actionEvent.getSource());
    }
}

From source file:MainClass.java

public void actionPerformed(ActionEvent actionEvent) {
    try {/*from w  ww.jav a  2  s  .  c om*/
        undoManager.redo();
    } catch (CannotRedoException cannotRedoException) {
        showMessage(actionEvent.getSource());
    }
}

From source file:MainClass.java

public MainClass() {
    // Build a mapping from book titles to their entries
    for (int i = 0; i < items.length; i++) {
        itemMap.put(items[i].getTitle(), items[i]);
    }/*w ww . j  a va2 s  .c  o 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);
}