fork download
  1. /*
  2.   Hello World Applet Example
  3.   This java example shows how to create and run Hello World Java Applet.
  4.   */
  5.  
  6.  
  7.  
  8. import java.applet.Applet;
  9. import java.awt.Graphics;
  10.  
  11. /*
  12.   *
  13.   * Applet can either run by browser or appletviewer application.
  14.   * Define <applet> tag within comments as given below to speed up
  15.   * the testing.
  16.   */
  17.  
  18. /*
  19.   <applet code="HelloWorldApplet" width=100 height=100>
  20.   </applet>
  21.   */
  22.  
  23. //every applet must extend from java.applet.Applet class
  24. class HelloWorldApplet extends Applet{
  25.  
  26. /*
  27.   * Override paint method.
  28.   * paint method is called every time the applet needs to redisplay
  29.   * it's output. For example, when applet is first displayed or applet
  30.   * window is minimized and then restored.
  31.   *
  32.   */
  33. public void paint(Graphics g){
  34.  
  35. /*
  36.   * Use
  37.   * void drawString(String str, int x, int y)
  38.   * method to print the string at specified location x and y.
  39.   */
  40. g.drawString("Hello World", 50, 50);
  41. }
  42. public static void main (String[] args)
  43. {
  44. }
  45. }
  46.  
Success #stdin #stdout 0.34s 53336KB
stdin
<html>
<body>
<applet code="HelloWorldApplet.class" width=300 height=100></applet>
</body>
</html> 
stdout
Standard output is empty