• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why does my game not work as a whole?  RSS feed

 
Danny Roberts
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code[pretty sure theres nothing wrong with it]:

TAB 1



TAB 2



My question is why isn't the GameBoard class running when i run the main class(because i did initialize an object of that class didn't i)?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on your definition of "running a class" - a phrase that has no commonly understood meaning in the Java world, at least not for classes that have no main method. This code instantiates an object and invokes a method on it - if that's not what you expected to happen, then what did you expect to happen?
 
Danny Roberts
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well i would like a window to pop up where rectangle/s are shown, this only happens if i run the GameBoard class and then only the constructor rectangle is shown. If i run the game in the main class only the text(println) is shown. I want BOTH rectangles to be shown as well as the println(if the println isn't possible in this context it can be omitted).
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't run GameBoard directly because it has no main method. I'm guessing that this behavior somehow depends on the GraphicsProgram class which it extends, but without knowing how that's supposed to work it's impossible to say what might be needed to make it work.
 
Danny Roberts
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I figured out what the problem was. I was supposed to have a run() method in the GameBoard class. But this brings me to my next problem. When i click "run" in the GameBoard class tab i get all the graphics i want shown. However if i move to the MainClass tab and click "run" there instead, i get no window that shows me the graphics(however any println statements in the other class are shown in the terminal). Do you have any idea why this is the case? Does it have anything to do with one being run as an application(MainClass) and the other as an applet(GameBoard class)? And if so or otherwise how can i get everything to run properly simply from clicking "run" in the main class?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that, too, depends on one of the classes extending GraphicsProgram, and the other one not.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!