1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
/* Hello World Applet Example This java example shows how to create and run Hello World Java Applet. */ import java.applet.Applet; import java.awt.Graphics; /* * * Applet can either run by browser or appletviewer application. * Define <applet> tag within comments as given below to speed up * the testing. */ /* <applet code="HelloWorldApplet" width=100 height=100> </applet> */ //every applet must extend from java.applet.Applet class public class HelloWorldApplet extends Applet{ /* * Override paint method. * paint method is called every time the applet needs to redisplay * it's output. For example, when applet is first displayed or applet * window is minimized and then restored. * */ public void paint(Graphics g){ /* * Use * void drawString(String str, int x, int y) * method to print the string at specified location x and y. */ g.drawString("Hello World", 50, 50); } } |
Example Output
Hello all
I am super new to Java and already have problems with codes in general, well i am still learning!
I run the above code and seems i am doing something wrong because i get an error:
=============
———- Run ———-Error: Main method not found in class HelloWorldApplet, please define the main method as: public static void main(String[] args)
Output completed (0 sec consumed) – Normal Termination
=============
Can you explain why i got this error and what can i do to fix it?
Compile correct but when i run the error shows.
Have jdk1.7.0_07 installed correct, able to run other codes but not this one, try in NetBeans, Eclipse, EditPlus but nothing
Please have a look and let me know where am i wrong
Best regards
Gabi
hi i had try the coding above where i used to get the error
java.lang.ClassNotFoundException: Hello World