This site requires JavaScript, please enable it in your browser!
Greenfoot back
DillonCummings
DillonCummings wrote ...

2012/10/18

I keep getting a class, interface, or enum expected error at public void act(), with the error line saying its just before the word void

DillonCummings DillonCummings

2012/10/18

#
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) /** * Write a description of class GameBall here. * * @author (your name) * @version (a version number or a date) */ public class GameBall extends Actor { enum BallState { UNCLICKED, GOLD, STEEL }; BallState state = BallState.UNCLICKED; public GameBall(){ setImage("cell.jpg"); } } /** * Act - do whatever the GameBall wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { // Add your action code here. } public void setGold(){ setImage("gold-ball.png"); state = BallState.GOLD; } public void setSteel(){ setImage("steel-ball.png"); state = BallState.STEEL; } public void reset(){ setImage("cell.jpg"); state = BallState.UNCLICKED; } }
Gevater_Tod4711 Gevater_Tod4711

2012/10/18

#
In java a method or anything else can't exist without a class, a interface or an enum. Try to introduce all the methods into the class GameBall. Then it should work.
danpost danpost

2012/10/18

#
Remove line 18 in the GameBall class, it is closing the class and the compiler cannot interpret the following lines because they are not what is expected at that point.
You need to login to post a reply.