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. public 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. }
  43.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:24: error: class HelloWorldApplet is public, should be declared in a file named HelloWorldApplet.java
    public class HelloWorldApplet extends Applet{
           ^
Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
stdout
Standard output is empty