Sie sind auf Seite 1von 20

JAVA SWING FRONT END

MINOR PROJECT REPORT


Submitted by

Ashim singh thapa (RA1711003010499)


Challa Naga Venkata Rohit (RA1711003011481)
for the course

15SE205J – Programming In Java


In partial fulfilment for the award of the degree

of

Bachelor of Technology
In

COMPUTER SCIENCE AND TECHNOLOGY

SRM INSTITUTE OF SCIENCE AND TECHNOLOGY


KATTANKULATHUR

APRIL 2019
SRM INSTITUTE OF SCIENCE AND TECHNOLOGY
KATTANKULATHUR

BONAFIDE CERTIFCATE

Certified that this project report on “TIC TAC TOE GAME” is the bonafide work of “ASHIM SINGH

THAPA (RA1711003010499) AND CHALLA NAGA VENKATA ROHIT(RA1711003011481)” who carried

out the project work as part of their course 15SE205J – PROGRAMMING IN JAVA.

SIGNATURE SIGNATURE

Course Instructor -Ms.R.Anita Head Of Department

Computer Science and Engineering

INTERNAL EXAMINER
Department of Computer Science and Engineering
SRM Institute of Science & Technology
Own Work* Declaration Form

This sheet must be filled in (each box ticked to show that the condition has been met). It must
be signed and dated along with your student registration number and included with all assignments
you submit – work will not be marked unless this is done.
To be completed by the student for all assessments

Degree/ Course : B.Tech / 15SE205J – Programming In Java

Student Name : Ashim Singh Thapa

: Challa Rohit

Registration Number : RA1711003010499

: RA1711003011481

Title of Work : TIC TAC TOE GAME

I / We hereby certify that this assessment compiles with the University’s Rules and Regulations relating to Academic
misconduct and plagiarism**, as listed in the University Website, Regulations, and the Education Committee guidelines.

I / We confirm that all the work contained in this assessment is my / our own except where indicated, and that I / We have
met the following conditions:

 Clearly references / listed all sources as appropriate


 Referenced and put in inverted commas all quoted text (from books, web, etc)
 Given the sources of all pictures, data etc. that are not my own
 Not made any use of the report(s) or essay(s) of any other student(s) either past or present
 Acknowledged in appropriate places any help that I have received from others (e.g. fellow students, technicians,
statisticians, external sources)
 Compiled with any other plagiarism criteria specified in the Course handbook / University website

I understand that any false claim for this work will be penalised in accordance with the University policies and
regulations.

DECLARATION:
I am aware of and understand the University’s policy on Academic misconduct and plagiarism and I certify that this
assessment is my / our own work, except where indicated by referring, and that I have followed the good academic
practices noted above.

If you are working in a group, please write your registration numbers and sign with the date for every student in your
group.

Please Note: If you are still unsure about what plagiarism is or need advice on how to avoid it, you can
1. Consult your programme handbook
2. Refer the University website or
3. Contact any one of the following assistances:
Your Faculty, Course Co-ordinator, Project Supervisor, Faculty Advisor, Head of the Department
OBJECTIVE
The project that we made is our first step towards
learning the basics of swing.
We hope our project to help people pass their
time while playing the game.
They can either play with the computer or their
friend. It’s their choice.
Since tic tac toe is a popular game, we thought of
making it as our first miniproject using swing.
Its simple yet time consuming game.
Hope people enjoy it.
CONTRIBUTION
The project is made with the help of google,
YouTube. We used both of them for making
our project.
Our faculty also played an important role in
helping us making the project. She taught us
the thing which is most important in making
the project i.e. she taught us java.
As for myself I worked hard with my associate
Akash to bring the project to life.
Numerous attempts were made before the
project could be compiled.
After several failed attempts we were able to
bring the game which we wanted to life.
In this project both me and my associate
worked hard so that we can finish what we
started.
And thus, here it is THE TIC TAC TOE GAME.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class TTT1 extends JFrame implements
ItemListener, ActionListener{
int i,j,ii,jj,x,y,yesnull;
int
a[][]={{10,1,2,3,11},{10,1,4,7,11},{10,1,5,9,11},{1
0,2,5,8,11},
{10,3,5,7,11},{10,3,6,9,11},{10,4,5,6,11},
{10,7,8,9,11} };
int
a1[][]={{10,1,2,3,11},{10,1,4,7,11},{10,1,5,9,11},{
10,2,5,8,11},

{10,3,5,7,11},{10,3,6,9,11},{10,4,5,6,11},{10,7,8,9,
11} };

boolean state,type,set;
Icon ic1,ic2,icon,ic11,ic22;
Checkbox c1,c2;
JLabel l1,l2;
JButton b[]=new JButton[9];
JButton reset;

public void showButton(){

x=10; y=10;j=0;
for(i=0;i<=8;i++,x+=100,j++){
b[i]=new JButton();
if(j==3)
{j=0; y+=100; x=10;}
b[i].setBounds(x,y,100,100);
add(b[i]);
b[i].addActionListener(this);
}

reset=new JButton("RESET");
reset.setBounds(100,350,100,50);
add(reset);
reset.addActionListener(this);

public void check(int num1){


for(ii=0;ii<=7;ii++){
for(jj=1;jj<=3;jj++){
if(a[ii][jj]==num1){ a[ii][4]=11; }

}
}

public void complogic(int num){


for(i=0;i<=7;i++){
for(j=1;j<=3;j++){
if(a[i][j]==num){ a[i][0]=11; a[i][4]=10; }
}
}
for(i=0;i<=7;i++){
set=true;
if(a[i][4]==10){
int count=0;
for(j=1;j<=3;j++){
if(b[(a[i][j]-1)].getIcon()!=null){ //if 2
count++;
}
else{ yesnull=a[i][j]; }
}
if(count==2){
b[yesnull-1].setIcon(ic2);
this.check(yesnull); set=false;break;
}
}
else
if(a[i][0]==10){
for(j=1;j<=3;j++){ //for2
if(b[(a[i][j]-1)].getIcon()==null){ //if 1
b[(a[i][j]-1)].setIcon(ic2);
this.check(a[i][j]);
set=false;
break;
}
}
if(set==false)
break;
}

if(set==false)
break;
}
}

TTT1(){
super("tic tac toe by ashwani");

CheckboxGroup cbg=new CheckboxGroup();


c1=new Checkbox("vs computer",cbg,false);
c2=new Checkbox("vs friend",cbg,false);
c1.setBounds(120,80,100,40);
c2.setBounds(120,150,100,40);
add(c1); add(c2);
c1.addItemListener(this);
c2.addItemListener(this);

state=true;type=true;set=true;
ic1=new ImageIcon("ic1.jpg");
ic2=new ImageIcon("ic2.jpg");
ic11=new ImageIcon("ic11.jpg");
ic22=new ImageIcon("ic22.jpg");

setLayout(null);
setSize(330,450);
setVisible(true);
setDefaultCloseOperation(JFrame.DISPOSE_ON_
CLOSE);
}

public void itemStateChanged(ItemEvent e){


if(c1.getState())
{
type=false;
}

else if(c2.getState())
{ type=true;
}
remove(c1);remove(c2);
repaint(0,0,330,450);
showButton();
}

public void actionPerformed(ActionEvent e){

if(type==true)//logicfriend
{
if(e.getSource()==reset){
for(i=0;i<=8;i++){
b[i].setIcon(null);
} for
}
else{
for(i=0;i<=8;i++){
if(e.getSource()==b[i]){

if(b[i].getIcon()==null){
if(state==true){ icon=ic2;
state=false;} else{ icon=ic1; state=true; }
b[i].setIcon(icon);
}
}
}
}
}
else if(type==false){
if(e.getSource()==reset){
for(i=0;i<=8;i++){
b[i].setIcon(null);
}//eof for
for(i=0;i<=7;i++)
for(j=0;j<=4;j++)
a[i][j]=a1[i][j]; //again initialsing array
}
else{ //complogic
for(i=0;i<=8;i++){
if(e.getSource()==b[i]){
if(b[i].getIcon()==null){
b[i].setIcon(ic1);
if(b[4].getIcon()==null){
b[4].setIcon(ic2);
this.check(5);
} else{
this.complogic(i);
}
}
}
}
}
}
for(i=0;i<=7;i++){

Icon icon1=b[(a[i][1]-1)].getIcon();
Icon icon2=b[(a[i][2]-1)].getIcon();
Icon icon3=b[(a[i][3]-1)].getIcon();

if((icon1==icon2)&&(icon2==icon3)&&(icon1!=nu
ll)){
if(icon1==ic1){
b[(a[i][1]-1)].setIcon(ic11);
b[(a[i][2]-1)].setIcon(ic11);
b[(a[i][3]-1)].setIcon(ic11);

JOptionPane.showMessageDialog(TTT1.this,"!!!Y
OU won!!! click reset");
break;
}
else if(icon1==ic2){
b[(a[i][1]-1)].setIcon(ic22);
b[(a[i][2]-1)].setIcon(ic22);
b[(a[i][3]-1)].setIcon(ic22);

JOptionPane.showMessageDialog(TTT1.this,"wo
n! click reset");
break;
}
}
}

public static void main(String []args){


new TTT1();
}
}