Java tic tac toe game ⭕

แชร์
ฝัง

ความคิดเห็น • 384

  • @BroCodez
    @BroCodez  4 ปีที่แล้ว +334

    //*****************************************
    public class Main {
    public static void main(String[] args) {
    TicTacToe tictactoe = new TicTacToe();

    }
    }
    //*****************************************
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    public class TicTacToe implements ActionListener{
    Random random = new Random();
    JFrame frame = new JFrame();
    JPanel title_panel = new JPanel();
    JPanel button_panel = new JPanel();
    JLabel textfield = new JLabel();
    JButton[] buttons = new JButton[9];
    boolean player1_turn;
    TicTacToe(){

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(800,800);
    frame.getContentPane().setBackground(new Color(50,50,50));
    frame.setLayout(new BorderLayout());
    frame.setVisible(true);

    textfield.setBackground(new Color(25,25,25));
    textfield.setForeground(new Color(25,255,0));
    textfield.setFont(new Font("Ink Free",Font.BOLD,75));
    textfield.setHorizontalAlignment(JLabel.CENTER);
    textfield.setText("Tic-Tac-Toe");
    textfield.setOpaque(true);

    title_panel.setLayout(new BorderLayout());
    title_panel.setBounds(0,0,800,100);

    button_panel.setLayout(new GridLayout(3,3));
    button_panel.setBackground(new Color(150,150,150));

    for(int i=0;i

    • @tusharkhandejod8327
      @tusharkhandejod8327 3 ปีที่แล้ว +17

      You didn't add tie situation when no one wins

    • @hendlegleg2021
      @hendlegleg2021 3 ปีที่แล้ว +5

      it doesn't work .
      Error: Main method not found in class TicTacToe, please define the main method as:
      public static void main(String[] args)

    • @hendlegleg2021
      @hendlegleg2021 3 ปีที่แล้ว +1

      help me please

    • @divakarkumarjha1171
      @divakarkumarjha1171 3 ปีที่แล้ว

      @@hendlegleg2021 many videos are available on TH-cam to solve this problem so you can search to get proper solution you can check BS Sindhu channel here you will get solution

    • @luthfiardiansyah8530
      @luthfiardiansyah8530 3 ปีที่แล้ว

      @@tusharkhandejod8327 Yes, you're right. Can you solve it, brother?

  • @KLead963
    @KLead963 2 ปีที่แล้ว +10

    Man you helped me a lot! Your way is very easy to understand every single code! BIG THANKS. And I already subscribed and liked the video.

  • @girl6994
    @girl6994 4 ปีที่แล้ว +14

    Finally we have a game. I really like games

  • @wolanus
    @wolanus 3 ปีที่แล้ว +5

    Another comment for the channel growth. Haven't been here for some time, but I see you've got much more subs. Well deserved! Thanks Bro!

  • @hamnabutt3000
    @hamnabutt3000 3 ปีที่แล้ว +6

    Finally i am able to make my first ever java game because of youuuuuu.thankyou soooo muchhhh!I wish you success in your lifeeee

  • @anilsuyal
    @anilsuyal 2 ปีที่แล้ว +2

    Thank you SO much sir, i learned lot from you about java GUI, SIr Please keep uploading interesting projects.

  • @gennius9726
    @gennius9726 3 ปีที่แล้ว +13

    thank you so much for this example .... :D
    very useful .....I'm currently playing on 2 tables so to speak: taking your 5 hours long tutorial on GUI in Eclipse, and at the same time going trough mini-projects just like this one :)
    cheers

  • @girishpoojari2910
    @girishpoojari2910 3 ปีที่แล้ว

    Awesome step by step Video. thank you very much

  • @YM-ix8uw
    @YM-ix8uw 3 ปีที่แล้ว +4

    Thanks for the code in the comments!
    I was trying to learn how to use GUI (I'm a beginner). I somewhat know what you were doing while I was following the tutorial.

  • @mkhaled23
    @mkhaled23 3 ปีที่แล้ว +125

    I hope you become a millionaire through this channel.

    • @ShivamSingh-te9tl
      @ShivamSingh-te9tl 10 หลายเดือนก่อน +1

      Yeah! He will!!! Is he is already a Billionaire.

    • @MbbScy
      @MbbScy 9 หลายเดือนก่อน +3

      I think he is already a millionaire, facts he knows

    • @user-ie6kl8gl6j
      @user-ie6kl8gl6j 23 วันที่ผ่านมา

      @@MbbScyaah….married?

  • @krishnaadhikari7098
    @krishnaadhikari7098 2 ปีที่แล้ว

    I love the way you teach, but please explain some difficult method or flag some times will be good for beginner. Thank you........

  • @hayyannadeem4346
    @hayyannadeem4346 11 หลายเดือนก่อน

    very helpful, I did this without any Java experience and the troubleshooting and learning was very fun and overall good experience

  • @supanam
    @supanam 2 ปีที่แล้ว

    Comment for the channel growth

  • @ntlakusojunior695
    @ntlakusojunior695 9 หลายเดือนก่อน

    Bro Code__ you are Amazing__ I now Understand Java Because of your insightful videos__thank you✌

  • @jonneelycrisp1930
    @jonneelycrisp1930 3 ปีที่แล้ว +5

    Thank you so much for teaching me this and I use IntelliJ and I still got it

  • @iceblockgaming9792
    @iceblockgaming9792 3 ปีที่แล้ว

    this videos are the best! it is so fun to learn to code!

  • @bossali2527
    @bossali2527 4 ปีที่แล้ว +5

    Hi bro code I love your videos hoping you will add java applet to your java course and we will do game development like creating adventure games and also we will do some algorithm and data structure and it will be more fun if we learn it through game development like development a sport game!!!!! thanks for video it has help me a lot......

    • @BroCodez
      @BroCodez  4 ปีที่แล้ว +5

      I was planning on adding a few small games for now, but I am open to suggestions for future videos. However it make take some time since I'm covering a few different languages on this channel.

    • @stephanieezat-panah7750
      @stephanieezat-panah7750 2 ปีที่แล้ว

      @@BroCodez Yes, please do

  • @minatouzumaki6
    @minatouzumaki6 ปีที่แล้ว

    this is amazing you explain it step by step kudos , this realy motivate me

  • @arfan6108
    @arfan6108 9 หลายเดือนก่อน

    Good project bro especially for java beginners people like me

  • @themasterrogerdelgado
    @themasterrogerdelgado 4 หลายเดือนก่อน

    This is excellent, thanks. I am going to use this with my Java high school class to introduce GUI dev.

  • @playerno1234
    @playerno1234 2 ปีที่แล้ว

    awesome java project for beginners

  • @erickim5712
    @erickim5712 ปีที่แล้ว +3

    Hello, I was trying to use the same concept to make a connect 4 to implement a way so I can code on my own. I guess only for the check function I would be coding on my own. However, when trying to draw on the each button panel it would only work once drawing a O. I put I

  • @dihanahmed965
    @dihanahmed965 3 ปีที่แล้ว

    thanks a lot brother ... you saved my day... thank you so much ...
    it will be a great help if you make a video about AI Play in TIC TAC TOE...

  • @levirann
    @levirann 3 ปีที่แล้ว +31

    Another easier, yet not completely optimal, way to code the winning condition, is to set the variables for A, B, C and the winnter "X" or "O" first, that way you can change only those variables and run the same if statement again and again like so:
    int A = 0;
    int B = 1;
    int C = 2;
    String testWinner = "X";
    if((buttons[A].getText()==testWinner) && (buttons[B].getText()==testWinner) && (buttons[C].getText()==testWinner)){ xWins(A,B,C); }
    A = 0;
    B = 1;
    C = 2;
    testWinner = "O";
    if((buttons[A].getText()==testWinner) && (buttons[B].getText()==testWinner) && (buttons[C].getText()==testWinner)){ oWins(A,B,C); }

  • @hubert8856
    @hubert8856 3 ปีที่แล้ว +1

    Like the way you explain stuff

  • @ucee
    @ucee 2 ปีที่แล้ว

    Nice and well explained

  • @itamaryuran8640
    @itamaryuran8640 3 ปีที่แล้ว

    Thank U so much ! can u make a video of how to export these games and make them a stand alone game?

  • @jaylordjl6337
    @jaylordjl6337 2 ปีที่แล้ว

    Nice sir but there's one thing youve forgot the tie hehe. But Thanks its very helpful

  • @rajeevranjanmishra1188
    @rajeevranjanmishra1188 ปีที่แล้ว

    Excellent Tutorial
    😍

  • @manthanpatki146
    @manthanpatki146 3 ปีที่แล้ว

    T
    his comment is to support your channel. Great video man

  • @janekk3397
    @janekk3397 ปีที่แล้ว

    Tic-Tac-Toe, I'm glad i have my Bro
    Man, your tutorials are a GREAT help, thak you!

  • @biancaserea5479
    @biancaserea5479 ปีที่แล้ว

    Your videos are very useful thank you very much

  • @wiggletv1567
    @wiggletv1567 หลายเดือนก่อน

    Thanks so much bro.....this is just very easy to learn and we'll tutored. You deserve a million dollar.

  • @KaushikUpadhyay-od4xl
    @KaushikUpadhyay-od4xl 2 หลายเดือนก่อน +1

    Thanks for helping me with the college project, Bro.

  • @richardgujja7460
    @richardgujja7460 3 ปีที่แล้ว

    Thanks bro for your knowledge

  • @manishpatidar5379
    @manishpatidar5379 3 ปีที่แล้ว

    Waoo that's awesome

  • @localbus7008
    @localbus7008 2 ปีที่แล้ว

    You did a great job bro... Keep it up...

  • @shamc8096
    @shamc8096 2 ปีที่แล้ว

    Sir, actually you are crazy and also you are the most underrated diamond I think so, I learned a lot of thinks and thank you for this kind of awesome programs. I request you to not leave this and please provide us many videos like this!!!!!!

  • @lucadestroyer98
    @lucadestroyer98 3 ปีที่แล้ว +3

    You're a king. Great video!

  • @kenkei.mwaniki
    @kenkei.mwaniki 20 วันที่ผ่านมา

    Nice
    I watched this then went and made the game but used JavaFX instead of Swing
    Learnt both from you and im super grateful.
    Also advanced the music player program you showed in the JavaFX lessons to have all the features a typical music player would have (shuffle, loop, playlists, search, access to audio metadata, library (artists, albums etc)
    Was really fun as my first project with Java.
    Could you make a video on how to create a runnable JAR file from JavaFX programs?
    The method for swing programs doesn't involve adding VM arguments and I've been struggling with this

    • @kenkei.mwaniki
      @kenkei.mwaniki 20 วันที่ผ่านมา

      I also used the Random class to add a PVE mode against the computer for the fan of it😂

  • @aussmohammed9865
    @aussmohammed9865 10 วันที่ผ่านมา

    Very good video bro love your work it helps me so much

  • @justinbanza4751
    @justinbanza4751 2 ปีที่แล้ว

    Thank you very match for this video
    You are doing a good Job

  • @akumablueberries
    @akumablueberries ปีที่แล้ว

    Thank uuu,we need more of these👍🏻

  • @Tebek
    @Tebek 3 ปีที่แล้ว +24

    Hi, can you please make a follow up tutorial to this where you add a screen before the game where it asks for player1's name and then for player 2's name ?

    • @__ArnobShariar
      @__ArnobShariar 2 ปีที่แล้ว

      Same thing is needed by me

    • @goplay1121
      @goplay1121 2 ปีที่แล้ว +5

      its easier than coding the game bro

  • @jaylordjl6337
    @jaylordjl6337 3 ปีที่แล้ว

    Please add a method for draw sir Thankyou

  • @PPTV07
    @PPTV07 2 ปีที่แล้ว

    thankuuuuu soo much
    we need a spring video soon .

  • @Yasmin-uc8vj
    @Yasmin-uc8vj 3 ปีที่แล้ว +1

    good explain love it

  • @omarmorales7117
    @omarmorales7117 3 ปีที่แล้ว +1

    HI Bro.....I.like your tutorials.............question.....how can I add a reset button to this application?
    thanks

  • @alexbagirov2583
    @alexbagirov2583 2 ปีที่แล้ว

    Great 👍

  • @panagiotiskougioumtzidis9114
    @panagiotiskougioumtzidis9114 3 ปีที่แล้ว

    This tutorial in Java is very useful.

  • @viniciusgentile2151
    @viniciusgentile2151 3 หลายเดือนก่อน

    Thank you Bro u are help me a lot to study java

  • @murtazagawhary4373
    @murtazagawhary4373 3 ปีที่แล้ว

    impressive 👊🏼👊🏼👊🏼👊🏼😍😍

  • @Purrpleb
    @Purrpleb ปีที่แล้ว

    This was very helpful thank you !
    do you know how or if someone would go about coding a simplistic AI player into this code?

  • @superkingpunga
    @superkingpunga 2 ปีที่แล้ว

    Awesomeness bro. Thanks so much.

  • @abdurrochman1093
    @abdurrochman1093 2 ปีที่แล้ว

    Thank you so much for teaching me this

  • @daizdamien1409
    @daizdamien1409 2 ปีที่แล้ว

    I main thing i watched this video was to check how the ai worked. Bro can you do that? Btw the prog is cool :D

  • @nizamchowdhury
    @nizamchowdhury 3 ปีที่แล้ว

    Can you give the same code playing with computer randomly, please.. Big fan of u

  • @helpandsupportcenter8353
    @helpandsupportcenter8353 2 ปีที่แล้ว

    Thank you soo much thats very helpful.
    ●● I like your theme of Eclips, can you send its link please??? Thanx again

  • @iven.jsr07
    @iven.jsr07 3 ปีที่แล้ว

    Thanks for thas nice Tutorial!!!

  • @rhujisiekajiri2269
    @rhujisiekajiri2269 3 ปีที่แล้ว +2

    how to reset for a rematch after a win or draw?
    btw awesome video, ty sir

  • @Neelpl80
    @Neelpl80 3 ปีที่แล้ว +1

    Nice Job, Can you put the link so we can play it?

  • @grzegorzszymonowicz3500
    @grzegorzszymonowicz3500 2 ปีที่แล้ว

    great video how you can make bigger board. 10x10?

  • @eliya9277
    @eliya9277 3 ปีที่แล้ว

    Hey quick question, would you allow me to turn this into an android game?

  • @hanibaltesfamichael5936
    @hanibaltesfamichael5936 2 ปีที่แล้ว

    I will just code games like this when I am bored at work......kkkkkkk THANKS BRO, YOU ARE THE BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  • @waterfallz3768
    @waterfallz3768 3 ปีที่แล้ว

    Thanks helped me a lot also commenting for the algorithm

  • @debamchakraborty1143
    @debamchakraborty1143 2 ปีที่แล้ว

    thanks mate, would had been great if you explained the code a bit but i guess thats too much to ask for.

  • @user-tf3vo7fg4i
    @user-tf3vo7fg4i 2 ปีที่แล้ว

    "hey you, I'm talking to you" sounds familiar xDD

    • @moli7075
      @moli7075 2 ปีที่แล้ว

      Dare to do?

  • @sidharth5849
    @sidharth5849 3 ปีที่แล้ว

    Thanks bro, was really helpful

  • @vasilizaitsev7246
    @vasilizaitsev7246 3 ปีที่แล้ว

    Awesome.

  • @ultimatelegoman1279
    @ultimatelegoman1279 3 ปีที่แล้ว +4

    Sooo underrated

  • @matthewsarsam7062
    @matthewsarsam7062 ปีที่แล้ว

    you could probably code the way you find if there is a winning combination just by checking the last button that was clicked.

  • @developerjunior446
    @developerjunior446 3 ปีที่แล้ว +1

    Hello bro i wanna learn algorithm and data structure.Can you make tutorial ?

  • @dragomirpetrov5138
    @dragomirpetrov5138 ปีที่แล้ว

    Simply Love it!

  • @user-wn1db9fm4o
    @user-wn1db9fm4o 3 ปีที่แล้ว

    Good video

  • @ctluwua7695
    @ctluwua7695 3 ปีที่แล้ว

    I really need this Thanks

  • @MatejDrbohlav01
    @MatejDrbohlav01 2 ปีที่แล้ว +1

    Hello guys! It was so much fun! I liked it so much, that I created "Five in a row" modification with 12 rows and columns (I am now working on making the grid size customizable) If anyone is interested I will post the code here! :)))

    • @lilsquirt9248
      @lilsquirt9248 2 ปีที่แล้ว +1

      Yes please. I was wondering if I could snag it and modify it. I'm making a heavily modified version of Tic Tac Toe.

    • @MatejDrbohlav01
      @MatejDrbohlav01 2 ปีที่แล้ว

      @@lilsquirt9248 I will not make it today but I will send it tommorow, nice anyone interested :))

    • @MatejDrbohlav01
      @MatejDrbohlav01 2 ปีที่แล้ว

      >>>> This is the second half of the code, just paste underneath the previous part...

    • @lilsquirt9248
      @lilsquirt9248 2 ปีที่แล้ว

      ​@@MatejDrbohlav01 Thanks. Do you have Discord by chance?

  • @gennius9726
    @gennius9726 3 ปีที่แล้ว

    could you show us how to output a tie screen .... ?

  • @neillunavat
    @neillunavat 3 ปีที่แล้ว +1

    Bro, thank you ❤️ for being awesome ❤️

  • @ValeriaGarciaHernandez
    @ValeriaGarciaHernandez 11 หลายเดือนก่อน

    Nice video

  • @mullim9860
    @mullim9860 2 ปีที่แล้ว

    Great video, thanks👍🏻

  • @kingannon4131
    @kingannon4131 3 หลายเดือนก่อน

    Fantastic tutorial!

  • @ErrorNotFound-rv1ql
    @ErrorNotFound-rv1ql 3 ปีที่แล้ว +1

    Nice Video Bro !

  • @user-vf9st7dm4b
    @user-vf9st7dm4b 11 หลายเดือนก่อน

    is it possible to use while loop to re run the program automatically?

  • @aungkyawphyo8006
    @aungkyawphyo8006 3 ปีที่แล้ว

    Thanks for the videos. I've learned so much from your videos. Thanks alot.

  • @_aumaca
    @_aumaca ปีที่แล้ว

    very nice.

  • @revatiupadhye1103
    @revatiupadhye1103 ปีที่แล้ว

    Will you create a matching game using button in java

  • @ashishprakash2879
    @ashishprakash2879 3 ปีที่แล้ว

    The video was so helpful

  • @rango099
    @rango099 3 ปีที่แล้ว

    best teacher ever

  • @yemanadep2803
    @yemanadep2803 2 ปีที่แล้ว

    Kudosss!

  • @erthuberthub7948
    @erthuberthub7948 3 ปีที่แล้ว +1

    Fajne, pozdrawiam! :)

  • @Wonderland8183
    @Wonderland8183 2 ปีที่แล้ว

    That was ultra cool

  • @SiminSibi
    @SiminSibi 6 หลายเดือนก่อน

    Thank you so much
    It was so nice 🌹

  • @cookwitharjunchef6336
    @cookwitharjunchef6336 2 ปีที่แล้ว

    Best video

  • @khazarasp
    @khazarasp 3 ปีที่แล้ว

    like from Khorezm

  • @mrboss8790
    @mrboss8790 2 ปีที่แล้ว

    One doubt , why dont we need a game loop for this game!?

  • @pvprogres3637
    @pvprogres3637 3 ปีที่แล้ว

    Can you make a video how to make a main menu

  • @younesyar
    @younesyar 2 ปีที่แล้ว

    amazing

  • @matthewade7256
    @matthewade7256 2 ปีที่แล้ว

    Thank God am here

  • @naikels6922
    @naikels6922 6 หลายเดือนก่อน

    Why is the for -loop that creates the buttons placing the buttons the way we actually want them to be. They are placed in an 3x3 Format but why did it work like this?

  • @tnnm2022
    @tnnm2022 ปีที่แล้ว

    Yeah bro I learned the logic behind the game. Btw, just posted this to "Help you, help ME"..