The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > javax.swing  [141 examples]

e732. The Quintessential Swing User Interface

This example creates and shows a frame with a button. To enable the button to respond to button clicks, see e743 Creating a JButton Component.
    import java.awt.*;
    import javax.swing.*;
    
    public class BasicUI {
        public static void main(String[] args) {
            JButton button = new JButton("Label");
            JFrame frame = new JFrame();
    
            // Add button to the frame
            frame.getContentPane().add(button, BorderLayout.CENTER);
    
            // Set initial size
            int frameWidth = 300;
            int frameHeight = 300;
            frame.setSize(frameWidth, frameHeight);
    
            // Show the frame
            frame.setVisible(true);
        }
    }

 Related Examples

See also: Actions    JButton    JCheckBox    JComboBox    JDesktop and JInternalFrame    JFrame, JWindow, JDialog    JLabel    JList    JProgressBar    JRadioButton    JScrollPane    JSlider    JSpinner    JSplitPane    JTabbedPane    JToolBar    Keystrokes and Input Maps    Layout    Look and Feel    Menus    Progress Monitor    The Screen    Tool Tips    UI Default Values   


© 2002 Addison-Wesley.