3
First applet
- import java.applet.Applet;
- import java.awt.Graphics;
- public class Simple extends Applet {
- public void init() {
- System.out.println("initializing...");
- }
- public void start() {
- System.out.println("starting...");
- }
- public void stop() {
- System.out.println("stopping...");
- }
- public void destroy() {
- System.out.println("destroyed!");
- }
- public void paint(Graphics g) {
- System.out.println("painting...");
- // g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
- g.drawString("Hello from Java", 5, 15); // try at 0, 0!
- }
- }
- <html>
- <head>
- <title>Simple</title>
- </head>
- <body>
- <applet code="Simple" width="400" height="25"> </applet>
- </body>
- </html>
$ javac Simple.java
$ firefox Simple.html
To view the trace messages, use appletviewer
:
$ appletviewer Simple.html
initializing...
starting...
painting...
stopping...
starting...
painting...
stopping...
destroyed!
Comments