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.