Talk:Java Swings/Event Handling

import javax.swing.*; import java.awt.BorderLayout; // The BorderLayout class // lives in java.awt. We                 // use its constants to tell // the JFrame where we want the // components to go. // expanded version of the hello application, // but with a button below. public class HelloWithButton { public static void main(String[] args) { // construct the JLabel, // an overloaded version of the constructor // allows us to specify the alignment off the // bat JLabel label = new JLabel ("Hello, World!", SwingConstants.CENTER); // create the button. The text in the // constructor will be visible on the // button. JButton button = new JButton("Button"); // create the frame JFrame frame = new JFrame("Hello"); // add the label and the button to the // frame, using layout constants. frame.add(label, BorderLayout.CENTER); frame.add(button, BorderLayout.SOUTH); frame.setSize(300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setLocationRelativeTo(null); frame.toFront; } }