/* File: Counter01.java Demonstrates how to open a window with Swing and count down from 10 in big giant letters. */ import javax.swing.*; import java.awt.Font ; public class Counter01 { public static void main( String[] args ) { try { // Create a window with Swing // JFrame frame = new JFrame( "HelloJava" ); JLabel label = new JLabel("Hello, Java!", JLabel.CENTER ); label.setFont( new Font("Serif", Font.BOLD, 36) ) ; frame.getContentPane().add( label ); frame.setSize( 300, 300 ); frame.setVisible( true ); // wait a sec .. Thread.sleep(1000) ; for(int i = 10 ; i >= 0 ; i--) { // change the label in the window label.setText( Integer.toString(i) ) ; Thread.sleep(500) ; } label.setText("Kaboom!") ; Thread.sleep(1000) ; } catch ( InterruptedException e ) { // we might get interrupted while we sleep System.out.println("Oh look! an exception!") ; } // Calling exit is necessary because the Swing window manager // will keep running // System.exit(0) ; } }