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() {
    setSize(300, 150);//from   w w  w  . j a v a 2  s  .  com
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new FlowLayout());
    add(b);
    b.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent ev) {
            b.setFont(new Font("Dialog", Font.PLAIN, ++size));
            b.revalidate();
        }
    });
    setVisible(true);
}

From source file:JProgressBarSetValue.java

public JProgressBarSetValue() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    step.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int value = bar.getValue() + 7;
            if (value > bar.getMaximum()) {
                value = bar.getMaximum();
            }/*from  www.ja va 2 s  .co m*/
            bar.setValue(value);
        }
    });

    getContentPane().add(bar, BorderLayout.NORTH);
    getContentPane().add(step, BorderLayout.EAST);
    pack();
    setVisible(true);
}

From source file:MainClass.java

public MainClass() {
    Container cp = getContentPane();
    JButton crasher = new JButton("Crash");
    cp.add(crasher);//  ww  w  .ja v  a2 s . c  o  m
    crasher.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            throw new RuntimeException("You asked for it");
        }
    });
    Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
        public void uncaughtException(Thread t, Throwable ex) {
            System.out.println("You crashed thread " + t.getName());
            System.out.println("Exception was: " + ex.toString());
        }
    });
    pack();
}

From source file:Main.java

public Main() {
    String[] comboTypes = { "Numbers", "Alphabets", "Symbols" };
    JComboBox<String> comboTypesList = new JComboBox<>(comboTypes);
    comboTypesList.setSelectedIndex(2);/*from w ww .j  av  a 2  s .c o m*/
    comboTypesList.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JComboBox jcmbType = (JComboBox) e.getSource();
            String cmbType = (String) jcmbType.getSelectedItem();
            System.out.println(cmbType);
        }
    });
    setLayout(new BorderLayout());
    add(comboTypesList, BorderLayout.NORTH);
}

From source file:MainClass.java

MainClass() {
    super("MainClass");
    setSize(200, 200);/*  ww w  .java  2  s .  com*/

    fc = new FileDialog(this, "Choose a file", FileDialog.LOAD);
    fc.setDirectory("C:\\");

    Button b;
    add(b = new Button("Browse...")); // Create and add a Button
    b.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            fc.setVisible(true);
            String fn = fc.getFile();
            if (fn == null)
                System.out.println("You cancelled the choice");
            else
                System.out.println("You chose " + fn);
        }
    });
}

From source file:Main.java

public Main() {
    Box b = Box.createHorizontalBox();
    b.add(new JScrollPane(t1));
    copy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            t2.setText(t1.getSelectedText());
        }//from   w w w .  j  av a2s .c  o  m
    });
    b.add(copy);

    t2 = new JTextArea(10, 15);
    t2.setEditable(false);
    b.add(new JScrollPane(t2));

    add(b);
    setSize(425, 200);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:TimerChangeButtonBackground.java

public TimerChangeButtonBackground() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    getContentPane().add(button, "Center");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            timer.stop();/*from   ww w  .jav  a 2 s.c  o m*/
            button.setBackground(Color.red);
        }
    });
    timer = new Timer(1000, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            button.setBackground(flag ? Color.green : Color.yellow);
            flag = !flag;
            repaint();
        }
    });
    timer.start();
    pack();
    setVisible(true);
}

From source file:PrimeCheck.java

public PrimeCheck() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel pnl = new JPanel();
    JButton btnCheck = new JButton("Check");
    ActionListener al;/*from   w w w .j  a v a 2 s .c o m*/
    al = new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            try {
                BigInteger bi = new BigInteger("1234567");
                System.out.println("One moment...");
                new PrimeCheckTask(bi).execute();
            } catch (NumberFormatException nfe) {
                System.out.println("Invalid input");
            }
        }
    };
    btnCheck.addActionListener(al);
    pnl.add(btnCheck);
    getContentPane().add(pnl, BorderLayout.NORTH);
    pack();
    setResizable(false);
    setVisible(true);
}

From source file:Main.java

public Main() {
    this.setSize(400, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton button = new JButton("Change Frame Color");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Component component = (Component) e.getSource();
            JFrame frame = (JFrame) SwingUtilities.getRoot(component);
            frame.setBackground(Color.RED);
        }//from w w w .  j  a v  a 2s  .co  m
    });
    this.getContentPane().add(button);
}

From source file:Main.java

public Main() {
    this.setSize(400, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setLayout(new FlowLayout(FlowLayout.CENTER));
    JButton button = new JButton("Change Frame Color");
    button.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Component component = (Component) e.getSource();
            JFrame frame = (JFrame) SwingUtilities.getRoot(component);
            frame.getContentPane().setBackground(Color.RED);
        }/*from  w  w  w  .  j a v a  2  s. co m*/
    });
    this.getContentPane().add(button);
}