Hello World Applet Example

  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. }

Example Output

Visit Java Example Forums to request Java examples or ask Java questions!

Create your own blog, submit tutorials articles and examples, join community of hundreds of members at Java Community Network




Suggested Reading

Oracle Magazine
Contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more.
Cost: FREE

View/Subscribe
NASA Tech Briefs
Features exclusive reports of innovations developed by NASA and its industry partners/contractors that can be applied to develop new/improved products and solve engineering or manufacturing problems.
Cost: FREE

View/Subscribe
FierceBiotech IT
Is a free, easy to read weekly email service that brings must read biotech IT news to senior biotech, pharma, and IT executives.
Cost: FREE

View/Subscribe
Simply SQL
Simply SQL is a practical step-by-step guide to writing SQL.
Cost: FREE

View/Subscribe
Simply JavaScript
Packed with full-color examples, Simply JavaScript is all you need to start programming in JavaScript the right way.
Cost: FREE

View/Subscribe
PCMag.com's What's New Now
Lance Ulanoff, Editor in Chief of the PC Magazine Network, brings you this twice-weekly roundup of the latest top tech stories, the best new product reviews, plus special offers from Ziff Davis and its partners.
Cost: FREE

View/Subscribe

Could not find what you are looking for? Search Java Examples