1. Trang chủ
  2. » Công Nghệ Thông Tin

Lập trình Java cơ bản : Lập trình GUI (Applet) part 4 pot

5 379 1
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 62,76 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Lớp Graphics• Vẽ đường thẳng • public void drawLineint x1, int y1, int x2, int y2; • Vẽ hình chữ nhật • public void drawRectint x, int y, int width, int height; • Tô một hình chữ nhật •

Trang 1

Lớp Graphics

• Vẽ đường thẳng

• public void drawLine(int x1, int y1, int x2, int y2);

• Vẽ hình chữ nhật

• public void drawRect(int x, int y, int width, int height);

• Tô một hình chữ nhật

• public void fillRect(int x, int y, int width, int height);

• Xoá một vùng chữ nhật

• public void clearRect(int x, int y, int width, int height);

• Vẽ đa giác

• public void drawPolygon(int[] x, int[] y, int numPoint);

• public void drawPolygon(Polygon p);

Trang 2

Lớp Graphics

17

•importimportDemojava.applet.java.awt.GraphicsApplet;;

public class DemoRect extends Applet

{

public void init()

{

System.out.println("Demonstration of some simple figures"); }

public void paint(Graphics g)

{

g.drawLine(70, 300, 400, 250);

g.drawRect(100, 50, 130, 170);

g.fillRect(120, 70, 70, 70);

int[] x = { 280, 310, 330, 430, 370 };

int[] y = { 2p0, 140, 170, 70, 90 };

g.drawPolygon(x, y, x.length);

}

}

Trang 3

Lớp Graphics

Trang 4

Lớp Graphics

19

• Vẽ đường tròn/elip

• public void drawOval(int x, int y, int width, int height);

• Tô đường tròn/elip

• public void fillOval(int x, int y, int width, int height);

• Vẽ cung tròn

• public void drawArc(int x, int y, int width, int height,

int startAngle, int arcAngle);

• Vẽ xâu kí tự

• public void drawString(String str, int x, int y);

• Vẽ ảnh

• public void drawImage(Image img, int x, int y, );

Trang 5

Lớp Graphics

•importimportDemojava.applet.java.awt.GraphicsApplet;;

public class DemoOval extends Applet

{

public void init()

{

System.out.println("Demonstration of some simple figures"); }

public void paint(Graphics g)

{

int xstart = 70, ystart = 40, size = 100;

g.drawOval(xstart, ystart, size, size);

g.drawOval(xstart + (size*3)/4, ystart, size, size);

g.drawOval(xstart + size/2, ystart + size/2, size, size);

g.drawArc(xstart, ystart, 300, 200, 0, -90);

g.drawString("good morning !", xstart + 265, ystart + 90);

Ngày đăng: 26/07/2014, 12:21

TỪ KHÓA LIÊN QUAN