Example usage for javax.swing JButton addActionListener

List of usage examples for javax.swing JButton addActionListener

Introduction

In this page you can find the example usage for javax.swing JButton addActionListener.

Prototype

public void addActionListener(ActionListener l) 

Source Link

Document

Adds an ActionListener to the button.

Usage

From source file:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);//w  ww . jav  a2s.c o m

    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JButton btnNewButton = new JButton("Click Me");
    btnNewButton.addActionListener(e -> doClick());
    contentPane.add(btnNewButton, BorderLayout.NORTH);
    jarFilesDB = new MyTreeModel();
    jarFilesDB.load(isAlpha);
    isAlpha = !isAlpha;
    jtree = new JTree(jarFilesDB);
    JScrollPane scrollPane = new JScrollPane(jtree);
    contentPane.add(scrollPane, BorderLayout.CENTER);
}

From source file:Main.java

public Main() {
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    // Make sure the frame is undecorated
    this.setUndecorated(true);
    this.setBackground(new Color(0, 0, 0, 0));
    this.setSize(200, 200);
    // Center it on the screen
    this.setLocationRelativeTo(null);

    this.getContentPane().setLayout(new GridLayout(0, 1));
    this.add(new TranslucentJPanel(Color.RED));
    JButton closeButton = new JButton("Close");
    this.add(closeButton);
    closeButton.addActionListener(e -> System.exit(0));
}

From source file:Test.java

public Test() {
    this.setBounds(100, 100, 200, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1, true));

    this.setLayout(new FlowLayout());

    JButton exitButton = new JButton("Exit");
    panel.add(exitButton);/*from  ww w .  ja va2 s  . c o m*/
    this.add(panel);

    exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}

From source file:Test.java

public Test() {
    this.setBounds(100, 100, 200, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createLoweredSoftBevelBorder());

    this.setLayout(new FlowLayout());

    JButton exitButton = new JButton("Exit");
    panel.add(exitButton);//from w w w.j ava 2 s  .c om
    this.add(panel);

    exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}

From source file:org.jfree.graphics2d.demo.SwingUIToSVGDemo.java

private JComponent createContent() {
    JPanel content = new JPanel(new BorderLayout());
    JTabbedPane tabs = new JTabbedPane();
    tabs.add("Tab 1", new JButton("First Tab"));
    tabs.add("Tab 2", new JButton("Second Tab"));
    JButton button = new JButton("Save to SVG");
    button.addActionListener(this);
    content.add(tabs);/*from w  w w . j  av  a 2  s  .c o  m*/
    content.add(button, BorderLayout.SOUTH);
    return content;
}

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);/*from www  .j  av  a 2 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: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();
        }/*from   w  ww.  ja  v  a2s.c  o m*/
    });

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

    setSize(360, 280);
}

From source file:ColorChooserDemo.java

protected void createUI() {
    setSize(400, 400);/* w ww  .  j a v a 2  s.co m*/
    getContentPane().setLayout(new GridBagLayout());
    JButton colorButton = new JButton("Choose a color...");
    getContentPane().add(colorButton);
    colorButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            Color c = JColorChooser.showDialog(ColorChooserDemo.this, "Choose a color...", getBackground());
            if (c != null)
                getContentPane().setBackground(c);
        }
    });

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent we) {
            System.exit(0);
        }
    });
}

From source file:SimpleAboutDialog.java

public SimpleAboutDialog(JFrame parent) {
    super(parent, "About Dialog", true);

    Box b = Box.createVerticalBox();
    b.add(Box.createGlue());/*from  w ww. ja va 2s.c  o  m*/
    b.add(new JLabel("Java source code, product and article"));
    b.add(new JLabel("By Java source and support"));
    b.add(new JLabel("At www.java2s.com"));
    b.add(Box.createGlue());
    getContentPane().add(b, "Center");

    JPanel p2 = new JPanel();
    JButton ok = new JButton("Ok");
    p2.add(ok);
    getContentPane().add(p2, "South");

    ok.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            setVisible(false);
        }
    });

    setSize(250, 150);
}

From source file:Test.java

public Test() {
    this.setBounds(100, 100, 200, 100);
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel panel = new JPanel();
    panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, Color.lightGray, Color.yellow));
    //panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.RAISED, 
    //  Color.lightGray, Color.yellow));
    //panel.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.LOWERED, 
    //  Color.lightGray, Color.lightGray, Color.white, Color.orange));

    this.setLayout(new FlowLayout());

    JButton exitButton = new JButton("Exit");
    panel.add(exitButton);//from  w  ww. jav  a  2s . c  om
    this.add(panel);

    exitButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent event) {
            System.exit(0);
        }
    });
}