import java.applet.*; import java.awt.*; // The Lesson3 class illustrates the difference between init and paint methods. // It also shows the difference between "instance variables" and "local variables" public class Lesson3 extends Applet { // Instance variables are declared outside of any method. They can be used in any // of the class methods int paintCount = 0; TextField paintText = new TextField("Times paint used: " + paintCount); int initCount = 0; // The init method for the Applet class is executed once when the applet is created public void init() { setBackground(Color.yellow); initCount++; // initText is a local variable which can only be used within this method. TextField initText = new TextField("Times init used: " + initCount); add(initText); add(paintText); } // The paint method is executed each time the applet needs to be redrawn on the screen. public void paint(Graphics g) { paintCount++; paintText.setText("Times paint used: " + paintCount); } }