2.1 Създаване на user interface с Java. Въведение в AWT. Applets Hello World: The Applet
The reason people are excited about Java as more than just another OOP language is because it allows them to write interactive applets on the web. Hello World isn't a very interactive program, but let's look at a webbed version.
import java.applet.Applet;
import java.awt.Graphics;
public class HelloWorldApplet extends Applet {
public void paint(Graphics g) {
g.drawString("Hello world!", 50, 25);
}
}
The applet version of HelloWorld is a little more complicated than the HelloWorld application, and it will take a little more effort to run it as well.
First type in the source code and save it into file called HelloWorldApplet.java. Compile this file in the usual way. If all is well a file called HelloWorldApplet.class will be created. Now you need to create an HTML file that will include your applet. The following simple HTML file will do.
Hello World
This is the applet:
Достарыңызбен бөлісу: |