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
16
votes
1 answer

Record voice with Java

I want to record voice using a Java application; I guess this will be basically an applet that will run on client side. But I don't have any idea of how to do it... any ideas? Also, I want to play the recorded voice. I have heard of Java Speech…
Varun
  • 5,001
  • 12
  • 54
  • 85
16
votes
2 answers

Why were applets deprecated in JDK 9?

I have recently read in an article posted by Oracle that they are going to mark the Applet class as deprecated in JDK 9. I have little experience with applets; I have only written some to understand the basics. Why are they unpopular, and what is…
Maksim
  • 351
  • 1
  • 2
  • 12
16
votes
5 answers

Run a Java application in a web browser

I am relatively new to Java and have a Java application consisting of a couple of packages and a number of classes. I want to be able to run this application in a web browser. How do I go about doing this?
Shanon
  • 161
  • 1
  • 1
  • 3
16
votes
1 answer

Can you increase line thickness when using Java Graphics for an applet? I don't believe that BasicStroke works

I am having trouble adjusting line thickness. Can I do that in Graphics or do i have to do it in Graphics2D? If so, how do I alter the program to make it run? Thanks! import java.applet.Applet; import java.awt.*; public class myAppletNumberOne…
user2465406
  • 169
  • 1
  • 1
  • 7
15
votes
3 answers

Answer password to keytool in batch files

i need use keytool and jarsigner to sign a lot o files here in many folders. Each time i start sign theses files i need delete the .cert and keystore file to recreate it. Im on development enviroment and using fake passwd to sign it, after…
ZenfStor
  • 151
  • 1
  • 1
  • 4
15
votes
0 answers

How do bots for Runescape (and similar games) work? How do they attach to a JVM, find references to an Applet, and fake AWT events?

Runescape is a large online game with a pure-Java client which runs in the browser as a signed applet. It is pretty unique in that regard, with the other major example I know being Yohoho Puzzle Pirates. Due in part to the forces in the game…
zxwv
  • 171
  • 5
15
votes
3 answers

Java applet with self-signed certificate on OS X Mountain Lion

We have a Java applet that needs to run with full trust. While developing and during pre-release tests we sign it using a self-signed certificate (the production version is signed with a real code signing certificte). But when we try to start the…
Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
15
votes
9 answers

What is the Rolls-Royce way to deploy a Java applet?

I know how to deploy an applet using applet, object, embed tags and JavaScript, but I'm after the best approach (in terms of end user experience). Sun suggests using the applet tag, and a mixed embed / object tag on the same page. What I am…
Pool
  • 11,999
  • 14
  • 68
  • 78
14
votes
4 answers

What does the future look like for Java Applets?

In the past, java applets were unreliable, due to the Microsoft/Sun JVM split. Flash took over, and Java applets became known for browser crashes and performance issues. Now that the JVM is enjoying resurgence as a platform for dynamic languages…
Marcus Cavanaugh
  • 374
  • 4
  • 12
14
votes
5 answers

Jpeg calculating max size

I have to say the I don't know much about how file formats work. My question is say I have a jpeg file that is 200 px by 200 px, how can one calculate what the maximum size that file could be in terms of megabytes/bytes? I think that the reasoning…
Tegra Detra
  • 24,551
  • 17
  • 53
  • 78
14
votes
6 answers

Java applets - is it a wrong choice today?

I have some non-trivial computational code that need to be applied on data already downloaded into the browser DOM and captured from user interactions. I do not wish to expose this code. I am wondering if: Write a webservice and communicate with…
Dinesh
  • 4,437
  • 5
  • 40
  • 77
13
votes
5 answers

What are the correspondent of Servlet and Applet in .NET?

I am trying to understand what's the correspondent of servlets and applets in .NET but I don't have much experience in JAVA. I am thinking applets could be compared to the silverlight stuff, meaning you code independently from the browser, but then…
JohnIdol
  • 48,899
  • 61
  • 158
  • 242
13
votes
3 answers

Why does Java tell me my applet contains both signed and unsigned code?

My signed Java applet has been running fine until Java update 19. Now some but not all of our users on Java Update 19 report a java security message stating that our applet contains both signed and unsigned code. The process for creating our applet…
JohnCooperNZ
  • 167
  • 1
  • 2
  • 9
13
votes
7 answers

Issues with Java 7u65

Last night a new Java 7 update has been released: 7u65. I have a web application where a service applet is loaded, and after the update, my tests on different PCs did not show issues nor wrong behaviors. Later, I started to receive issue reports…
David
  • 1,282
  • 3
  • 18
  • 40
13
votes
11 answers

What can I do to make jar / classes smaller?

I'm developing a Java Applet, and reducing the size of the binary code will make the applet open faster and will improve the user experience. Is there anything I can do to reduce the size of classes and / or jar files? I want to be sure I'm not…
amarillion
  • 24,487
  • 15
  • 68
  • 80