嘿,我制作了一个java Projekt,它在Mac上运行得非常好,见截图1。 但是当我在linux上运行相同的项目时,似乎有些麻烦可能有人知道为什么会发生这种情况?似乎重绘在linux上无法正常工作。
private void startGame(){
gameOver = false;
loop = new Timer(10, new ActionListener() {
@Override
public void actionPerformed(ActionEvent x) {
board.play();
frame.repaint();
}});
loop.start()}
@Override
public void paint(Graphics g) {
Point a = board.getBird().getLeftBottemCorner();
Point b = (board.getBird().getRightUpCorner());
g.setColor(Color.red);
g.fillRect(a.x, a.y, b.x - a.x, b.y - a.y);
drawHurdles(g);
g.setColor(Color.red);
g.drawString("Score: " + board.getBird().getHighScore(),10 , board.getBoardHight()+15);
}
private void drawHurdles(Graphics g) {
g.setColor(Color.black);
ArrayList<Model.BOX> hurdles = board.getHindernisse().getHurdles();
Iterator<BOX> it = hurdles.iterator();
Point a;
Point b;
BOX akt;
int hoehe;
while (it.hasNext()) {
akt = it.next();
hoehe = akt.getRightUpCorner().y - akt.getLeftBottemCorner().y;
a = akt.getLeftBottemCorner();
b = akt.getRightUpCorner();
g.fillRect(a.x, a.y, b.x - a.x, hoehe);
System.out.println(a + ", " + b + ", " + hoehe);
}
}
也许有人知道为什么重绘不要在linux上清理?
答案 0 :(得分:3)
您需要在super.paint(g);
方法中调用paint
,以消除绘制工件。但你甚至不应该在JFrame上绘画。而是在JPanel上绘制并覆盖paintComponent
并调用super.paintComponent
。请参阅Performing Custom Painting
答案 1 :(得分:-1)
您可以尝试处理图形。
public void paint (Graphics g) {
g.setColor (Color.white);
g.fillRect (0,0,2000,1000);
// your painting stuff here
g.dispose();
}