//HelloApplet2.java import java.awt.*; //contains the Graphics, Font and Color classes import javax.swing.*; //contains the J... classes public class HelloApplet2 extends JApplet { //***fields that need to be shared by init and paint methods: 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 ) { int width=getWidth(); //current width of applet area int height=getHeight(); //current height of applet area g.setColor( Color.GREEN ); g.fillOval( 0, 0, width/2, height/2 ); g.setColor( Color.MAGENTA ); g.fillOval( width/2, 0, width/2, height/2 ); g.setColor( Color.CYAN ); g.fillOval( 0, height/2, width/2, height/2 ); g.setColor( Color.YELLOW ); g.fillOval( width/2, height/2, width/2, height/2 ); g.setColor( Color.RED ); g.drawLine( 0, 0, width, height ); g.drawLine( width, 0, 0, height ); g.drawRect( 10, 10, width-20, height-20 ); g.drawOval( 0, 0, width-1, height-1 ); g.setColor( Color.BLUE ); g.setFont( new Font( "Serif", Font.BOLD, 16 ) ); g.drawString( name, width/2-20, height/2 ); } }