search
HomeJavajavaTutorialTeach you how to configure the Applet environment

Java applets, also known as Java Applets, can run in a web browser. Java Applets must be embedded in HTML pages in the form of scripts to run in web browsers.

I always thought that if I installed the JDK locally and specified the JAVA_HOME and PATH environment variables, all Java programs would be able to run. Later, a colleague asked me to When I helped him solve the problem that a Gantt chart of a project management software could not be run in the web browser, I discovered that the running environment configurations of Java Applet and general Java applications were different. To run Java applications on Windows, as long as you have the JDK binary directory and specify JAVA_HOME and PATH, you can use it directly. You do not need to install it through the JDK installation program. Therefore, you can back up the installed JDK directory as a compressed package. When you reinstall the system or install the Java environment on other machines in the future, you can directly copy the JDK binary compressed package and use it directly after decompression.

But in Windows, when configuring the running environment of Java Applet, it is not enough to only specify the JDK directory. You must meet the following requirements:

1. Use the JRE installation package. Installation

2. The JRE version provides Java Plugin

3 The bit length of .JRE and the web browser must be consistent, such as both 32-bit or 64-bit software versionsThis is because the JRE will install Java-related Information is written to the registry and a Java Plugin is installed for the web browser. When the Java Plugin of the web browser runs an Applet, it will first read the Java information from the Windows registry and then execute the Applet program.

It should be noted here that different versions of JRE support different web browsers and versions. My local web browsers include IE8, Firefox16, and Chrome19. After installing JRE6u11, only IE8 can run Applets; under Firefox16, you can see that the Java Plugin is installed through about:plugins, but cannot run Applets; while under Chrome19, it shows that there is no Java Plugin installed. Java Plugin. After installing JRE7u9, all browsers can run Applets. So, the simplest thing is to just install the latest JRE version. Usually if the browser does not have Java Plugin installed, the user will be prompted to install the plug-in when running a web page with an Applet. Generally, it can be installed directly.

Java Tester is a website that is used to check the locally installed JRE version and software manufacturer. It can also check whether the web browser can run the Applet program:

Java Tester - What Version of Java Are You Using?

For ordinary users, it is very simple to install the Applet running environment, but sometimes it is the browser of Java developers that cannot run Applet, which is a bit shabby. Java developers often install multiple Java versions on their computers. Sometimes they directly move or

delete

the JDK directory without uninstalling it through the Windows control panel, resulting in residual Java installation information in the Windows registry. , there is no problem running the Java application, but the Java Plugin cannot find the JRE in the web browser to execute the Applet. After installing JRE, a Java icon will appear on the Java control panel. If you find that the Java icon cannot be displayed, it will prompt that the program cannot be found when you click it, as shown below:

Teach you how to configure the Applet environmentThe Java icon that cannot be displayed above means that the JRE environment on Windows cannot be found and the JRE needs to be reinstalled. The normally available JRE environment is as shown below:

Teach you how to configure the Applet environmentClick the Java icon to open the Java Control Panel (javacpl), indicating that the JRE on Windows is already available.

To sum up, Java applications and Java Applets have different requirements for the running environment. When a Java application is running, there is no need to find the registry, as long as the JDK directory is specified, it can be run. For Applet applets, the Java Plugin in the web browser needs to find the JRE environment through the registry and run the Java Applet.

Therefore, it is recommended that the local Java environment:

Install a higher version of JRE to support newer web browsers running Applets Program The JDK required for Java applications,

directly copy the JDK binary directory and use , no installation is required, multiple JDKs can coexist, and the JDK version must be used when executing.

Appendix 1

: If you cannot reinstall JRE, you can follow the steps in the following article to clear the remaining Java installation information in the registry and then run the JRE installer:

Appendix 2

: How to enable Java in a web browser? (It must meet the prerequisite that JRE is installed and available, and the web browser has Java Plugin installed)

www.java.com/zh_CN/download/help/enable_browser.xml

Appendix 3: Hello Applet

1. Write an Applet applet, Inherit Applet base class:

Java code

public class HelloApplet extends Applet {  
  
    private static final long serialVersionUID = 5511892956119084309L;  
  
    @Override  
    public void init() {  
        Graphics g = this.getGraphics();  
        paint(g);  
    }  
  
    public void paint(Graphics g) {  
        g.drawString("Hello Applet!", 45, 45);  
    }  
}

2. Compile Applet

Java code

CMD>javac HelloApplet.java

3. Embed the Applet applet in the index.html web page

Html code

...  
<applet alt="" code="cn.david.applet.HelloApplet.class" archive="applet-1.0.0-SNAPSHOT.jar"  width="200" height="200"   
codebase=".">  
</applet>  
...

Note:

*Applet must be embedded into a web page to run. Use the tag to embed Applet

*codeAttributeSpecify Applet Class

*The archive attribute specifies the jar package where the applet is located. If it is not packaged, it can be omitted

*The codebase attribute specifies the root directory used to find the Applet class and Jar package. This directory is relative to For the directory where the web page is located, specify a relative directory. codebase="." means to search for the Applet applet in the web page directory.

*The tag should be used in the web page. When using , it can run normally in the web page, but the applet window cannot be displayed in the appletviewer.

4. Use appletviewer to test Applet applet

Java code

CMD>appletviewer index.html

Teach you how to configure the Applet environment

5. Run Applet in web browser Applet

Drag the web page to the browser to view it, or deploy the web page and Applet applet to the HTML document directory of Apache to access it through the URL.

【Related Recommendations】

1. Special Recommendation: "php Programmer Toolbox" V0.1 version download

2. Java free video tutorial

3.Detailed explanation of the difference between Application and Applet

4. Introduce in detail what is Java applet

5. Teach you how to run applet in browser

The above is the detailed content of Teach you how to configure the Applet environment. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log?Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to elegantly obtain entity class variable names to build database query conditions?How to elegantly obtain entity class variable names to build database query conditions?Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How to use the Redis cache solution to efficiently realize the requirements of product ranking list?How to use the Redis cache solution to efficiently realize the requirements of product ranking list?Apr 19, 2025 pm 11:36 PM

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

How to safely convert Java objects to arrays?How to safely convert Java objects to arrays?Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

How do I convert names to numbers to implement sorting and maintain consistency in groups?How do I convert names to numbers to implement sorting and maintain consistency in groups?Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products?Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the default run configuration list of SpringBoot projects in Idea for team members to share?How to set the default run configuration list of SpringBoot projects in Idea for team members to share?Apr 19, 2025 pm 11:24 PM

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools