Results 1 to 9 of 9

Thread: Small questionI

  1. #1
    ProtoMan is offline Member
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Default Small questionI

    I'm making a tic-tac-toe game that uses JButtons with image icons in them to mark whoever's turn it is.
    I was wondering if there is a way to make it so that disabled JButtons have regular JButton colors, rather than the greyscale that they have now.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Don't disable the button. If a player clicks a button that has already been chosen then simply put in a check before changing the icon for that button. If it has already been chosen make no change and pop-up a warning message. Otherwise change icon to current player.

  3. #3
    ProtoMan is offline Member
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Don't disable the button. If a player clicks a button that has already been chosen then simply put in a check before changing the icon for that button. If it has already been chosen make no change and pop-up a warning message. Otherwise change icon to current player.
    Another question:
    How do I clear the icon from a JButton? I thought that JButton.setIcon(""); would work, but it didn't, and I can't find a thing about it in the API.

    Edit: Nevermind, I figured it out ( JButton.setIcon(null); )

    Right now I'm just polishing it.
    Last edited by ProtoMan; 03-03-2011 at 01:37 AM.

  4. #4
    ProtoMan is offline Member
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Default

    Another 2 questions:
    Can you add an image icon to the back of a JPanel? If so, how?
    Can you add an image icon to a JOptionPane.ShowMessageDialog? If so, how?

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by ProtoMan View Post
    Another 2 questions:
    Can you add an image icon to the back of a JPanel? If so, how?
    Google
    Can you add an image icon to a JOptionPane.ShowMessageDialog? If so, how?
    Check the API. JOptionPane has more than one showMessageDialog method.

  6. #6
    ProtoMan is offline Member
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Default

    I googled.
    It said I had to override the paint method, or something like that, and I didn't really get it. It sounded complicated for what seemed like, to me, something that should be easy.

  7. #7
    ProtoMan is offline Member
    Join Date
    Feb 2011
    Posts
    14
    Rep Power
    0

    Default

    How do you make a JMenuItem store 2 different options?

    In my case, you would click file on the menu bar, click new game, and new game would extend to 1 Player or 2 Players.

  8. #8
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I believe there is something called a sub menu, try googlong for it's API. Putting an icon on a panel would probably require overriding paintcomponent, it's not as difficult as it may seem, check out the sun tutorials.

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Quote Originally Posted by ProtoMan View Post
    How do you make a JMenuItem store 2 different options?

    In my case, you would click file on the menu bar, click new game, and new game would extend to 1 Player or 2 Players.
    Just add a JMenu to a JMenu.

Similar Threads

  1. small windows
    By ghostofdarling in forum Java Applets
    Replies: 1
    Last Post: 04-17-2010, 08:55 AM
  2. small problem
    By rawan in forum Java Applets
    Replies: 2
    Last Post: 04-07-2010, 03:32 AM
  3. A small doubt
    By ranganathan in forum New To Java
    Replies: 5
    Last Post: 02-19-2010, 06:18 AM
  4. small code, need help
    By p0rnstar in forum New To Java
    Replies: 22
    Last Post: 01-22-2010, 01:57 PM
  5. Small problem
    By ayoood in forum New To Java
    Replies: 2
    Last Post: 06-06-2008, 12:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •