DoJa version of the Helloword program

Source: Internet
Author: User

As with all other Java programs, each DoJa program needs to have an entry function.

Gossip less, or read the procedure first:

import com.nttdocomo.ui.*;
import com.nttdocomo.io.*;
public class HelloWorld extends IApplication  // —— (1)
{
public HelloWorld()
{
System.out.println("Construct IApplication!");
}
public void start()     // —— (2)
{
Display.setCurrent(new MyCanvas());     // —— (3)
System.out.println("Start IApplication!");
}
public class MyCanvas extends Canvas    // —— (4)
{
public MyCanvas()
{
System.out.println("Construct MyCanvas!");
}
public void paint(Graphics g)    // —— (5)
{
g.drawString("Hello Doja!", 20, 20);   // —— (6)
}
}
}

(1). The main class of the application, the class name must be the same as the project name, where you can consider it as the main () function in the C language. Class Com.nttdocomo.ui.IApplication provides a prototype for each application, and the main class of all programs must inherit this class.

(2). The main class must overwrite method Start () in IApplication, which is also the first method that is invoked after the program is run.

(3). You can interpret this as a definition of an artboard, on which you can have a picture, text, graphic ... to operate.

(4). Define your own artboard and inherit the class Canvas (Com.nttdocomo.ui.Canvas). DoJa's framework is mainly divided into canvas and panel, the former is the low-end application interface and then the advanced application interface. Panel mainly provides the operation of the form, for the game design is not very useful and it is relatively regular, easy to grasp, so here we mainly study class canvas.

(5). Each artboard class must overwrite method Paint (Graphics g), which is used to draw on the artboard. You can repaint the artboard by means of repaint (Intx, Inty, Intwidth, intheight) or repaint ().

(6). Draw text on the artboard. You can also set the associated font properties by calling SetColor (int c), SetFont (font f).

All right, the next step is to "compile-> run" on the emulator.

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.