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

Add Java Applet to Sencha Touch 2

I want to add a Java Applet to Sencha Touch 2. Is there an opportunity? For example in Ext.app.Application with a config attribute or in Ext.navigation.View or somewhere else? At the moment I have it in the workflow.html under the body tag: …
Niklas
  • 23,674
  • 33
  • 131
  • 170
2
votes
1 answer

Access a local client database using Java Applet

I am trying to build a Java Applet that connects to database on the client side and executes some query. The applet needs to use JDBC... so I implemented a very simple JDBC connection to a database file located on my C:/ drive. After signing the app…
BBacon
  • 2,456
  • 5
  • 32
  • 52
2
votes
2 answers

Applets failing to load

While testing our setup for user acceptance testing, we got some reports that java applets in our web application would occasionally fail to load. The envt where it was reported was WinXP/IE6, and there were no errors found in the java…
Roy Tang
  • 5,643
  • 9
  • 44
  • 74
2
votes
3 answers

signed java applet restrictions?

I wrote a java applet and self signed it. When I run it in eclipse or as a executable jar it works fine. But when I upload it, it doesn't do anything. It loads, and the self signed cert warning does come up and I click yes but nothing. I was under…
Ilia Choly
  • 18,070
  • 14
  • 92
  • 160
2
votes
1 answer

Export Java applet to .jar

My problem is : When I tried to export my applet, I couldn't find the 'main class'. When I double click on the exported jar file, nothing appears, but when I compile my code it works fine! The code here import java.applet.*; import…
2
votes
3 answers

This demo works 4 out of 5 times, why is it giving me an error sometimes?

I am practicing rendering and drawing graphics, I can't seem to find out why eclipse gives me an error around 1/5 of the time. Exception in thread "Thread-3" java.lang.NullPointerException at game.StartingPoint.run(StartingPoint.java:74) at…
Steven
  • 833
  • 3
  • 11
  • 18
2
votes
1 answer

Conversion of a Java Web Start app to an Applet

I'm trying to figure out how difficult it would be to convert a Java Web Start app to an applet. Theoretically, if the application didn't do anything such as write to the file system...basically if all of it's actions should be safe within the…
milesmeow
  • 3,688
  • 5
  • 35
  • 58
2
votes
2 answers

Professionally sign an applet

I've made a Java applet and I self signed it before, but due to security changes in recent Java updates, self signing no longer gives the applet the necessary permissions. I need the applet to be able to read the local file system to use images and…
rasen58
  • 4,672
  • 8
  • 39
  • 74
2
votes
4 answers

Loading Image in Java Applet

When I try to run an applet in applet viewer it is not able to find resources (Image). I try to load resource like this: String cb= this.getCodeBase().toString(); String imgPath =…
sachin
  • 1,376
  • 2
  • 15
  • 37
2
votes
1 answer

Why isnt my repaint working?

I have the code: import java.applet.Applet; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class obj_Dingus extends Applet implements KeyListener{ private Rectangle rect; //The rectangle that we…
user2577576
2
votes
1 answer

convert Image to Buffered Image in an applet program

I tried many ways for converting an image of Image class to BufferedImage in an applet program. And i got one method which is works fine when running from the netbeans.but same code is not working while running through browser. The code i tried…
Udanesh N
  • 161
  • 2
  • 2
  • 15
2
votes
1 answer

How can functions in a Griffon applet be called from JavaScript?

We have a project that is web-based, but needs to have significant access to the user's filesystem. HTML doesn't (yet) allow us enough access, and since we are primarily a Grails shop, having the file access code as an applet makes far more sense…
cdeszaq
  • 30,869
  • 25
  • 117
  • 173
2
votes
2 answers

Java applet can't find resources in jar if run locally

Problem: Java applet can't load resources located inside its jar when run locally on windows platforms. The same applet can load the resources if it is launched from a web server instead of launched locally or if it's launched locally on a linux…
Jim
  • 31
  • 1
  • 4
2
votes
3 answers

When I run a JApplet got different colors for the same code

I've written a JApplet and I set, in the initialization, colors for the Nimbus L&F. When I run the applet, both via Netbeans or via Google Chrome, 9/10 times it happens that button background is set to dark, but sometimes Nimbus is not able to set…
Paolo M
  • 12,403
  • 6
  • 52
  • 73
2
votes
3 answers

Paste image from clipboard

I'm trying to paste image from clipboard in my website (like copy and paste). Appreciate if anyone could advice on this. Can I achieve this using HTML 5 or applet or any way. Any advice or any link for reference is highly appreciated.
chinna_82
  • 6,353
  • 17
  • 79
  • 134