An application is a standalone program consisting of at least one class with a main method. Applets differ significantly from applications. First, applets do not have a main method that is automatically called to begin the program. Instead, several methods are called at different points in the execution of an applet. The difference between Java applets and applications lies in how they are run. Applications are usually run by loading the application’s main class file with a Java interpreter, such as the java tool in the JDK(TM) 6. An applet is a special kind of Java program that a browser enabled with Java technology can download from the internet and run. An applet is typically embedded inside a web-page and runs in the context of the browser.

Applet + Application Example:

import javax.swing.*;
class helloApp {
	public static void main(String[] args){
		// create Frame and put my mainPanel in it
		JFrame f = new JFrame(“title”);
		mainPanel p = new mainPanel();
class helloApplet extends JApplet {
	public void init(){
		// put my mainPanel in the Applet
		mainPanel p = new mainPanel();
// my main GUI is in here:
class mainPanel extends JPanel {
		setLayout(new FlowLayout());
		JButton b = new JButton(“press me”);
public class DisplayImageWithURL extends JApplet {
  public DisplayImageWithURL() { url = this.getClass().getResource("us.gif");
    add(new JLabel(new ImageIcon(url)));
  /** Main method */
  public static void main(String[] args) {
    // Create a frame
    JFrame frame = new JFrame("DisplayImageWithURL");
    // Create an instance of the applet
    DisplayImageWithURL applet = new DisplayImageWithURL();
    // Add the applet instance to the frame
    frame.getContentPane().add(applet, java.awt.BorderLayout.CENTER);
    // Display the frame
    frame.setSize(200, 150);
Tagged with: JAVAProgramming

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Related News Feeds

Set your Twitter account name in your settings to use the TwitterBar Section.