import javax.swing.*; import java.awt.event.*; import java.awt.*; // FrameExample inherits from JFrame // through use of the extends keyword. public class FrameExample extends JFrame { // Variables for objects JButton button; JPanel buttonPanel; public FrameExample() { // Initialize the button and panel. button = new JButton("A Button Framed"); buttonPanel = new JPanel(); // Add the button to the panel buttonPanel.add(button); // Add the panel to the content pane // of the JFrame in the North region of // the default layout, in this case // BorderLayout. getContentPane().add(buttonPanel, BorderLayout.NORTH); // To close the window setDefaultCloseOperation(EXIT_ON_CLOSE); // Sets the width and height of the frame. setSize(350, 200); setVisible(true); } public static void main(String args[]) { FrameExample fe = new FrameExample(); } }