Displaying text is the most basic function in Java. It is a very simple way to support the display of text. It can be achieved by using the drawString() function in the Graphics class. Let's look at the simplest ghq example:
//ghq.java
import java.awt.*;
import java.applet.*;
public class ghq extends Applet
{
String text="ghq is a student!";
public void paint(Graphics g)
{
g.drawString(text,20,20);
} //Display the content of text at coordinates 20,20
}
This is the most basic Java Applet, which only displays "ghq is a student!" when running. Java supports Unicode, so Chinese can also be displayed well in Java. We change "ghq is a student!" to "Hello! Welcome to visit!", which can also be displayed (if it cannot be displayed correctly, it is the browser Bug, if you are using IE4.0, there is such a problem, please switch to Netscape or IE5.0 or above). It is worth noting that each character in Java is represented by 16 bits instead of 8 bits, which is different from the C language.