• Post Reply Bookmark Topic Watch Topic
  • New Topic

GUI for Mastermind Game - Question

 
Kevin Behr
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

So I created a text-based version of the game mastermind. If you are not familiar with it, here is a link to a pre-existing java game:

http://www.irt.org/games/js/mind/

What I want to do now, is to develop a GUI for it. So I downloaded NetBeans, and created a UI for it. Before I start what I believe will be a difficult task (adding functionality to the UI - I have never done this before), I have a question or two:

First, here is the UI that I have created:



Now, the white boxes that you see are text boxes...

First question: Is it possible to click on a text box and, each time I click on it, the background color changes (looping through six colors)?

Second question: Is there a way to disable a Panel? Or, if not, to disable text boxes and buttons?

Third question: If I cannot achieve that which is presented in the first question, I will simply have the user type in the first letter of each of the six colors, i.e. R,O,Y,G,B,P into the text boxes. Can I limit the length of the text boxes to 1 character?

Thanks for your help guys, I feel like this will be tough...
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can indeed respond to clicks in text boxes, but it might look a little weird, and there could be some tricky details. It would be more traditional and easier to use nice little square JButtons!

You can disable any Swing component that accepts input with setEnabled(false); here you'd want to loop over your buttons (or text fields, if you insist) and call this on each one.
 
Kevin Behr
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great, thanks alot! I'll use the JButtons instead.
 
Kevin Behr
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One more thing - I have each "set" of JButton's and the Guess Button in it's own JPanel - just to keep them grouped together. Should I take them out? Are there advantages/disadvantages?

Thanks!
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's OK. Actually, many developers do this to make the layout easier.
 
Kevin Behr
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, yes I found it easier too. Thanks alot.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!