In this step, we both draw on the applet's panel and add UI components. Thus, we combine code from Steps 1 & 2.Example Applet
import java.applet.Applet; import java.awt.*; public class step3 extends Applet{ // adds UI components and draws TextArea ta = new TextArea ("My Text Area", 5, 40); Button button = new Button ("Button"); public void init ( ){ setBackground (Color.white); setForeground (Color.red); add (ta); add (button); } // end init public void paint (Graphics g ) { g.fillRect (50, 50, 100, 100); g.setColor (Color.blue); g.setFont (new Font ("Helvetica", Font.BOLD, 24) ); g.drawString ("Hello, World!", 200, 200); g.setColor (Color.yellow); g.drawOval (300, 50, 100, 100); g.setColor (Color.green); g.fillArc (50, 300, 200, 200, 180, -90); g.setColor (Color.cyan); g.fill3DRect (300, 300, 100, 100, true ); } // end paint } // end step3Run the applet
Discussion
This works ok, but notice that things are overlapped. Not ideal!