【发布时间】:2014-12-24 13:25:15
【问题描述】:
我想在左上角画一个圆圈。圆圈的某些部分与窗口的边框重叠?如何避免这种情况?
public class Yard extends JFrame {
public static final int WIDTH = 15;
public static final int HEIGHT = 15;
private static final int BLOCK_SIZE = 30;
public void launch() {
this.setLocation(200, 200);
this.setSize(WIDTH * BLOCK_SIZE, HEIGHT * BLOCK_SIZE);
this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
this.setVisible(true);
}
@Override
public void paint(Graphics g) {
Color c = g.getColor();
g.setColor(Color.GRAY);
g.fillRect(0, 0, HEIGHT * BLOCK_SIZE, WIDTH * BLOCK_SIZE);
g.setColor(c);
g.fillOval(0, 0, 100, 100);
}
public static void main(String Args[]) {
new Yard().launch();
}
}
【问题讨论】:
-
Oracle 教程 Graphics2D 的基础知识在这里每天被问 10-15 次