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

2014/6/13

Very Confused! Pls Help!

1
2
danpost danpost

2014/6/14

#
Mint_Greenie wrote...
@danpost: Thanks a lot for your help! Just one last question. Is there any way I can execute the code from the 'world' class from the 'options' class?
I do not see why you would need to do that in the 'world' class; but
world w = (world)getWorld();
w.playGame();
// or simply
((world)getWorld()).playGame();
would work. Using 'new World()' first would not work because the case is wrong for your subclass of World and an error will ensue saying 'World' is abstract and cannot be instantiated. Even then, if you used 'new world()' to create a new world, it would not be able to find the 'playGame' method because you are assigning it to a field that holds a 'World' object instead of a 'world' object. And then, further, if you did use this:
world w = new world();
w.playGame();
you would lose all the data input by the user because it is in a different 'world' object (as the data is not in the newly created one). Actually, the second line in the above two-liner would never execute, as creating a new 'world' object will restart the options process. This will continue until the non-fileDialog option is taken.
You need to login to post a reply.
1
2