Text display with tips for Java Applet Programming

Source: Internet
Author: User

[Document Introduction] display text is the most basic function in Java. It is very simple to support text display.

Display text is the most basic function in Java. It supports text display in a very simple way. You only need to use the drawString () function in Graphics. Let's look at the simplest example of ghq:

// 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 text content at the coordinates of 20 and 20
}


This is the most basic Java Applet. Only "ghq is a student!" is displayed during running !". Java supports Unicode, so Chinese characters can be well displayed in Java !" Change to "Hello! Welcome to visit !", It can also be displayed. (If it cannot be correctly displayed, It is a browser Bug. For example, IE4.0 has such a problem. use Netscape or IE5.0 or later ). It is worth noting that in Java, each character is represented by 16 bits rather than 8 bits, which is different from the C language.

Related Article

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.