HelloWorld Applet – Java

Below is the java code for the HelloWorld Applet. For running this applet, create an HTML file with referencing this applet and use "appletviewer" for running the applet. 
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;
public class HelloWorld extends JApplet {
//Called when this applet is loaded into the browser.
public void init() {
//Execute a job on the event-dispatching thread; creating this applet's GUI.
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
JLabel lbl = new JLabel("Hello World");
add(lbl);
}
});
} catch (Exception e) {
System.err.println("createGUI didn't complete successfully");
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *