关于游戏开发

问题描述 投票:-1回答:1

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));”给出错误“无法实例化类型计时器”

java
1个回答
0
投票

com.sun.glass.ui.Timer是一个抽象类。我认为您真正想要使用的是:javax.swing.Timer。相应地更新您的导入语句。

© www.soinside.com 2019 - 2024. All rights reserved.