import javax.swing.*; import java.awt.*; class Ex3 { // Screen is divided into many pixels // Pixel is a unit of drawing final static int XPIXELS = 800; final static int YPIXELS = 600; public static void main(String[] args) { // JFrame is a predefined class JFrame jf = new JFrame("Example-3 in Java GUI"); // What to do when window is closed? jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Set the size of the window (in terms of pixels) jf.setSize(new Dimension(XPIXELS, YPIXELS)); // Create components Container con = jf.getContentPane(); // Create a label JLabel label = new JLabel("Example-3"); con.add(label); // Create a button JButton btn = new JButton("Click-me"); con.add(btn); // Show the frame jf.setVisible(true); // Note: main does not exit here } // End main() }