【发布时间】:2015-03-17 23:32:26
【问题描述】:
所以我们正在为游戏制作头像,并且我们已经将头像创建为Avatar 类文件。我们的问题是,在我们的类文件Game 中,我们很难将 Avatar 声明为实例变量。
代码如下:
public class Game extends JApplet {
private static final long serialVersionUID = 1L;
public static final long WIDTH = 800;
public static final long HEIGHT = 600;
// Declare an instance variable to reference your Avatar object
public @Override void init() {
// Store an instantiated Avatar into the instance variable
setSize(new Dimension( WIDTH, HEIGHT));
getContentPane().setBackground(Color.BLUE);
}
public @Override void paint(Graphics g) {
super.paint(g); // Call the JAplet paint method (inheritance)
// Call the draw method in your Avatar class
}
}
【问题讨论】:
-
您是否按照 Oracle 网站上的教程路径进行操作?
-
你的问题是什么?
-
究竟是什么阻止了您为 Avatar 声明实例变量?抱歉,我真的看不到你在问什么。
标签: java object instance-variables japplet