【发布时间】:2020-12-04 08:16:50
【问题描述】:
这个程序使用fillPolygon()方法在屏幕上绘制一个正方形。在执行代码时,绘制部分非常慢。我该如何改进呢?还是说使用 Java AWT 进行 GUI 开发最差?
import java.awt.*;
import java.awt.event.*;
public class BluePolygon extends Frame {
int x, x1, y, y1;
public BluePolygon() {
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
System.exit(0);
}
});
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent me) {
x = me.getX();
y = me.getY();
}
});
addMouseMotionListener(new MouseAdapter() {
public void mouseDragged(MouseEvent me) {
x1 = me.getX();
y1 = me.getY();
repaint();
}
});
}
public void paint(Graphics g) {
g.setColor(new Color(Color.blue.getRed(),Color.blue.getGreen(),Color.blue.getBlue(),60));
int xx[] = {x1,x,x,x1};
int yy[] = {y,y,y1,y1};
g.fillPolygon(xx, yy, 4);
}
public static void main(String args[]) {
BluePolygon winapp = new BluePolygon();
winapp.setTitle("Blue Polygon");
winapp.setSize(1200, 720);
winapp.setVisible(true);
}
}
【问题讨论】:
标签: java user-interface graphics awt polygon