import javax.swing.*; import java.awt.*; class Ex2 { // 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-2 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 a label JLabel label = new JLabel("Example-2"); Container con = jf.getContentPane(); con.add(label); // Show the frame jf.setVisible(true); // Note: main does not exit here } // End main() }