//HelloApplet2c.java //demo of init and paint together. with a field. //init gets input (and can do some calculation), paint draws (and can do some calculation) import java.awt.*; import javax.swing.*; public class HelloApplet2c extends JApplet { //***"field": variable that need to be shared by init and paint methods. //declared outside of init and paint String name; //***init() for setting up GUI, if any, and getting input, if any. //***called automatically, before the paint method. public void init() { name = JOptionPane.showInputDialog( "Hello, what's your name?" ); } //paint draws in the applet. //***called automatically after init() and whenever window is uncovered or resized. public void paint( Graphics g ) { g.drawString("Welcome: " + name, 100, 100 ); } }