我无法发表评论,所以我会在这里说出来并在您回答时进行编辑,到目前为止您的代码是什么样的?你试过什么?有很多方法可以实现你想要的,但你的问题有点缺乏细节。
编辑:您没有显示名为grow 的字段,并且拥有一个名为grow 的字段/变量并拥有一个名为grow 的方法并不是一个好主意。
您可以根据自己的情况做的一件事就是这样。
public class Sprite extends JFrame implements ActionListener {
public boolean Grown;
public Board board; // never set in your example,
// nor do i have any idea what it is for
public Timer timer;
public BufferedImage UngrownImage; // Initialize these images yourself
public BufferedImage GrownImage;
public sprite() {
Grown = false;
timer = new Timer(1000, this);
timer.start();
}
public void actionPerformed(ActionEvent e) {
Grown = true;
board.repaint(); // you may want to call super.repaint() too
// but again I do not know what board is.
}
// unless your "Board" is taking care of it, here you can paint the images
public void paint(Graphics g) {
super.paint(g);
int imgX = 0, imgY = 0;
if(Grown && GrownImage != null)
g.drawImage(GrownImage, imgX, imgY, null);
else if(UngrownImage != null)
g.drawImage(UngrownImage, imgX, imgY, null);
else
System.out.println("error: No images loaded");
}
}
如果您有任何不明白的地方,请告诉我,我很乐意为您总结,我认为所有这些都是您使用过的东西,判断您正在尝试做的事情。