Pages

Tuesday, August 31, 2010

Bulding Graphical MIDlets

Numeric Color Component Values




Lines
Dipakai untuk menggambar garis.
Syntax: 
drawLine(int x1, int y1, int x2, int y2)
dimana x1, y1 adalah starting point dan x2, y2 adalah ending point.

Contoh:

public void paint(Graphics g) {
g.drawLine(5, 10, 15, 55);
}


Rectangles
Dipakai untuk menggambar persegi atau persegi panjang.

Syntax: drawRect(int x, int y, int width, int height)

Contoh:

public void paint(Graphics g) {
g.drawRect(5, 10, 15, 55);
}


Arcs
Dipakai untuk menggambar sudut.

Syntax: drawArc(int x, int y, int width, int height, int startAngle, int arcAngle)


Contoh:

public void paint(Graphics g) {
g.drawArc(5, 10, 150, 75, 95, 115);
}


Drawing Text
Dipakai untuk menambahkan teks.

Syntax: setFont(Font font)


Font getFont(int face, int style, int size)



The font face must be one of the following values: FACE_SYSTEM, FACE_MONOSPACE, or FACE_PROPORTIONAL.
The style of font must be one of the constants I mentioned earlier: STYLE_PLAIN or a combination 
of STYLE_BOLD, STYLE_ITALIC, and STYLE_UNDERLINED. T
he font size is specified 
as one of the following predefined constants: SIZE_SMALL, SIZE_MEDIUM, or SIZE_LARGE.


Contoh:

Font myFont = Font.getFont(Font.MONOSPACE, Font.LARGE, Font.BOLD | Font.UNDERLINED);


drawString(String str, int x, int y, int anchor)


An anchor point is associated with a horizontal constant and a
vertical constant, each of which determines the horizontal and vertical positioning of the 
text with respect to the anchor point. The horizontal constants used to describe an anchor 
point are LEFT, HCENTER, and RIGHT. One of these constants is combined with a vertical 
constant to fully describe an anchor point. The vertical constants are TOP, BASELINE, and 
BOTTOM.

Contoh:

g.drawString(“Look up here!”, getWidth() / 2, 0, Graphics.HCENTER | Graphics.TOP);


Drawing Images
 Dipakai untuk menambahkan image atau picture.
Contoh:
public void paint(Graphics g) {
// Clear the display

g.setColor(255, 255, 255); // White
g.fillRect(0, 0, getWidth(), getHeight());


// Create and load the image

Image img = Image.createImage(“Bull.png”);


// Draw the image

g.drawImage(img, getWidth()/2, getHeight()/2,

Graphics.HCENTER|Graphics.VCENTER);
}


Sumber: Sams Teach Yourself: Wireless Java With J2ME in 21 Days

1 comment:

  1. CasinoDaddy - DrMCD
    This website is a gambling website 남양주 출장안마 operated 세종특별자치 출장샵 by Dr.MCD and operated 전주 출장샵 by the 포항 출장안마 Borgata Hotel Casino & Spa, Atlantic City. It provides information about casino License: 7/2021Location: 이천 출장샵 7.0 Rating: 7.1/10 · ‎1 review

    ReplyDelete

 

Blogger news

About Me

My photo
Palembang, Sumatera Selatan, Indonesia
Seorang yang ingin terus belajar.