lop graphics trong java swing

2 323 0
lop graphics trong java swing

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

Thông tin tài liệu

http://vietjack.com/java_swing/index.jsp Copyright © vietjack.com Lớp Graphics Java Swing Lớp java.awt.Graphics cung cấp nhiều phương thức để lập trình đồ họa Dưới số phương thức sử dụng phổ biến lớp Graphics: public abstract void drawString(String str, int x, int y): sử dụng để vẽ chuỗi cho public void drawRect(int x, int y, int width, int height): vẽ hình chữ nhật với độ rộng width chiều cao height cho public abstract void fillRect(int x, int y, int width, int height): sử dụng để điền màu mặc định độ rộng chiều cao cho vào hình chữ nhật public abstract void drawOval(int x, int y, int width, int height): sử dụng để vẽ hình Ovan với độ rộng chiều cao cho public abstract void fillOval(int x, int y, int width, int height): sử dụng để điền màu mặc định độ rộng chiều cao cho vào hình Oval public abstract void drawLine(int x1, int y1, int x2, int y2): sử dụng để vẽ line hai điểm có tọa độ (x1, y1) (x2, y2) public abstract boolean drawImage(Image img, int x, int y, ImageObserver observer): sử dụng để vẽ hình ảnh cho public abstract void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle): sử dụng để vẽ đường tròn circular elip public abstract void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle): sử dụng để điền hình tròn elip public abstract void setColor(Color c): sử dụng để thiết lập màu đồ họa thành màu color cho public abstract void setFont(Font font): sử dụng để thiết lập font đồ họa thành font cho http://vietjack.com/ Trang chia sẻ học online miễn phí Page http://vietjack.com/java_swing/index.jsp Copyright © vietjack.com Chương trình ví dụ lớp Graphics Java Swing import java.awt.*; import javax.swing.JFrame; public class DisplayGraphics extends Canvas{ public void paint(Graphics g) { g.drawString("Hello",40,40); setBackground(Color.WHITE); g.fillRect(130, 30,100, 80); g.drawOval(30,130,50, 60); setForeground(Color.RED); g.fillOval(130,130,50, 60); g.drawArc(30, 200, 40,50,90,60); g.fillArc(30, 130, 40,50,180,40); } public static void main(String[] args) { DisplayGraphics m=new DisplayGraphics(); JFrame f=new JFrame(); f.add(m); f.setSize(400,400); //f.setLayout(null); f.setVisible(true); } } http://vietjack.com/ Trang chia sẻ học online miễn phí Page ...http://vietjack.com /java_ swing/ index.jsp Copyright © vietjack.com Chương trình ví dụ lớp Graphics Java Swing import java. awt.*; import javax .swing. JFrame; public class DisplayGraphics extends Canvas{... g.fillArc(30, 130, 40,50,180,40); } public static void main(String[] args) { DisplayGraphics m=new DisplayGraphics(); JFrame f=new JFrame(); f.add(m); f.setSize(400,400); //f.setLayout(null);... java. awt.*; import javax .swing. JFrame; public class DisplayGraphics extends Canvas{ public void paint (Graphics g) { g.drawString("Hello",40,40); setBackground(Color.WHITE); g.fillRect(130, 30,100, 80);

Ngày đăng: 02/12/2017, 21:44

Mục lục

    Lớp Graphics trong Java Swing

    Chương trình ví dụ về lớp Graphics trong Java Swing

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan