//***************************************** 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(){
@@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
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
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.
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......
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.
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
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); }
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!!!!!!
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
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 ?
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! :)))
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?
//*****************************************
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
You didn't add tie situation when no one wins
it doesn't work .
Error: Main method not found in class TicTacToe, please define the main method as:
public static void main(String[] args)
help me please
@@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
@@tusharkhandejod8327 Yes, you're right. Can you solve it, brother?
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.
Finally we have a game. I really like games
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!
Finally i am able to make my first ever java game because of youuuuuu.thankyou soooo muchhhh!I wish you success in your lifeeee
Thank you SO much sir, i learned lot from you about java GUI, SIr Please keep uploading interesting projects.
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
Awesome step by step Video. thank you very much
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.
I hope you become a millionaire through this channel.
Yeah! He will!!! Is he is already a Billionaire.
I think he is already a millionaire, facts he knows
@@MbbScyaah….married?
I love the way you teach, but please explain some difficult method or flag some times will be good for beginner. Thank you........
very helpful, I did this without any Java experience and the troubleshooting and learning was very fun and overall good experience
Comment for the channel growth
Bro Code__ you are Amazing__ I now Understand Java Because of your insightful videos__thank you✌
Thank you so much for teaching me this and I use IntelliJ and I still got it
this videos are the best! it is so fun to learn to code!
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......
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.
@@BroCodez Yes, please do
this is amazing you explain it step by step kudos , this realy motivate me
Good project bro especially for java beginners people like me
This is excellent, thanks. I am going to use this with my Java high school class to introduce GUI dev.
awesome java project for beginners
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
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...
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); }
Like the way you explain stuff
Nice and well explained
Thank U so much ! can u make a video of how to export these games and make them a stand alone game?
Nice sir but there's one thing youve forgot the tie hehe. But Thanks its very helpful
Excellent Tutorial
😍
T
his comment is to support your channel. Great video man
Tic-Tac-Toe, I'm glad i have my Bro
Man, your tutorials are a GREAT help, thak you!
Your videos are very useful thank you very much
Thanks so much bro.....this is just very easy to learn and we'll tutored. You deserve a million dollar.
Thanks for helping me with the college project, Bro.
Thanks bro for your knowledge
Waoo that's awesome
You did a great job bro... Keep it up...
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!!!!!!
You're a king. Great video!
yeah, totally
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
I also used the Random class to add a PVE mode against the computer for the fan of it😂
Very good video bro love your work it helps me so much
Thank you very match for this video
You are doing a good Job
Thank uuu,we need more of these👍🏻
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 ?
Same thing is needed by me
its easier than coding the game bro
Please add a method for draw sir Thankyou
thankuuuuu soo much
we need a spring video soon .
good explain love it
HI Bro.....I.like your tutorials.............question.....how can I add a reset button to this application?
thanks
Great 👍
This tutorial in Java is very useful.
Thank you Bro u are help me a lot to study java
impressive 👊🏼👊🏼👊🏼👊🏼😍😍
This was very helpful thank you !
do you know how or if someone would go about coding a simplistic AI player into this code?
Awesomeness bro. Thanks so much.
Thank you so much for teaching me this
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
Can you give the same code playing with computer randomly, please.. Big fan of u
Thank you soo much thats very helpful.
●● I like your theme of Eclips, can you send its link please??? Thanx again
Thanks for thas nice Tutorial!!!
how to reset for a rematch after a win or draw?
btw awesome video, ty sir
Nice Job, Can you put the link so we can play it?
great video how you can make bigger board. 10x10?
Hey quick question, would you allow me to turn this into an android game?
I will just code games like this when I am bored at work......kkkkkkk THANKS BRO, YOU ARE THE BEST!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Thanks helped me a lot also commenting for the algorithm
thanks mate, would had been great if you explained the code a bit but i guess thats too much to ask for.
"hey you, I'm talking to you" sounds familiar xDD
Dare to do?
Thanks bro, was really helpful
Awesome.
Sooo underrated
you could probably code the way you find if there is a winning combination just by checking the last button that was clicked.
Hello bro i wanna learn algorithm and data structure.Can you make tutorial ?
Me too
Simply Love it!
Good video
I really need this Thanks
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! :)))
Yes please. I was wondering if I could snag it and modify it. I'm making a heavily modified version of Tic Tac Toe.
@@lilsquirt9248 I will not make it today but I will send it tommorow, nice anyone interested :))
>>>> This is the second half of the code, just paste underneath the previous part...
@@MatejDrbohlav01 Thanks. Do you have Discord by chance?
could you show us how to output a tie screen .... ?
Bro, thank you ❤️ for being awesome ❤️
Nice video
Great video, thanks👍🏻
Fantastic tutorial!
Nice Video Bro !
is it possible to use while loop to re run the program automatically?
Thanks for the videos. I've learned so much from your videos. Thanks alot.
very nice.
Will you create a matching game using button in java
The video was so helpful
best teacher ever
Kudosss!
Fajne, pozdrawiam! :)
That was ultra cool
Thank you so much
It was so nice 🌹
Best video
like from Khorezm
One doubt , why dont we need a game loop for this game!?
Can you make a video how to make a main menu
amazing
Thank God am here
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?
Yeah bro I learned the logic behind the game. Btw, just posted this to "Help you, help ME"..