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

public void actionPerformed(ActionEvent e) {
    if (e.getSource() == m_newFrame)
        newFrame();/*from  ww w  .jav a 2 s  . c om*/
    else if (e.getSource() == m_UIBox) {
        m_UIBox.hidePopup(); // BUG WORKAROUND
        try {
            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:ImageViewer.java

public void actionPerformed(ActionEvent evt) {
    Object source = evt.getSource();
    if (source == openItem) {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(new File("."));

        chooser.setFileFilter(new javax.swing.filechooser.FileFilter() {
            public boolean accept(File f) {
                return f.getName().toLowerCase().endsWith(".gif") || f.isDirectory();
            }/*from www.  java2 s  .c  o m*/

            public String getDescription() {
                return "GIF Images";
            }
        });

        int r = chooser.showOpenDialog(this);
        if (r == JFileChooser.APPROVE_OPTION) {
            String name = chooser.getSelectedFile().getName();
            label.setIcon(new ImageIcon(name));
        }
    } else if (source == exitItem)
        System.exit(0);
}

From source file:MyActionListener.java

public void actionPerformed(ActionEvent e) {
    System.out.println("Command: " + e.getActionCommand());
    Object source = e.getSource();
    if (source instanceof JButton) {
        JButton jb = (JButton) source;
        System.out.println("JButton: " + jb.getText());
    }/*from   w  ww .ja v  a  2  s  . c  o  m*/
}

From source file:DynamicHookupTest.java

public void actionPerformed(ActionEvent e) {
    Target target = (Target) actions.get(e.getSource());
    if (target == null)
        throw new RuntimeException("unknown source");
    invokeReflectedMethod(target.object, target.methodName, null, null);
}

From source file:com.github.fritaly.dualcommander.UserPreferencesPanel.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource() == checkBox) {
        preferences.setShowHidden(!preferences.isShowHidden());
    }//from   www.  ja v  a 2s  . c  o  m
}

From source file:ColorPicker.java

public ColorPicker() {
    super("JColorChooser Test Frame");
    setSize(200, 100);/*from   w w  w .  j  a v  a 2 s.c  o  m*/
    final Container contentPane = getContentPane();
    final JButton go = new JButton("Show JColorChooser");
    go.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Color c;
            c = JColorChooser.showDialog(((Component) e.getSource()).getParent(), "Demo", Color.blue);
            contentPane.setBackground(c);
        }
    });
    contentPane.add(go, BorderLayout.SOUTH);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
}

From source file:CardFrame.java

public void actionPerformed(ActionEvent ae) {
    if (ae.getSource().equals(nextCard)) {
        cardLayout.next(cardPanel);//  w w  w . j a v  a  2s. co  m
    } else if (ae.getSource().equals(prevCard)) {
        cardLayout.previous(cardPanel);
    } else if (ae.getSource().equals(lastCard)) {
        cardLayout.last(cardPanel);
    } else if (ae.getSource().equals(firstCard)) {
        cardLayout.first(cardPanel);
    }
}

From source file:com.os.util.PasswordDecoderEncoder.java

@Override
public void actionPerformed(ActionEvent e) {
    if (e.getSource().equals(encryptBtn)) {
        try {/*from www  .  j  ava 2 s  .  c  o  m*/
            String password = encrypt(passText.getText());
            outputPassword.setText(password);
        } catch (Exception ex) {
            Logger.getLogger(PasswordDecoderEncoder.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (e.getSource().equals(decryptBtn)) {
        try {
            String password = decrypt(passText.getText());
            outputPassword.setText(password);
        } catch (Exception ex) {
            Logger.getLogger(PasswordDecoderEncoder.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

From source file:Popup.java

public void init() {
    Container cp = getContentPane();
    cp.setLayout(new FlowLayout());
    cp.add(t);/*from  ww  w.  j  a v  a 2 s  .c o m*/
    ActionListener al = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            t.setText(((JMenuItem) e.getSource()).getText());
        }
    };
    JMenuItem m = new JMenuItem("Hither");
    m.addActionListener(al);
    popup.add(m);
    m = new JMenuItem("Yon");
    m.addActionListener(al);
    popup.add(m);
    m = new JMenuItem("Afar");
    m.addActionListener(al);
    popup.add(m);
    popup.addSeparator();
    m = new JMenuItem("Stay Here");
    m.addActionListener(al);
    popup.add(m);
    PopupListener pl = new PopupListener();
    addMouseListener(pl);
    t.addMouseListener(pl);
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    JComboBox jcb = (JComboBox) e.getSource();
    System.out.println("down action");
    ComboBoxUI ui = jcb.getUI();/* w  w w.  j a  v a 2 s. c  om*/

    if (ui.isPopupVisible(jcb)) {
        int i = jcb.getSelectedIndex();
        if (i < jcb.getModel().getSize() - 1) {
            jcb.setSelectedIndex(i + 1);
            jcb.repaint();
        }
    } else {
        int nItems = jcb.getItemCount();

        ComboBoxEditor cbe = jcb.getEditor();

        String st; // Search text

        st = ((String) cbe.getItem()).toUpperCase();

        for (int i = 0; i < nItems; i++) {
            String item = ((String) jcb.getItemAt(i)).toUpperCase();

            if (item.startsWith(st)) {
                jcb.setSelectedIndex(i);
                break;
            }
        }

        ui.setPopupVisible(jcb, true);
    }
}