Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Disablng jBottons

  1. #1
    Junior Member
    Join Date
    May 2013
    Location
    Durban South Africa
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Disablng jBottons

    myButton.setEnabled(false);



    will this line disable a button from bieng played twice in tic tac toe game

  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Disablng jBottons

    The question is out of context.

    What you've shown will disable the button from being mouse selectable and firing selected action events, but it won't prevent the underlying program logic from choosing that position as a move in the game. There must be a check in your "select a move" logic that ensures the selected square is available. Last I saw, you didn't have that check. The user and the computer players could select the same square over and over again.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    njabulo ngcobo (September 16th, 2013)

  4. #3
    Junior Member
    Join Date
    May 2013
    Location
    Durban South Africa
    Posts
    28
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Disablng jBottons

    ive fixed that one last question

    JOptionPane.showInputDialog(" welcome");

    this statement it displays welcome to the user ryt, now it also allows user to input ,idont want that ,i want it to oly displays welcom and an okay botton ,how can i modify

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Disablng jBottons

    This tutorial will describe the various options available and how to program them.

  6. #5
    Member
    Join Date
    May 2013
    Posts
    106
    My Mood
    Amused
    Thanks
    16
    Thanked 9 Times in 9 Posts

    Default Re: Disablng jBottons

    Like Greg said, the command you mentioned will disable the button, making it unclickable and unable to fire action events. However, any kind of code invoked by the event handler can still be executed if there's different logic that does the same thing. If you want to be thorough, and both disable the button and the code it invokes, you would want to close that code in some sort of if statement. The condition of the if statement would just be some boolean variable you set up, and you would set it to true or false depending on whether you want the code inside to execute.