The applet loads Java applications.

Source: Internet
Author: User
Many Java-related books have discussed how to write small apps and embed them into webpages. We will not repeat this type of problem here, but will discuss how to use a small application as a component, and let your own applications load and run Java small applications normally.
  
What is a small application (applet)
  
"Applet" is generally considered a secure application that can embed web pages on the Internet. It should be said that such a definition is not very accurate. Next let's take a look at the meaning of the small application.
  
Simpleapplet is used as an independent application program.
  
The basic class of a small application is the java. Applet. Applet Class, which is expanded from the java. AWT. Panel class. Therefore, small applications are panel ). The Java. AWT. Panel class is extended from the java. AWT. Container class, so small applications can also be considered as some containers ). Next, you will find that Java. AWT. the container class is extended from Java. AWT. so it can be said that the applet is a component, which means that the applet can process various events and be added to various containers.
  
Use small applications as components
  
In the above discussion, we have made it clear that the applet of the small application is a component (container), which means that the applet of the small application can be embedded into the container in an appropriate form.
Add a small application to another scenario when the application is running.
  
1. Use the main () method to load and run small applications
  
To embed a small application into other programs, it can be used by common applications. The key to implementation is to instantiate a small application in the main () method, call the init () and start () Methods of the small application, create a new framework for the small application, and include the small application. The source program list is as follows:
  
"Simpleapplet. Java"
  
Import java. Applet .*;
  
Import java. AWT .*;
  
Public class simpleapplet extends applet {
  
Public static void main (string [] ARGs ){
  
Frame F = new frame ("A frame! ″);
  
Simpleapplet H = new simpleapplet ();
  
H. INIT ();
  
H. Start ();
  
F. Add ("center", H );
  
F. Pack ();
  
F. Show ();}
  
Public void Init (){
  
Add (new label ("I Am a component ″));}
  
}
  
2. Load small applications with other classes
  
Small applications do not have to be the primary driver of applications. If necessary, other classes can also load, install, and run small applications. In the following example, a frame is created and a small application is loaded twice. The source program list is as follows:
  
"Simpleapplet. Java"
  
Import java. Applet .*;
  
Import java. AWT .*;
  
Public class simpleapplet extends applet {
  
Public void Init (){
  
Add (new label ("I Am a component ″));}
  
}
  
"Multi. Java"
  
Import java. Applet .*;
  
Import java. AWT .*;
  
Public class multi extends frame {
  
Public static void main (string [] ARGs ){
  
Multi MA = new multi ("frame ″);
  
Ma. Resize (200,200 );
  
Ma. setlayout (New gridlayout (2, 1 ));
  
Ma. launchapplet ();
  
Ma. launchapplet ();
  
Ma. Show ();}
  
Public multi (string s ){
  
Super (s );}
  
Void launchapplet (){
  
Applet theapplet = new simpleapplet ();
  
Add (theapplet );
  
Theapplet. INIT ();
  
Theapplet. Start ();}
  
}
  
Note: During running, you can first use the javac command to compile "simpleapplet. Java", and then copy the compiled "simpleapplet. Class" to the directory where "multi. Java" is located. Finally, compile "multi. Java" with the javac command and run "multi" with the Java command.
  
Through the above introduction, we can draw a conclusion that the applet is not only a security-protected application that is used to embed web pages on the Internet, but also an applet) it can also be added to other applications as components. We can instantiate small applications in the main () method, or load and run some small applications in other classes.
96 stack Software Programming Network, http://www.96dz.com, C \ c ++, Java, C #. NET programming, Linux programming, Web programming professional website.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.