How to Create a Tic Tac Toe Game in Java NetBeans

Поділитися
Вставка
  • Опубліковано 7 лют 2025
  • Create a TicTacToe games in Java NetBeans using Methods, call to methods, if statement, JFrame, jButtons, jPanels, jLabels and setting panels properties.
    To support more videos from DJ Oamen, visit POamen Paypal
    www.paypal.me/...
    To Become a Channel member click on the Link below to JOIN:
    / @djoamen
    Winning Solution for Player O below:
    if (b1==("O") && b2 == ("O") && b3 == ("O"))
    {
    JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
    oCounter++;
    gameScore();
    jButton1.setBackground(Color.PINK);
    jButton2.setBackground(Color.PINK);
    jButton3.setBackground(Color.PINK);
    }
    if (b4==("O") && b5 == ("O") && b6 == ("O"))
    {
    JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
    oCounter++;
    gameScore();
    jButton4.setBackground(Color.YELLOW);
    jButton5.setBackground(Color.YELLOW);
    jButton6.setBackground(Color.YELLOW);
    }
    if (b7==("O") && b8 == ("O") && b9 == ("O"))
    {
    JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
    oCounter++;
    gameScore();
    jButton7.setBackground(Color.MAGENTA);
    jButton8.setBackground(Color.MAGENTA);
    jButton9.setBackground(Color.MAGENTA);
    }
    if (b1==("O") && b4 == ("O") && b7 == ("O"))
    {
    JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
    oCounter++;
    gameScore();
    jButton1.setBackground(Color.MAGENTA);
    jButton4.setBackground(Color.MAGENTA);
    jButton7.setBackground(Color.MAGENTA);
    }
    if (b2==("O") && b5 == ("O") && b8 == ("O"))
    {
    JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
    oCounter++;
    gameScore();
    jButton2.setBackground(Color.MAGENTA);
    jButton5.setBackground(Color.MAGENTA);
    jButton8.setBackground(Color.MAGENTA);
    }
    if (b3==("O") && b6 == ("O") && b9 == ("O"))
    {
    JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
    oCounter++;
    gameScore();
    jButton3.setBackground(Color.PINK);
    jButton6.setBackground(Color.PINK);
    jButton9.setBackground(Color.PINK);
    }
    if (b1==("O") && b5 == ("O") && b9 == ("O"))
    {
    JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
    oCounter++;
    gameScore();
    jButton1.setBackground(Color.PINK);
    jButton5.setBackground(Color.PINK);
    jButton9.setBackground(Color.PINK);
    }
    if (b3==("O") && b5 == ("O") && b7 == ("O"))
    {
    JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
    oCounter++;
    gameScore();
    jButton3.setBackground(Color.PINK);
    jButton5.setBackground(Color.PINK);
    jButton7.setBackground(Color.PINK);
    }

КОМЕНТАРІ • 64

  • @khangdeng8286
    @khangdeng8286 4 роки тому +1

    thanks for the massive help you have provided to me through this tutorial

  • @gewoonjoppe8752
    @gewoonjoppe8752 4 роки тому

    Very nice video. Really helped me in class

  • @keanukendean1897
    @keanukendean1897 2 роки тому +2

    The score counter is not working need help

    • @DJOamen
      @DJOamen  2 роки тому +1

      Check out the function called "WinningGame". Why have you not subscribe to the channel😒

  • @jishnudipsaha2756
    @jishnudipsaha2756 4 роки тому

    nice representation of UI

    • @DJOamen
      @DJOamen  4 роки тому

      You're very welcome!

    • @jishnudipsaha2756
      @jishnudipsaha2756 4 роки тому

      @@DJOamen
      Can you make a video on "How to make this game as a application and could be shared..........................."
      pls

    • @jishnudipsaha2756
      @jishnudipsaha2756 4 роки тому

      I really
      appreciate your hard work !!!!!!!

  • @klevisgoga1294
    @klevisgoga1294 5 років тому +1

    You are fantastic.I want to try it!!!

  • @razzmakilan5463
    @razzmakilan5463 5 років тому +3

    thank you so much for the tutorial.this help me a lot for our defense

  • @kafendel1448
    @kafendel1448 5 років тому +1

    You are the best man !!!💪🤘

  • @Bboyabel17
    @Bboyabel17 5 років тому +1

    Amazing thank youu!

  • @udaysharama1854
    @udaysharama1854 4 роки тому

    Thnx sir...one more query in my exit button Yes option is working ...but NO oprtion is not working

    • @DJOamen
      @DJOamen  4 роки тому

      What do you want NO to do?

    • @udaysharama1854
      @udaysharama1854 4 роки тому

      Sir remain in the game bt when I click on no option it gets quit

    • @DJOamen
      @DJOamen  4 роки тому

      I can't understand, what you want, but check your code

  • @manishkesharwani7271
    @manishkesharwani7271 4 роки тому +1

    Sir, Is there also need of database to create tic tac TOC?

    • @DJOamen
      @DJOamen  4 роки тому +1

      No, however, you can do whatever you like.

  • @muskannagi1896
    @muskannagi1896 4 роки тому

    i have installed java jdk and did all the setup but jdk file is not opening when I run it.What should I do now?

    • @DJOamen
      @DJOamen  4 роки тому

      Re-install your Java NetBeans, you can also see some tutorials on youtube of how to install Java NetBeans

  • @grfx4205
    @grfx4205 4 роки тому

    Great video, any suggestions on code for a tie game?

    • @DJOamen
      @DJOamen  4 роки тому

      Not that I know of

  • @godwin_gonzalo3124
    @godwin_gonzalo3124 4 роки тому

    thankyouuuuu❤️

  • @MuhammadZeeshan-dg4ry
    @MuhammadZeeshan-dg4ry 4 роки тому

    you are awesone :)

  • @yudhimoodley9472
    @yudhimoodley9472 4 роки тому

    Hi, I loved this video and have thought of some quality of life improvements, however I am struggling to implement them. For instnace: How would I prevent a player from overwriting an already occupied button? Please help me out and thanks for the great work.

    • @DJOamen
      @DJOamen  4 роки тому

      You can disable the button or use on Mouse Enter event.

    • @mehrozmuzaffar4790
      @mehrozmuzaffar4790 4 роки тому

      if(jButton1.getText()!="")
      {
      return;
      }
      Put this code at the start of each button function and change jButton1 for respective button function.

  • @leizelmaebarrit1808
    @leizelmaebarrit1808 5 років тому +1

    where did you declare the JOptionPane?

    • @DJOamen
      @DJOamen  5 років тому +1

      Right at the top: import javax.swing.JOptionPane;

  • @claretiong1125
    @claretiong1125 4 роки тому

    when O win it will not show the winner, just can X to win leh?

    • @DJOamen
      @DJOamen  4 роки тому

      See the description area of the video for support

    • @claretiong1125
      @claretiong1125 4 роки тому

      oic thank you

  • @udaysharama1854
    @udaysharama1854 4 роки тому

    sir im not able to get who o player wins??????im not getting msg of o player wins

    • @DJOamen
      @DJOamen  4 роки тому

      See solution on the description area of the video

  • @abedalrahmandwairi1800
    @abedalrahmandwairi1800 4 роки тому

    if the player "O" WIN the massage the player "o" dont appear???please i need help

    • @DJOamen
      @DJOamen  4 роки тому

      See solution on the description area of the video

  • @santi2985
    @santi2985 5 років тому

    Hello sir, the O player can't win...
    I already put this code on my winningGame function:
    if(b1 == ("O") && b2 == ("O") && b3 == ("O"))

    {
    JOptionPane.showMessageDialog(this, "Player O wins", "Tic Tac Toe", JOptionPane.INFORMATION_MESSAGE);
    oCount++;
    gameScore();
    jButton1.setBackground(Color.RED);
    jButton2.setBackground(Color.RED);
    jButton3.setBackground(Color.RED);
    }
    and so on for the other combinations
    The o player in my code still doesn't win.

    • @santi2985
      @santi2985 5 років тому

      Nevermind sir, mine is working already, instead of an "O" a letter, i misinputted a "0" a number. LOL. Thanks for the wonderful video

    • @DJOamen
      @DJOamen  5 років тому

      Thanks 👍

  • @user-lc3du9zp8i
    @user-lc3du9zp8i 2 роки тому

    Helpppp only x show when i click the button

    • @DJOamen
      @DJOamen  2 роки тому

      See codes in the description

  • @AndreyjarabeGamingYT
    @AndreyjarabeGamingYT Рік тому

    Why does JOption has error for me

    • @DJOamen
      @DJOamen  Рік тому

      Carefully watch the video and check your code

  • @kavindujayamal9194
    @kavindujayamal9194 4 роки тому

    Sir, my program "O" wins are not working

    • @DJOamen
      @DJOamen  4 роки тому +1

      See the solution on the describtion area of the video: The codes is right there

    • @kavindujayamal9194
      @kavindujayamal9194 4 роки тому

      @@DJOamen thanks sir

  • @emanuelbremi
    @emanuelbremi 6 років тому +1

    Great! :)

  • @tuanle7998
    @tuanle7998 4 роки тому

    Exit no not working?????

    • @DJOamen
      @DJOamen  4 роки тому

      Check your code

  • @yfi-yonnatafajar5596
    @yfi-yonnatafajar5596 5 років тому

    Why can't Player "O"win?

    • @DJOamen
      @DJOamen  5 років тому

      Check your code

    • @tanjinmitul6626
      @tanjinmitul6626 5 років тому

      @@DJOamen It also happen with me

    • @DJOamen
      @DJOamen  5 років тому

      Check the winning function for "O": Such as below:
      if (b1==("O") && b2 == ("O") && b3 == ("O"))
      {
      JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
      oCounter++;
      gameScore();
      jButton1.setBackground(Color.PINK);
      jButton2.setBackground(Color.PINK);
      jButton3.setBackground(Color.PINK);
      }

    • @DJOamen
      @DJOamen  5 років тому

      Check the winning function for "O": Such as below:
      if (b1==("O") && b2 == ("O") && b3 == ("O"))
      {
      JOptionPane.showMessageDialog(this,"Player O Wins", "Tic Tac Toe",JOptionPane.INFORMATION_MESSAGE);
      oCounter++;
      gameScore();
      jButton1.setBackground(Color.PINK);
      jButton2.setBackground(Color.PINK);
      jButton3.setBackground(Color.PINK);
      }

    • @itzqueen3500
      @itzqueen3500 5 років тому

      @@DJOamen Should we merge that in X wins? (Sorry for my bad english)