Results 1 to 3 of 3
  1. #1
    Nghasemi is offline Member
    Join Date
    Feb 2011
    Posts
    13
    Rep Power
    0

    Default 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

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    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.

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    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

  1. TicTacToe Help
    By Ryan10 in forum New To Java
    Replies: 16
    Last Post: 03-31-2011, 08:01 PM
  2. Help with TicTacToe
    By jokerboy123 in forum New To Java
    Replies: 1
    Last Post: 01-22-2011, 02:29 AM
  3. Help with tictactoe
    By ximenaacucr in forum New To Java
    Replies: 3
    Last Post: 09-16-2009, 09:30 PM
  4. TicTacToe
    By Thomas Covington in forum New To Java
    Replies: 1
    Last Post: 04-10-2008, 05:51 AM
  5. TicTacToe
    By Joe3161 in forum New To Java
    Replies: 4
    Last Post: 11-25-2007, 07:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •