Questions tagged [applet]

Applet means 'small application'. This has become commonly used to describe Java applets embedded in web pages. And in that context, applets can be regarded as outdated technology.

Applet

Applet means 'small application'. This term has become commonly used to describe Java applets embedded in web pages - to the extent that the HTML based applet element is for embedding Java applets.

That being said:

  • An applet does not need to be embedded in a web page
  • An applet does not need to be written in Java
  • Many embedded Java applets are not 'small'

Gradually this term is being dragged back to its original meaning. In the more general sense, it might be applied to (for example) operating system settings or configuration applets. Such OS specific applets would typically not be written using Java.

Having covered the general meaning, and recognizing that the common usage of 'applet' is still 'Java applet', the rest of this entry will focus on Java applets.


Java Applet

Looking from the specific Java applet context, it is important to understand that no modern browser is supporting Java plugins any more; and therefore Java applets are not supported any more, too! This means: Java applets can be seen as a product that has reached "end of life"; it should not be used any more when developing new products; applets are only relevant in the sense of "how to migrate away" from them.

Java applets are applications written using the Java programming language that are embedded in web pages. Applets typically provide dynamic functionality that is not supported by plain HTML or a combination of HTML and JavaScript.

Perhaps ironically, the functionality of JavaScript is sometimes invoked from Java applets to achieve things that applets cannot do on their own. Further, the deployJava.js JavaScript provided by Oracle is designed to launch applets after checking a suitable minimum Java version is installed. While Java can do things that JavaScript cannot - most modern applets would not get very far if JavaScript was disabled in the user's browser!

Many 'beginner books' on Java seem to rush into applet development in early stages in the book. This is a huge mistake. Any text that does so should be considered suspect.

While applets might seem easy to develop, they are actually quite tricky. To deploy an applet reliably to 'all comers' (or at least the vast majority) on the WWW is an order of magnitude more difficult again. For more details See Why CS teachers should stop teaching Java applets, a blog entry by the top ranked provider of answers for the applet tag.

The Java applet API provides methods considered handy to web based applications. These include methods to gain images and audio clips, discover and communicate with other applets, ascertain the code base and document base (where am I?) to allow relative references to resources (images, clips, text files, etc.) that the applet might use.

Applets could be embedded in web pages since Java 1.1. With Java 1.2 came Java Web Start, which could launch both applications and applets as free floating entities (not embedded in a web page). With the release of Java 1.6.0_10, applets could remain embedded in web pages, but they also access the functionality of JWS and services of the JNLP API.

Applet 'Hello World' Example

This example requires the Java Development Kit installed. Visit Java SE Downloads for the latest JDK.

/* <!-- Defines the applet element used by the appletviewer. -->
<applet code='HelloWorld' width='200' height='100'></applet> */
import javax.swing.*;

/** An 'Hello World' Swing based applet.

To compile and launch:
prompt> javac HelloWorld.java
prompt> appletviewer HelloWorld.java  */
public class HelloWorld extends JApplet {

    public void init() {
        // Swing operations need to be performed on the EDT.
        // The Runnable/invokeAndWait(..) ensures that happens.
        Runnable r = new Runnable() {
            public void run() {
                // the crux of this simple applet
                getContentPane().add( new JLabel("Hello World!") );
            }
        };
        SwingUtilities.invokeAndWait(r);
    }
}

See also

7462 questions
2
votes
1 answer

How do I use html5 local storage in a java applet?

In HTML5, one uses local storage to store things on the client's computer, making them persistent beyond a page refresh. Usually, one uses JavaScript to program things on the client-side, but Java applets can be on the client-side too! Thus, I must…
Tespa42
  • 567
  • 4
  • 12
2
votes
1 answer

How to embed a java applet located under a different system path

I am trying to use an applet that is located in a jar that is located somewhere else in my system (not in the same project location as the web stuff). I know of a property called codebase which is pointing to where the web for look for the jar that…
Scott
  • 174
  • 5
  • 19
2
votes
0 answers

Java Applet run under host of file

I am new here, so cut me some slack if I do something wrong. I am running a Java Applet in the background of my site as a hidden 'JavaScript iFrame'. It runs on every page of my site. Every time I go to a different page it asks me to run it, only…
HeroCC
  • 988
  • 15
  • 33
2
votes
1 answer

Java- Adding Radio Buttons using AWT?

This program has 2 radio buttons. 1: for a circle and 2: for outputting a square. This program is basically designed to either output a cirlce or square based off a radio button group. My issue is that I don't know how to implement an action…
Fryon Alexandra
  • 139
  • 7
  • 19
2
votes
1 answer

Grabbing graphics data from Google Street View object

As the title suggests, I have a Google Street View object in my web page. My program 'drives' along certain routes, essentially, I control Google Street View's javascript API through an embedded Java applet (in the same page). I need to be able to…
Warlax
  • 2,459
  • 5
  • 30
  • 41
2
votes
0 answers

launch java applet with jnlp but with unspecified width and height

I have an applet and would like to launch it via jnlp. Currently it launches, but the problem is in the width and height. If I launch the applet manually (java -jar applet.jar), I don't specify a width and height. The applet decides itself what size…
gogators
  • 783
  • 2
  • 6
  • 17
2
votes
1 answer

Applet fails to reload after page refresh or after navigating to same page, getting classNotFoundException second time (after page refresh)

Applet loads and run succesfully for first time but when we goes off the page and again try to navigate to same page getting class not found Exception. Using jnlp exception: JNLP file error: applet-test-applet.jnlp. Please make sure the file…
2
votes
2 answers

Custom file picker without using

I am working on a java-based (webwork framework) web-app where the file to be uploaded needs to be compressed first. Since there's no way to set the value of "input type='file'" element via javascript, I decided to take the route of an embedded…
user2110793
  • 21
  • 1
  • 3
2
votes
1 answer

During Java applet startup, what does "Running JVM args match the secure subset" mean?

I am trying to run remote debugging on a Java applet, but cannot get the applet to connect to the debugger (Eclipse) nor will it suspend. During startup, I get the following: ... Match: digesting vmargs: -Djava.compiler=NONE -Xdebug…
Phoebe
  • 2,774
  • 3
  • 22
  • 27
2
votes
1 answer

Reduced size of polygons in the paint method implementation

I've made a program in JAVA applets. The program draw a polygon A with 4 randomly generated points then it draws another polygon with 4 randomly generated point B. After this it compares each points of each polygon to see if they're the same. If…
2
votes
3 answers

Deployment Toolkit for Java applets: how to avoid the redirect when no JVM is installed

I have created an applet; it is deployed using the Deployment Toolkit as below (the URLs are fake):