/* File: Counter02.java Same as Counter01, except now we put the code for counting down in a private inner class, with a method called run. */ import javax.swing.*; import java.awt.Font ; public class Counter02 { // a private inner class private class Window1 { int start ; // start counting down from 10 by default Window1() { start = 10 ; } // this constructor lets me specify the starting point Window1(int n) { start = n ; } void run() { 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 ); Thread.sleep(1000) ; for(int i = start ; i >= 0 ; i--) { label.setText( Integer.toString(i) ) ; Thread.sleep(500) ; } label.setText("Kaboom!") ; Thread.sleep(1000) ; } catch ( InterruptedException e ) { System.out.println("Oh look! an exception!") ; } } } // This is the "real" main program. Static methods cannot // invoke non-static methods... public void doThis() { Window1 w1 = new Window1(13) ; w1.run() ; System.out.println("Ok, I'm done.") ; System.exit(0) ; } /// Entry point. Just create an object and call doThis(). public static void main( String[] args ) { Counter02 obj = new Counter02() ; obj.doThis() ; } }