Java beginners practice tutorial-applet

Source: Internet
Author: User

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

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.