// HelloPanelApplet.java (c) 2006 Kari Laitinen // http://www.naturalprogramming.com/ // 2006-01-21 File created. // 2006-10-02 Latest modification. // This program is another version of HelloApplet.java. // In this version a separate HelloPanel class is declared, and // a HelloPanel object contains the text that is printed to the // screen. // See the notes at the end of this file. import java.awt.* ; import javax.swing.* ; class HelloPanel extends JPanel { public void paintComponent( Graphics graphics ) { // The superclass version of paintComponent() clears the // component area and does other necessary things. super.paintComponent( graphics ) ; graphics.drawString( "Hello. I am a Java applet.", 80, 100 ) ; graphics.drawString( "The coordinates of this line are (80,150).", 80, 150 ) ; } } public class HelloPanelApplet extends JApplet { public void init() { Container content_pane_of_this_applet = getContentPane() ; HelloPanel main_panel_of_this_applet = new HelloPanel() ; content_pane_of_this_applet.add( main_panel_of_this_applet ) ; } } /* NOTES: // The above init() method can alternatively be written in the // following way: public void init() { getContentPane().add( new HelloPanel() ) ; } */