Java learning notes-the first Applet and the solution to a small problem

Source: Internet
Author: User

Continue learning!

Create a helloworld_app.java file in the D: \ majava \ folder and write the following content:

Import Java. AWT .*;
Import Java. Applet .*;
Public Class Helloworld_app Extends Applet
{
Public Void Init (){
}
Public Void Paint (Graphics g)
{
G. drawstring ("Hello world! ", 25, 25 );
}

}

Then I wrote a helloworld_app.html file and wrote the following:Code:

< Applet Code = "Helloworld_app" Width = 150 Height = 100 >

</Applet> 

Compilation SourceProgram: D: \ myjava> javac helloworld_app.java

Run: D: \ myjava> appletviewer helloworld_app.html

This problem occurs during execution:

"Warning: the attribute file of appletviewer cannot be read". There is another directory. Forget it. Then Baidu gave it a try and the solution was as follows:

1. Open the Command Prompt window (CMD)

2. Enter policytool and press Enter.
3. In the policytool dialog box, click Add Policy entry (add rule project)
4. Click Add permission (add permission)
5. Click the license drop-down menu and select all permission.
6. Click OK)
7. Click Done)
8. select Save As from the File menu (save as from the File menu)

9. In c: \ Documents ents and Settings \ Administrator (current operating system username) \ "file name" (it seems that it can be in any directory, and I saved it to the C root directory)

After performing the nine steps, compile and run the program again, and there will be no above errors!

Cut a picture to commemorate it.

 

In addition, double-click the webpage file to execute it in the browser!

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.