3

First applet

  1. import java.applet.Applet;
  2. import java.awt.Graphics;
  3.  
  4. public class Simple extends Applet {
  5.     public void init() {
  6.         System.out.println("initializing...");
  7.     }
  8.  
  9.     public void start() {
  10.         System.out.println("starting...");
  11.     }
  12.  
  13.     public void stop() {
  14.         System.out.println("stopping...");
  15.     }
  16.  
  17.     public void destroy() {
  18.         System.out.println("destroyed!");
  19.     }
  20.  
  21.     public void paint(Graphics g) {
  22.         System.out.println("painting...");
  23. //      g.drawRect(0, 0, getSize().width - 1, getSize().height - 1);
  24.         g.drawString("Hello from Java", 5, 15); // try at 0, 0!
  25.     }
  26. }
  1. <html>
  2. <head>
  3. <title>Simple</title>
  4. </head>
  5. <body>
  6. <applet code="Simple" width="400" height="25"> </applet>
  7. </body>
  8. </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

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].