Handling and Consuming Events - Java JavaFX

Java examples for JavaFX:Action

Description

Handling and Consuming Events

Demo Code

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JButton;

public class Main extends JFrame {
  JButton closeButton = new JButton("Close");

  public Main() {
    super("Simplest Event Handling JFrame");
    this.initFrame();
  }//  w w  w. ja va  2s  .  c o  m

  private void initFrame() {
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);

    this.setLayout(new FlowLayout());

    this.getContentPane().add(closeButton);

    closeButton.addActionListener(e -> System.exit(0));
  }

  public static void main(String[] args) {
    Main frame = new Main();
    frame.pack();
    frame.setVisible(true);
  }
}

Related Tutorials