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
21
votes
8 answers

Run local java applet in browser (chrome/firefox) "Your security settings have blocked a local application from running"

I'm trying to run a Java Applet (html file), but the browser keeps saying: "Your security settings have blocked a local application from running" I have tried using Chrome and Firefox but i get the same error. I have upgraded to the latest…
ymerdrengene
  • 1,421
  • 2
  • 17
  • 20
21
votes
13 answers

Do beautiful, user-friendly Java applets exist?

When I use Java applets, they tend to be slow, don't integrate very well with the browser environment and often require a few click throughs ("No, I don't want to give this unsigned application free reign of my hard disk"). So, I'm curious. Are…
David Wolever
  • 148,955
  • 89
  • 346
  • 502
20
votes
5 answers

Convert a Graphics2D to an Image or BufferedImage

I have a little problem here. I have an applet, where user can "draw" inside it. To do that, I use the java.awt.Graphics2D. But, how can I do to save the user draw image as a JPEG image, or at least, convert it to a BufferedImage or something? I…
caarlos0
  • 20,020
  • 27
  • 85
  • 160
20
votes
10 answers

Why do applets have such a low adoption level?

Why do applets have such a low adoption level, compared for example against Flash? Is it because they are technological disadvantages, or is it just an issue of popularity?
flybywire
  • 261,858
  • 191
  • 397
  • 503
20
votes
2 answers

Embedding a bokeh app in flask

I am trying desperately to embed a working bokeh applet into flask, and can't find a proper way to do this. I looked through all the examples, but I can't find one which includes the ability to update the data (best example: the sliders_applet). If…
lakerz
  • 1,051
  • 3
  • 12
  • 20
19
votes
2 answers

BouncyCastle Cryptography provider library used with applet on Java 7u40

The case: I am maintaining a Java applet which uses the BouncyCastle libraries bcpkix-jdk15on-149.jar, and bcprov-jdk15on-149.jar. Problem is when the applet is run on a JRE version 7_u40 enabled browser. The behavior has changed from version 7_u25…
Steph V.
  • 511
  • 3
  • 9
19
votes
2 answers

method init()v not found

I'm rewriting an applet I have, but when it loads it's giving me a runtime exception. The exception is Exception in thread "main" java.lang.NoSuchMethodError: ClientSettings: method < init>()V not found at…
Dan
  • 649
  • 4
  • 11
  • 19
18
votes
10 answers

JavaFX is now out: Are Applets and Java Desktop officially dead/dying?

JavaFX is now out, and there are promises that Swing will improve along with JavaFX. Gone will be the days of ugly default UI, and at long last we can create engaging applications that are comparable to Flash, Air, and Silverlight in terms of…
user46915
18
votes
2 answers

Applet served by Java Web Start, resources requested to WEB Server before look in the JAR files

I am new here and I apologize for my bad English. I have a little problem with an Applet class served by Java Web Start technology. I have some platform dependent JAR files which Web Start download correctly, but when I get the content by…
Roberto Santini
  • 216
  • 2
  • 7
18
votes
3 answers

Applet v/s Servlet

Whats the difference between Applet and Servlet in JAVA
Sachin
  • 20,805
  • 32
  • 86
  • 99
18
votes
2 answers

How does URLConnection.setUseCaches() work in practice?

I have an Applet which is loading images over a http connection using URLConnection. I am setting setUseCaches(true) for all connections, but still not seeing any caching behavior. My image's HTTP headers have reasonable cache settings. If you look…
Joel Carranza
  • 967
  • 2
  • 12
  • 19
17
votes
8 answers

Why does my applet get a java.security.AccessControlException: access denied (java.net.SocketPermission ...), and how can I avoid it?

We are clueless about why my client is encountering a Java Security exception in Safari. Could anyone help? The exception occurs reliably in Safari on Windows. This involves a Java applet. The exception also occurs with Firefox and IE8 on Windows…
Crashalot
  • 33,605
  • 61
  • 269
  • 439
17
votes
4 answers

How can I get early access to Oracle Java updates, so I can test my RIA and avoid fire-drills when these updates are made public?

Having had our application stop working when customers installed the 7u45 update, we're wondering what more we can do in the future to be ready for these updates up-front and avoid release-day support nightmares. (Per the Java version numbering…
Matt McHenry
  • 20,009
  • 8
  • 65
  • 64
16
votes
1 answer

What does the jp2launcher do in the applet program?

Run a page which contains Java applet, notice that a process called jp2launcher is running. What does this process do?
user705414
  • 20,472
  • 39
  • 112
  • 155
16
votes
4 answers

getClassLoader().getResource() returns null

I have this test app: import java.applet.*; import java.awt.*; import java.net.URL; public class Test extends Applet { public void init() { URL some=Test.class.getClass().getClassLoader().getResource("/assets/pacman.png"); …
Ali
  • 261,656
  • 265
  • 575
  • 769