package com.globalsoftwaresupport.ui;
import java.awt.Dimension;导入java.awt.Graphics;
import javax.swing.ImageIcon;导入javax.swing.JPanel;
import com.globalsoftwaresupport.constants.Constants;
导入com.globalsoftwaresupport.image.Image;
import com.globalsoftwaresupport.image.ImageFactory;
import com.sun.glass.ui.Timer;
公共类GamePanel扩展了JPanel {
private ImageIcon backgroundImage;
private Timer timer;
public GamePanel() {
initilizeVariables();
initilaizeLayout();
}
private void initilizeVariables() {
this.backgroundImage=ImageFactory.createImage(Image.BACKGROUND);
this.timer = new Timer(Constants.GAME_SPEED,new GameLoop(this));
this.timer.start();
}
private void initilaizeLayout() {
setPreferredSize(new Dimension(Constants.BOARD_WIDTH,Constants.BOARD_HEIGHT));
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
g.drawImage(backgroundImage.getImage(),0,0,null);
System.out.println("REPAINT");
}
public void doOneLoop() {
update();
repaint();
Blockquote
}
private void update() {
System.out.println("Update");
}
}
第24行“ this.timer = new Timer(Constants.GAME_SPEED,new GameLoop(this));”给出错误“无法实例化类型计时器”
com.sun.glass.ui.Timer
是一个抽象类。我认为您真正想要使用的是:javax.swing.Timer
。相应地更新您的导入语句。