In the current java World, many things are called x×let, and x×let all mean small programs. For example, applet applications, servlet server-side applets, mini programs in the midlet mobile phone, and small programs in the portlet portal container. In this section, we will introduce the applet. This is not a lot of things, but it makes sense in the java architecture. This item can be run in a browser and can be embedded into an HTML page. We know that the common Application must have main () as the entry point, and the Applet should be run in the browser, or appletviewer should be used for viewing during development. For example, practice:
Import java. awt .*;
Import java. applet .*;
@ SuppressWarnings ("serial") // suppress the warning
// All the applets inherit the java. Applet. applet
Public class HelloApplet extends Applet {
Public void paint (Graphics g ){
G. drawString ("baibaiquan software project lab! ", 30, 30 );
}}
Create an html file because it can be embedded in a browser. Use the notebook to create a hello.html Code as follows:
<Applet code = "HelloApplet. class" width = 150 heightb = 150> </applet> www.2cto.com
Then compile the class with javac. Finally, enter appletviewer hello.html in the command line to view the result.
This kind of Applet makes up for the shortcomings of the B/S model and can execute the client's things in a browser. It is a good thing because it is powerful. However, this feature is so powerful that it raises some security issues. Therefore, the browser also imposes some security restrictions on the applet. Applet also has a mechanism called the Sandbox Model, which makes resources without access permissions inaccessible. Security is ensured. At the same time, it is not so convenient for development. Applet is also a cross-platform feature.
In addition, Microsoft's IE browser does not run quickly when running the applet, which is not as convenient as activex. The interface is not too beautiful. However, its idea of running in a browser is still quite good.
Author: tbwshc