Thank you for your effort Kenny , this is a very good tutorial for an average programmer. Please keep up the good work like this one. I have subcribed recently and watching all of your prev. tutorials
Great video, very clear. I am going to try to modify your code to where the computer can play one of the players. I have seen it done in Python so I will try in Java.
I assume people will follow the tutorial to learn and later improve on the project. I purposely left out the replay button so that it would be something for you to figure out on your own. Shouldn't be too difficult since following the tutorial will teach you how to add a button, add an action listener to that button when clicked, and at the end of the video I also identified which variables you should update when resetting the game.
very cool explanation! Will there be more JavaScript content? will there be any JavaScript tutorials or maybe you will understand the algorithms and Data Structures in JavaScript? And yet, can I contact you personally, write to you?
Yes, there will be more JavaScript content in the future. Currently I’m just taking some time to focus on Java so that I can expand my content to those who prefer coding in Java. But I will continue to upload JS content
please tell me where did you learn javascript? maybe you can advise some literature on this programming language to read?! you really are the best at explaining anyone I've seen on RUclips!!!!
I am getting - Error: Could not find or load main class TicTacToe Caused by: java.lang.ClassNotFoundException: TicTacToe in my project can you tell how to resolve this problem
it is the ternary operator syntax, you can mentally read the syntax like so: currentPlayer = is (currentPlayer == playerX) ? set to playerO : else set to playerX this syntax is shorthand for the following: if (currentPlayer == playerX) { currentPlayer = playerO; } else { currentPlayer = playerX; }
Thank you for your effort Kenny , this is a very good tutorial for an average programmer. Please keep up the good work like this one. I have subcribed recently and watching all of your prev. tutorials
Very useful tutorial. The thing I like about the video is , each line of the code you explained what it does.
Help me plz about tile in 12 minute on video. I do not write “tile” because I have an issue😢
you are a king i have no idea how to code and i just made a game
you could also - to keep the code as much the same as possible change setWinner for anti-diagionally to this:
for (int i = 0; i
Impossible to dislike this... YOU SAVED MY LIFE!!!
Yeahhhh 🎉 thank you kenny. Pls be continue in java projects...
Great video, very clear. I am going to try to modify your code to where the computer can play one of the players. I have seen it done in Python so I will try in Java.
Thank you for this amazing explanation 🎉
next time please add the replay button. im currently following your all game tutorial. so it will be very helpful.
I assume people will follow the tutorial to learn and later improve on the project. I purposely left out the replay button so that it would be something for you to figure out on your own.
Shouldn't be too difficult since following the tutorial will teach you how to add a button, add an action listener to that button when clicked, and at the end of the video I also identified which variables you should update when resetting the game.
keep up man uare the best keep going i'm learning so much from you
Super underrated
super helpful my g
:)
does this code work in ide on cellphone? like Jvdroid?
Thanks for the tutorial :-)
very cool explanation! Will there be more JavaScript content? will there be any JavaScript tutorials or maybe you will understand the algorithms and Data Structures in JavaScript? And yet, can I contact you personally, write to you?
Yes, there will be more JavaScript content in the future. Currently I’m just taking some time to focus on Java so that I can expand my content to those who prefer coding in Java. But I will continue to upload JS content
Unfortunately, I don’t do personal one on ones but I usually reply to comments/questions on my videos
please tell me where did you learn javascript? maybe you can advise some literature on this programming language to read?! you really are the best at explaining anyone I've seen on RUclips!!!!
new to coding, every time I type frame.setVisible (true); I get an error about Boolean, what is that?????
Would recommend you learn the basics of coding before hopping into a project
What does the error say?
I am getting -
Error: Could not find or load main class TicTacToe
Caused by: java.lang.ClassNotFoundException: TicTacToe
in my project
can you tell how to resolve this problem
Maybe you aren't have main class in your project
Why my Inteliji IDE has not see "tile"? on 12m14sec. Help me plz!!!!
How to fix it?
playerX ? playerO : playerX;
I've never seen this kind of code before. what is that mean? sorry, im a begginer of Java.
it is the ternary operator syntax,
you can mentally read the syntax like so:
currentPlayer = is (currentPlayer == playerX) ? set to playerO : else set to playerX
this syntax is shorthand for the following:
if (currentPlayer == playerX) {
currentPlayer = playerO;
} else {
currentPlayer = playerX;
}
@@KennyYipCoding Thank you for the explanation!
Thank you
In java compiler main class" Public static void main (String [] args ) not found error is getting ?.
Solution plz🙏
Are you using vs code?
@@KennyYipCoding .
No i am not using vs code...
Will it work on it???
@@GodStories1306 no, it’s not necessary, but do you have a file with the main function?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TicTacToc {
int boardWidth = 600;
int boardHeight = 650;//50px for the text panel on top
JFrame frame =new JFrame( "Tic-Tac-Toc");
JLabel textLabel = new JLabel();
JPanel textPanel = new JPanel();
JPanel boardPanel = new JPanel();
JButton[][] board = new JButton[3][3];
String playerX = "X";
String playerO = "O";
String currentPlayer = playerX;
boolean gameOver = false;
TicTacToc() {
frame.setVisible(true);
frame.setSize(boardWidth, boardHeight);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
textLabel.setBackground(Color.darkGray);
textLabel.setForeground(Color.white);
textLabel.setFont(new Font("Arial", Font.BOLD,50));
textLabel.setHorizontalAlignment(JLabel.CENTER);
textLabel.setText("Tic-Tac-Toc");
textLabel.setOpaque(true);
textPanel.setLayout(new BorderLayout());
textPanel.add(textLabel);
frame.add(textPanel, BorderLayout.NORTH);
boardPanel.setLayout(new GridLayout(3,3));
boardPanel.setBackground(Color.darkGray);
frame.add(boardPanel);
for (int r = 0; r < 3; r++ ) {
for (int c = 0; c< 3; c++) {
JButton tile = new JButton();
board[r][c] = tile;
boardPanel.add(tile);
tile.setBackground(Color.darkGray);
tile.setForeground(Color.white);
tile.setFont(new Font("Arial", Font.BOLD, 120));
tile.setFocusable(false);
// tile.setText(currentPlayer);
tile.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (gameOver) return;
JButton tile = (JButton) e.getSource();
if (tile.getText() == "") {
tile.setText(currentPlayer);
checkWinner();
if (!gameOver){
currentPlayer = currentPlayer == playerX ? playerO : playerX;
textLabel.setText(currentPlayer + "'s turn.");
}
}
}
});
}
}
}
void checkWinner() {
//horizontal
for (int r = 0; r < 3; r++) {
if (board[r][0].getText()== "") continue;
if (board[r][0].getText() == board[r][1].getText() &&
board[r][1].getText() == board[r][2].getText ()) {
for (int i =0; i < 3; i++) {
setWinner(board[r][i]);
}
gameOver = true;
return;
}
}
//vertical
for (int c = 0; c
Why I can't see code on your site????
The GitHub link is in the video description
The code compiles and interprets but it doesnt give the output🥲 any solution??
I’m not sure what you’re referring to
did u set the visibility of ur jframe to true ?
Sombody have a restart button?😢
i guess a button and then a loop if clicked to reset all buttons
I using Replit java on phone and it keeps come up with an errors! Am i doing something wrong? Is the video wrong? What is going on?! 😭
You should code in a proper environment, there’s probably limitations coding on a website, especially on a phone
Also you should read the errors, they tell you what’s wrong
@@KennyYipCoding they dont tell me much sadly
Bros committed o7
@@LimeBytesYTyes i am
Amazing!
Thanks