Ask your own question, for FREE!
Computer Science 17 Online
OpenStudy (joachim):

I am coding minesweeper in java (using swing) how would I start a new game? should i write a reset method, or use a constructor that defaults everything again?

OpenStudy (anonymous):

I tend to like cleaner constructors, so I'd probably pull out the code into a separate function like reset() or initialize(). There's nothing to say that your constructor can't call it. In fact it probably should, and you can keep it private if you don't anticipate it ever being needed outside that specific class. But it reduces the amount of code that's actually stuffed in the constructor, keeps the documentation cleaner, makes code reuse easier, and you can expose publicly in the future if you come across that use case. Best,

OpenStudy (joachim):

how would i incorporate multiple difficulties? such as if file->new game->easy for example is clicked in the gui how can I "reset" the gui so that the new buttons are not added, but are made from scratch...

OpenStudy (konradzuse):

you can disable / set visibility of buttons and other components that you need.

OpenStudy (joachim):

thanks - got it working

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!