2
public class TerrisView extends JFrame {
public Canvas canvas;
public TerrisView(String title) {
super(title);
canvas = new Canvas();
canvas.setSize(300, 400);
canvas.setBackground(Color.WHITE);
// setSize(300, 400);
this.add(canvas, BorderLayout.CENTER);
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
paint();
}
public void paint() {
// this.createBufferStrategy(2);
// Graphics gp=getBufferStrategy().getDrawGraphics();
// gp.setColor(Color.RED);
// gp.fillRect(100, 100, 50, 50);
// getBufferStrategy().show();
Graphics gp = canvas.getGraphics();
gp.setColor(Color.BLACK);
gp.fillRect(0, 0, 10, 10);
}
}
爲什麼它在畫布上繪製Rect
失敗?代碼有什麼問題?搖擺畫布沒有按預期繪畫(或根本沒有畫)
發佈代碼或代碼片段時,請使用代碼格式。 – 2012-03-30 04:00:56