我刚开始重新编码,我想我忘记了如何加倍缓冲。这是我现在拥有的代码,我不确定我缺少什么。当我启动它时,只有一个白色的屏幕,没有椭圆形。
渲染的错误是什么?
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JFrame;
public class Graphs extends JFrame {
private Image dbImage;
private Graphics dbg;
public static void main(String[] args) {
new Graphs();
}
public Graphs() {
setSize(1000, 600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
setTitle("Graphs");
setLocationRelativeTo(null);
setVisible(true);
}
public void paint(Graphics g) {
dbImage = createImage(getWidth(), getHeight());
dbg = dbImage.getGraphics();
paintComponent(dbg);
dbg.drawImage(dbImage, 0, 0, this);
}
public void paintComponent(Graphics g) {
g.drawOval(200, 200, 200, 200);
repaint();
}
}
更新:编译错误@Override
The method paintComponent(Graphics) of type Graphs must override or implement a supertype method.
1 quick fix available:
-> Remove '@Override' annotation