Example usage for java.awt.event ActionListener ActionListener

List of usage examples for java.awt.event ActionListener ActionListener

Introduction

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

Prototype

ActionListener

Source Link

Usage

From source file:Main.java

public Main() {
    addTabButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            add();// w  w w .  j  a v a 2  s.co  m
        }
    });
    closeButtonSize = new Dimension(closeXIcon.getIconWidth() + 2, closeXIcon.getIconHeight() + 2);

    frame.add(tabbedPane, BorderLayout.CENTER);
    frame.add(addTabButton, BorderLayout.SOUTH);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.pack();
    frame.setMinimumSize(new Dimension(300, 300));
    frame.setVisible(true);

}

From source file:Main.java

public Main() {
    try {//www .  j a  v a 2 s  . c om
        robot = new Robot();
    } catch (Exception e1) {
        e1.printStackTrace();
    }

    timer = new Timer(3000, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Rectangle size = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
            Image image = robot.createScreenCapture(size);
            label.setIcon(new ImageIcon(image));
            frame.setVisible(true);
        }
    });
    timer.setRepeats(false);

    button.addActionListener(e -> {
        frame.setVisible(false);
        timer.start();
    });

    frame.add(button, BorderLayout.NORTH);
    frame.add(label, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(1024, 768);
    frame.setVisible(true);
}

From source file:SysTray.java

public void installSystemTray() throws Exception {
    PopupMenu menu = new PopupMenu();
    MenuItem exit = new MenuItem("Exit");
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);/*from   ww w. j  a  v  a  2s  .com*/
        }
    });
    menu.add(exit);

    TrayIcon icon = new TrayIcon(getImage(), "Java application as a tray icon", menu);
    icon.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "Hi!");
        }
    });
    SystemTray.getSystemTray().add(icon);
    Thread.sleep(3000);
    icon.displayMessage("Attention", "Please click here", TrayIcon.MessageType.WARNING);
}

From source file:Main.java

public Main() {
    final AbstractTableModel model = new MyModel();
    final JTable table = new JTable(model);
    getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
    model.setValueAt(new Integer(1), 0, 0);

    JButton button = new JButton("Increment selected cell");
    getContentPane().add(button, BorderLayout.SOUTH);
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int row = table.getSelectedRow();
            int column = table.convertColumnIndexToModel(table.getSelectedColumn());
            int currentValue = ((Integer) model.getValueAt(row, column)).intValue();
            model.setValueAt(new Integer(currentValue + 1), row, column);
        }/*w  w  w .j  a  v a  2 s.co  m*/
    });

    pack();
}

From source file:JBenchFrame.java

public JBenchFrame() {
    this.getContentPane().setLayout(borderLayout1);
    this.setSize(new Dimension(400, 300));
    fillButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ListData ld = new ListData();
            long tmStart = System.currentTimeMillis();
            list1.setModel(ld);/* w w  w .  j a  v a 2s .  c o  m*/
            list1.repaint();
            long tmEnd = System.currentTimeMillis();
            System.out.println(tmEnd - tmStart);

        }
    });
    fillButton.setText("Fill");
    this.getContentPane().add(new JScrollPane(list1), BorderLayout.CENTER);
    this.getContentPane().add(fillButton, BorderLayout.SOUTH);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setVisible(true);
}

From source file:ColorComboBoxEditor.java

public ColorComboBoxEditor(Color initialColor) {
    editor = new JButton("");
    editor.setBackground(initialColor);//from   w  w w. j  ava  2s . c o m
    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Color currentBackground = editor.getBackground();
            Color color = JColorChooser.showDialog(editor, "Color Chooser", currentBackground);
            if ((color != null) && (currentBackground != color)) {
                editor.setBackground(color);
                fireActionEvent(color);
            }
        }
    };
    editor.addActionListener(actionListener);
}

From source file:JWindowNoTitleBar.java

public JWindowNoTitleBar() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    window.getContentPane().add(new JLabel("About"), BorderLayout.NORTH);
    window.getContentPane().add(new JLabel("Label", SwingConstants.CENTER), BorderLayout.CENTER);
    JButton b = new JButton("Close");
    window.getContentPane().add(b, BorderLayout.SOUTH);
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            window.setVisible(false);/*  w  ww. ja  v a2 s.c o m*/
        }
    });
    window.pack();
    window.setBounds(50, 50, 200, 200);

    b = new JButton("About...");
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            window.setVisible(true);
        }
    });
    getContentPane().add(b);
    pack();
}

From source file:Main.java

public ClockPane() {
    setLayout(new BorderLayout());
    tickTock();// ww w . j a v  a2  s .c o m
    add(clock);
    Timer timer = new Timer(500, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            tickTock();
        }
    });
    timer.setRepeats(true);
    timer.setCoalesce(true);
    timer.setInitialDelay(0);
    timer.start();
}

From source file:ImageLoader.java

public ImageLoader() {
    super("Image Loader");

    this.log = new JTextArea(4, 4);
    this.viewer = new JPanel();

    JButton start = new JButton("Start");
    start.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String[] files = new String[] { "Bodie_small.png", "Carmela_small.png", "Death Valley_small.png",
                    "Lake_small.png" };
            new ImageLoadingWorker(log, viewer, files).execute();
        }/* www  .j  a va2  s.com*/
    });

    add(new JScrollPane(log), BorderLayout.NORTH);
    add(new JScrollPane(viewer), BorderLayout.CENTER);
    add(start, BorderLayout.SOUTH);

    setSize(360, 280);
}

From source file:Main.java

public Main() {
    JFrame jfrm = new JFrame("Cut, Copy, and Paste");
    jfrm.setLayout(new FlowLayout());
    jfrm.setSize(230, 150);/*from  w w w.  j ava  2  s .com*/
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    jbtnCut.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            jtf.cut();
            update();
        }
    });

    jbtnPaste.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            jtf.paste();
            update();
        }
    });

    jbtnCopy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent le) {
            jtf.copy();
            update();
        }
    });

    jtf.addCaretListener(new CaretListener() {
        public void caretUpdate(CaretEvent ce) {
            update();
        }
    });

    jfrm.add(jtf);
    jfrm.add(jbtnCut);
    jfrm.add(jbtnPaste);
    jfrm.add(jbtnCopy);
    jfrm.setVisible(true);
}