Java Applet Getting Started example

Source: Internet
Author: User

An example of the preparation activity before:

1. To have a Java compiler, it can be the sun's JDK compiler, it can be Microsoft's vj++, or it could be a compiler developed by some other companies.

2. A text writing software, the general machine has, Notepad can be. If it is vj++, you can save this step, if the JDK, it is best to have one.

3. Browser, can be Netscape, of course, can also be Microsoft's IE, other browsers, I do not know whether to support Java, it is best to prepare the two of the one bar, I believe it is not difficult!

Two hands to write the first Java applet program: Helloworld.java, with Notepad on it.

The source program code is as follows:

import java.applet .*;
import java.awt.*;
public class HelloWorld extends Applet
{
 public void paint(Graphics g)
 {
  g.drawString ("你好,Java世界!",2,20);
 }
}

(This example is very brief.) But can explain a lot of questions, hehe, to explain in detail later)

When you have finished typing This example, remember to save it with Helloworld.java.

Compiling three with JDK compilers:

In the DOS command line, enter the following command:

C:\JavaJdk\javac.exe Helloworld.java

The previous C:\JavaJdk\ is the directory name where the JDK is installed, Javac.exe is the name of the compiler, and Helloworld.java is the name of the program you have just written, if the compilation is not successful, it is your source code input problems, please carefully check, then compile, after the successful compilation, will generate a Helloworld.class file. At this point, things are basically done. The next step is to put the generated. class file into the Web page and create a Web page file, as follows:

</body>
<p>
<applet code=HelloWorld.class
width=300
height=200>
</applet>
</body>

I don't have to tell you how to see it, hehe. Double-click the file and open it in the browser to see the effect of the file you just compiled. Effect please look ahead.

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.