Java programming thoughts (2)

Source: Internet
Author: User

Why does Sun develop the applet? What are the shortcomings of browsers in client programming? This is the first question I thought about when I started learning the applet section. Applet is a small program embedded in a web browser (what is the difference between Applet and Microsoft ActiveX Control? Puzzled ...).

 

In my opinion, we need something that combines the advantages of the "thin client" in B/S mode and the powerful and rich programming capabilities of the C/S mode, in this way, the functions of the Web browser are extended. Why does the applet appear. However, because the applet comes from the server, there are many limits for it for security reasons. (Java runtime security systems always stare at this Pandora box .) : 1) It cannot access (read/write) the local disk. This is of course a security consideration, but excessive security restrictions will also damage the applications of many trusted applets. Therefore, sun improves the digital signature to allow users to select the behavior of the applet. 2) the applet is on the server side, so it needs to be downloaded to the client every time. If you need a class to be downloaded through a browser, the user will wait too long. Therefore, we should package the entire applet component into a jar, so that we can download the required applet completely by sending a request to the server. of course, the advantages of Applet are also obvious: 1) when the software is updated, the installation and maintenance of the client is too cumbersome, the 'dll hell' caused by version chaos is even more annoying. The applet has nothing to do with the platform on the basis of JVM. Therefore, as long as a virtual machine is installed on the local machine, you can directly download and run the applet. therefore, when the applet is updated, you can avoid the trouble of installing and updating the client. 2) because of the built-in security mechanisms of Java and Applet, you do not have to worry about the harm of Applet to your machine.

 

The purpose of the application framework class library is to provide one or more classes with certain basic functions to help programmers create applications. These basic functions are essential to such applications. So when you write an application, you only need to inherit this class, and then overwrite several methods you are interested in as needed, so you can customize its behavior. The default control mechanism of the application framework will call the methods you write at the right time. The application framework is an excellent example of "separating things that will change and will not change. Its design philosophy is to overwrite the personalized part of the program locally. Separate the unchanged and variable parts to respond to business changes. The applet is created using the application framework. You only need to inherit the japplet class and override several methods.



Init ()
The applet is automatically called during initialization. Its tasks include the layout of the loaded components. Must be overwritten.
 
Start ()
It is called when an applet is displayed in a web browser. After the display is complete, the applet starts to work normally (especially those that are closed with stop ). (In addition, the application framework) also calls this method after calling Init.
 
Stop ()
Call the applet when it disappears from the web browser, so that it can close some resource-consuming operations. In addition, this method will be called before (called by the application framework) destroy.
 
Destroy ()
When the applet is no longer needed by the browser and needs to be detached from the page, this method will be called to release resources.
 

 

 

Let alone, let's take a simple example:

Import java. AWT .*;

Import javax. Swing .*;

Public class testapplet extends japplet

{

Public void Init ()

{

Button btnok = new button ("OK ");

This. getcontentpane (). Add (btnok );

}

}

Swing requires that all components be added to the content Panel (content pane) of the Form. Therefore, when adding (), getcontentpane () must be called first (), instead of directly adding to the form like AWT.

To run a program, you must first put the applet into a web page and then open the page with a Web browser that can run Java. You need to put the applet in the web page with a special tag, and then let it tell the page how to load and run the applet.

 

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.