Results 1 to 3 of 3
Thread: I need help with my TicTacToe
- 04-19-2011, 02:58 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 13
- Rep Power
- 0
I need help with my TicTacToe
// This is my code i can't make it work i don't know what it needs. I know i have to put some other codes but i don't know where and what i have to add//
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TicTacToeV1 implements ActionListener {
/*Instance Variables*/
private JFrame window = new JFrame("Tic-Tac-Toe");
private JButton button1 = new JButton("");
private JButton button2 = new JButton("");
private JButton button3 = new JButton("");
private JButton button4 = new JButton("");
private JButton button5 = new JButton("");
private JButton button6 = new JButton("");
private JButton button7 = new JButton("");
private JButton button8 = new JButton("");
private JButton button9 = new JButton("");
private String letter = "";
private int count = 0;
private boolean win = false;
JButton jbtn1v1 = new JButton("Player vs Player");
JMenuBar jmnuMain = new JMenuBar();
JMenuItem jmnuNewGame = new JMenuItem("New Game");
JButton jbtnEmpty[] = new JButton[10];
JLabel lblTitle = new JLabel("Tic-Tac-Toe");
//JLable
private JLable jblPlayerX;
private JLable jblPlayerO;
//JTextField
private JTextField jtfName = new JTextField(20);
private JTextField jtfPlayerX;
private JTextField jtfPlayerO;
//JPanel
JPanel jpnlNewGame = new JPanel();
JPanel jpnlNorth = new JPanel();
JPanel jpnlSouth = new JPanel();
JPanel jpnlTop = new JPanel();
JPanel jpnlBottom = new JPanel();
JPanel jpnlPlayingField = new JPanel();
// class Constructor
public TicTacToeV1(String sTitle){
/*Create Window*/
super (sTitle);
window.setSize(400,400);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLO SE);
window.setLayout(new GridLayout(3,3));
/*Add Buttons To The Window*/
window.add(button1);
window.add(button2);
window.add(button3);
window.add(button4);
window.add(button5);
window.add(button6);
window.add(button7);
window.add(button8);
window.add(button9);
/*Add The Action Listener To The Buttons*/
button1.addActionListener(this);
button2.addActionListener(this);
button3.addActionListener(this);
button4.addActionListener(this);
button5.addActionListener(this);
button6.addActionListener(this);
button7.addActionListener(this);
button8.addActionListener(this);
button9.addActionListener(this);
/*Make The Window Visible*/
window.setVisible(true);
}// end Constructor
public void actionPerformed(java.awt.event.ActionEvent e){
}// end actionPerformed
public static void main(String[] args) {
TicTacToeSwing winTicTacToeSwing = new TicTacToeSwing("Tic Tac Toe Swing");
} // end main
- 04-19-2011, 03:08 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Your action performed method doesn't do anything yet, which I'm sure you are aware of. Your problem though is that you never set the window to be visible.
JFrame has a method called setVisible(boolean b), you need to use it.
Also, seems like a lot of teachers really enjoy having students make tic tac toe.
- 04-19-2011, 03:10 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
i can't make it work i don't know what it needs. I know i have to put some other codes but i don't know where and what i have to add
What sort of problem description is this?
I'm sorry to be blunt, but you've been here for a while and have continued to post in this vein. As Fubarable observed 'Again, please read the "smart questions" link as this teasing information out of you will get old for both of us soon.' (Go back through your threads, find his post and read the link he provided)
Does the code you posted compile? If there are compiler messages you can't understand, post the messages and say to which lines of your code they refer.
Does the code produce unwanted behaviour at runtime - including runtime exceptions? If so describe the actual behaviour as well as what you intended the program to do.
The thing is that "doesn't work" means nothing to people who haven't been told what the program was supposed to do in the first place!
Similar Threads
-
TicTacToe Help
By Ryan10 in forum New To JavaReplies: 16Last Post: 03-31-2011, 07:01 PM -
Help with TicTacToe
By jokerboy123 in forum New To JavaReplies: 1Last Post: 01-22-2011, 01:29 AM -
Help with tictactoe
By ximenaacucr in forum New To JavaReplies: 3Last Post: 09-16-2009, 08:30 PM -
TicTacToe
By Thomas Covington in forum New To JavaReplies: 1Last Post: 04-10-2008, 04:51 AM -
TicTacToe
By Joe3161 in forum New To JavaReplies: 4Last Post: 11-25-2007, 06:47 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks