Close
Login to Your Account
Faadooengineers
F Polls
Loading...
Results 1 to 3 of 3

Thread: Java Source code for TicTacToe

  1. #1
    Fuchcha FaaDoO Engineer
    Join Date
    Jan 2011
    Posts
    4

    Gender: : Male

    City : Aligarh




    Txt 32 Java Source code for TicTacToe

    Here is the source code for the TicTacToe ...

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class TicTacToe extends JFrame implements ActionListener {

    private int[][] winCombinations = new int[][] {
    {0, 1, 2}, {3, 4, 5}, {6, 7, 8},
    {0, 3, 6}, {1, 4, 7}, {2, 5, 8},
    {0, 4, 8}, {2, 4, 6}
    };
    Font f1 = new Font("Times New Roman", 1, 72);

    JMenuBar bar;
    JMenu jm1;
    JMenuItem jt1,jt2;
    JButton buttons[] = new JButton[9];
    int flg = 0;
    String letter = "";
    boolean win = false;

    public TicTacToe(){

    setLayout(new GridLayout(1,1));

    bar=new JMenuBar();
    jm1=new JMenu("File");
    jt1=new JMenuItem("New");
    jt2=new JMenuItem("Exit");

    add(bar);
    jm1.add(jt1);
    jm1.addSeparator();
    jm1.add(jt2);
    add(jm1);
    bar.add(jm1);


    setVisible(true);
    setSize(400,400);

    setLayout(new GridLayout(3,3));


    for(int i=0; i<=8; i++){
    buttons[i] = new JButton();

    add(buttons[i]);
    buttons[i].addActionListener(this);
    }


    setVisible(true);
    }

    public void actionPerformed(ActionEvent a) {
    flg++;


    if(flg % 2 == 0){
    letter = "O";
    } else {
    letter = "X";
    }


    JButton pressedButton = (JButton)a.getSource();
    pressedButton.setFont(f1);
    pressedButton.setBackground(Color.cyan);

    pressedButton.setText(letter);

    pressedButton.setEnabled(false);


    for(int i=0; i<=7; i++){
    if( buttons[winCombinations[i][0]].getText().equals(buttons[winCombinations[i][1]].getText()) &&
    buttons[winCombinations[i][1]].getText().equals(buttons[winCombinations[i][2]].getText()) &&
    buttons[winCombinations[i][0]].getText() != ""){
    win = true;
    }
    }


    if(win == true){
    JOptionPane.showMessageDialog(null, letter + " wins the game!");
    System.exit(0);
    } else if(flg == 9 && win == false){
    JOptionPane.showMessageDialog(null, "The game was tie!");
    System.exit(0);
    }
    }

    public static void main(String[] args){
    TicTacToe starter = new TicTacToe();
    }
    }
    if you have any query, please contact through PM.


    Attached Files for Direct Download
      File Name:
      File Size:
      2.0 KB
    * Click on the 'file icon' or 'file name' to start downloading
    Last edited by Sakshi Dutta; 10th February 2011 at 07:45 PM. Reason: email sharing not allowed, make your threads more presentable!

  2. #2
    Fuchcha FaaDoO Engineer
    Join Date
    Sep 2012
    Posts
    2

    Gender: : Female

    Branch: : Information Technology Engineering

    City : Jaipur

    Re: Java Source code for TicTacToe

    dere is error in this codeing.............

  3. #3
    Fuchcha FaaDoO Engineer
    Join Date
    Aug 2012
    Posts
    1

    Gender: : Male

    Branch: : Computer Science Engineering

    City : Mumbai

    Re: Java Source code for TicTacToe

    can you please post java code for hitori algorithm

    ---------- Post added at 01:43 PM ---------- Previous post was at 01:41 PM ----------

    /home/nick/Downloads/TicTacToe1.txt

Tags for this Thread


Send Birthday Wish
Send Birthday Wish
  • savitapoonia
    Branch : Computer Science Engineering

    savitapoonia

  • abinashkaji
    Branch : Electronics Engineering

    abinashkaji

  • suresh270
    Branch : Electrical Engineering

    suresh270

  • holy123
    Branch : THIS DOES NOT APPLY ON ME!

    holy123

  • ROHIT RAJAN
    Branch : Mechanical Engineering

    ROHIT RAJAN

  • rahulp123
    Branch : Information Technology Engineering

    rahulp123

  • grandhi92
    Branch : Electronics Engineering

    grandhi92

  • shruthigvr

    shruthigvr

  • omiadhi1234567
    Branch : Mechanical Engineering

    omiadhi1234567

  • Source82

    Source82

  • saud.mughal
    Branch : Computer Science Engineering

    saud.mughal

  • MANAN ROY
    Branch : Computer Science Engineering

    MANAN ROY

  • raghav9811
    Branch : Bio-Tech Engineering

    raghav9811

  • khalilahmad81
    Branch : Computer Science Engineering

    khalilahmad81

  • aakashaaaa
    Branch : Electrical Engineering

    aakashaaaa

  • vikas008
    Branch : Electrical Engineering

    vikas008

  • sarvdeep
    Branch : Mechanical Engineering

    sarvdeep

  • suhas1
    Branch : Computer Science Engineering

    suhas1

  • maddy.p

    maddy.p

  • kpkendall
    Branch : Mechanical Engineering

    kpkendall

  • ramziya
    Branch : Electronics Engineering

    ramziya

  • anniegupta
    Branch : THIS DOES NOT APPLY ON ME!

    anniegupta

  • pu12345
    Branch : Computer Science Engineering

    pu12345

  • akshayjain7967
    Branch : Electronics Engineering

    akshayjain7967

  • anandurtvm
    Branch : Electronics Engineering

    anandurtvm

  • ashutosh.makwana94
    Branch : Aeronautical Engineering

    ashutosh.makwana94

  • gvgsgoutham

    gvgsgoutham

  • devendrasingh paroda

    devendrasingh paroda

  • djrajput
    Branch : Information Technology Engineering

    djrajput

  • santhanakumar.t
    Branch : Mechanical Engineering

    santhanakumar.t

  • jai.pawar7
    Branch : Aeronautical Engineering

    jai.pawar7

  • Ravi Babel

    Ravi Babel

  • praweenmasthan
    Branch : Computer Science Engineering

    praweenmasthan

  • kdesai58

    kdesai58

  • surana_abhijeet
    Branch : Electrical Engineering

    surana_abhijeet

  • Sazz786
    Branch : Mechanical Engineering

    Sazz786

  • aniltandon
    Branch : Electronics Engineering

    aniltandon

  • natkhataditya
    Branch : Mechanical Engineering

    natkhataditya

  • Ram4137
    Branch : Computer Science Engineering

    Ram4137

  • shusaroha
    Branch : THIS DOES NOT APPLY ON ME!

    shusaroha

  • mc100207235
    Branch : Computer Science Engineering

    mc100207235

  • achu m
    Branch : Electrical Engineering

    achu m

  • kishan6016
    Branch : Information Technology Engineering

    kishan6016

  • subhodip
    Branch : Electronics Engineering

    subhodip

  • suresh

    suresh

  • harish dargu
    Branch : Computer Science Engineering

    harish dargu

  • Crystal

    Crystal

  • balaji1991
    Branch : Electronics Engineering

    balaji1991

  • dawoodshah
    Branch : Instrumentation Engineering

    dawoodshah

  • nimish.great.best
    Branch : Some other branch

    nimish.great.best

  • grandhi.sv.n.rama.praveen

    grandhi.sv.n.rama.praveen

  • chingthewar
    Branch : Computer Science Engineering

    chingthewar

  • rohn_pks
    Branch : Aeronautical Engineering

    rohn_pks

  • valiirathi
    Branch : Electronics Engineering

    valiirathi

  • kat

    kat

  • NIMISHA DWIVEDI
    Branch : Civil Engineering

    NIMISHA DWIVEDI

  • praveen13

    praveen13

  • kyoalex
    Branch : Electrical Engineering

    kyoalex

  • amaroli
    Branch : Civil Engineering

    amaroli

  • faizan7861
    Branch : Computer Science Engineering

    faizan7861

  • deyabhijit

    deyabhijit

  • routmak
    Branch : Computer Science Engineering

    routmak

  • Arijit Karmakar
    Branch : Aeronautical Engineering

    Arijit Karmakar

  • Munazzar

    Munazzar

  • prasanthsarma
    Branch : Computer Science Engineering

    prasanthsarma

  • Maheswaran S
    Branch : Some other branch

    Maheswaran S

  • gangasagar
    Branch : Information Technology Engineering

    gangasagar

  • KKEENNUU
    Branch : Electrical Engineering

    KKEENNUU

  • SETTIPALLI SRIDHAR

    SETTIPALLI SRIDHAR

  • mukesh99

    mukesh99

  • pratik418

    pratik418

  • cs.amit1

    cs.amit1

  • heikhama
    Branch : THIS DOES NOT APPLY ON ME!

    heikhama

  • anupriya234
    Branch : Computer Science Engineering

    anupriya234

  • karthiskkarthi
    Branch : Electronics Engineering

    karthiskkarthi

  • swethareddy.puppala
    Branch : Electronics Engineering

    swethareddy.puppala

  • gajjar

    gajjar

  • kulkarniyogeshak

    kulkarniyogeshak

  • dipak

    dipak

  • ankur_backtorock
    Branch : Computer Science Engineering

    ankur_backtorock

  • chakra Tech
    Branch : Computer Science Engineering

    chakra Tech

  • wrtwyewyhe
    Branch : Computer Science Engineering

    wrtwyewyhe

  • shubham180293

    shubham180293

  • Darshanshah
    Branch : Civil Engineering

    Darshanshah

  • SID1994OCT

    SID1994OCT

  • tesba
    Branch : Civil Engineering

    tesba

  • joyz4angel
    Branch : Computer Science Engineering

    joyz4angel

  • Sankaravel
    Branch : Some other branch

    Sankaravel

  • aravindraju
    Branch : Electronics Engineering

    aravindraju

  • trajesh.engg
    Branch : Computer Science Engineering

    trajesh.engg

  • janmesh
    Branch : Computer Science Engineering

    janmesh

  • samuelwines
    Branch : Some other branch

    samuelwines

  • anthony1234
    Branch : Instrumentation Engineering

    anthony1234

  • RENUKAANAND
    Branch : Computer Science Engineering

    RENUKAANAND

  • aparna arora

    aparna arora

  • jvntaker

    jvntaker

  • bapina18
    Branch : Electrical Engineering

    bapina18

  • kuhcpqsz519
    Branch : Aeronautical Engineering

    kuhcpqsz519

  • tapas.rangers
    Branch : Computer Science Engineering

    tapas.rangers

  • srinivasareddy306
    Branch : Mechanical Engineering

    srinivasareddy306

×

Send Birthday wish

Send Wish