Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Agarwal Public School

Section: 2017-18

Computer Project

Submitted by:
Submitted to:
Nikhil Wadhwani Sir
Virendra
Class: 11th A
Mishra
Acknowledgement

I would like to express my gratitude


towards our Principal Mrs Vandana
Ojha, who had given me such great
curriculum to study at

I would also like to thank my subject


teacher Sir Virendra Mishra who has
been a great support during the
completion of the project.
Last but not the least, I want to thank
my friends and family who helped me in
the project.
Certificate

This is to certified that NIKHIL


WADHWANI of Class 11thA has
successfully completed the project
work of Informatics Practices.
It is further certified that this
project is individual work of
candidate.

Teacher’s Sign Principal’s Sign School Seal


Introduction to netbeans
NetBeans is an open-source project dedicated to providing rock
solid software development products (the NetBeans IDE and
the NetBeans Platform) that address the needs of developers,
users and the businesses who rely on NetBeans as a basis for
their products; particularly, to enable them to develop these
products quickly, efficiently and easily by leveraging the
strengths of the Java platform and other relevant industry
standards.
In June 2000, NetBeans was made open source by Sun
Microsystems, which remained the project sponsor until
January 2010 when Sun Microsystems became a subsidiary of
Oracle. Please see our History section for more information.
The two base products, the NetBeans IDE and NetBeans
Platform, are free for commercial and non-commercial use.
The source code to both is available to anyone to reuse as they
see fit, within the terms of use. The legal sectioncontains
information regarding licensing, copyright issues, privacy policy
and terms of use.
The NetBeans project is also a vibrant community in which
people from across the globe can ask questions, give
advice, contribute and ultimately share in the success of our
products. On the NetBeans mailing lists and forums, you will
find posts from students, developers from top companies, and
individuals looking to expand their skills.
With over 18 million downloads of the NetBeans IDE to date,
and over 800,000 participating developers, the NetBeans
project is thriving and continues to grow, thanks to the
individuals and partner companies. To be a part of the
community, simply register for free.

Introduction to Project

Cross n Knot is a two player game. The aim of the application is to allow
the players to decide on the position where they want to place the
symbol (in our case cross for player one and knot for player two by
default) one by one in a 3 x 3 grid. So the first thing we should have on
the form is 9 text fields with suitable labels for placing the symbols. Note
that these text fields should be disabled so that they just display the
position without being edited.
The game starts with Player 1 and he has to decide on the position
where he wants to place the cross. He will enter this input in a text field
and similarly player 2 needs to enter his position in a text field. So the
next thing we need to have on the form is 2 text fields to accept the
inputs of Player 1 and Player 2 respectively. Note that the Labels against
the text fields are necessary as they help in identifying the position
where the player is going to place the symbol (cross or knot).
After the player decides on the input he should click on a button to place
the symbol in the appropriate position and transfer the turn to the other
player. To achieve this we should have two buttons, one for each player.
Apart from these controls we need to have two more buttons - first for
restarting the game and second for ending the application.
The game continues till all the text fields are filled .To avoid confusion,
when Player 1 is playing, only his controls have to be enabled and the
controls of Player 2 have to be disabled. As soon as Player 1 finishes his
turn by clicking on the button, the controls of
Player 1 should be disabled and the controls for the Player 2 should be
enabled.
Exit button as
jbutton 3

Textfield as t10

Textfield as t11

Replay button
as t11
t1,t2,t3,t4,t5,t6,t7,t8,t9
respectively

Player 2 as t11

t11

Player 1 as t10
THE CODING FOR GIVEN PROGRAM IS :
Coding for replay button is as follows:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {

t1.setText("1");

t2.setText("2");

t3.setText("3");

t4.setText("4");

t5.setText("5");

t6.setText("6");

t7.setText("7");

t8.setText("8");

t9.setText("9");

t10.setEditable(true);

t11.setEditable(false);

jbutton1.setEnabled(true);

jbutton2.setEnabled(false);

Coding for Player 1 button is as follows:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {

int Input1;

Input1 = Integer.parseInt(t10.getText());

if (Input1<1 || Input1>9)

JOptionPane.showMessageDialog

(this,"Enter a Valid Position (1..9)");

else

if ((Input1==1 && t1.getText().equals("1")) ||


(Input1==2 && t2.getText().equals("2")) ||

(Input1==3 && t3.getText().equals("3")) ||

(Input1==4 && t4.getText().equals("4")) ||

(Input1==5 && t5.getText().equals("5")) ||

(Input1==6 && t6.getText().equals("6")) ||

(Input1==7 && t7.getText().equals("7")) ||

(Input1==8 && t8.getText().equals("8")) ||

(Input1==9 && t9.getText().equals("9"))

){

switch (Input1)

case 1:t1.setText("X");break;

case 2:t2.setText("X");break;

case 3:t3.setText("X");break;

case 4:t4.setText("X");break;

case 5:t5.setText("X");break;

case 6:t6.setText("X");break;

case 7:t7.setText("X");break;

case 8:t8.setText("X");break;

case 9:t9.setText("X");break;

if ((t1.getText().equals("X") &&

t2.getText().equals("X") &&

t3.getText().equals("X"))||

(t4.getText().equals("X") &&

t5.getText().equals("X") &&

t6.getText().equals("X"))||

(t7.getText().equals("X") &&

t8.getText().equals("X") &&

t9.getText().equals("X"))||

(t1.getText().equals("X") &&

t4.getText().equals("X") &&

t7.getText().equals("X"))||
(t2.getText().equals("X") &&

t5.getText().equals("X") &&

t8.getText().equals("X"))||

(t3.getText().equals("X") &&

t6.getText().equals("X") &&

t9.getText().equals("X"))||

(t1.getText().equals("X") &&

t5.getText().equals("X") &&

t9.getText().equals("X"))||

(t3.getText().equals("X") &&

t5.getText().equals("X") &&

t7.getText().equals("X"))

JOptionPane.showMessageDialog(this,"Player 1 Wins");

else

if ( !t1.getText().equals("1") &&

!t2.getText().equals("2") &&

!t3.getText().equals("3") &&

!t4.getText().equals("4") &&

!t5.getText().equals("5") &&

!t6.getText().equals("6") &&

!t7.getText().equals("7") &&

!t8.getText().equals("8") &&

!t9.getText().equals("9"))

JOptionPane.showMessageDialog(this,"It is a DRAW...");

else

t11.setEditable(true);

jButton1.setEnabled(false);

jButton2.setEnabled(true);

t10.setEditable(false);

else

JOptionPane.showMessageDialog
(this,"Already Occupied Option RE-ENTER (1..9)");

t10.setText("");

Coding for Player 2 button is as follows:


private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {

int Input2;

Input2 = Integer.parseInt(t11.getText());

if (Input2<1 || Input2>9)

JOptionPane.showMessageDialog

(this,"Enter a Valid Position (1..9)");

else

if ((Input2==1 && t1.getText().equals("1")) ||

(Input2==2 && t2.getText().equals("2")) ||

(Input2==3 && t3.getText().equals("3")) ||

(Input2==4 && t4.getText().equals("4")) ||

(Input2==5 && t5.getText().equals("5")) ||

(Input2==6 && t6.getText().equals("6")) ||

(Input2==7 && t7.getText().equals("7")) ||

(Input2==8 && t8.getText().equals("8")) ||

(Input2==9 && t9.getText().equals("9"))

){

switch (Input2)

case 1:t1.setText("O");break;

case 2:t2.setText("O");break;

case 3:t3.setText("O");break;

case 4:t4.setText("O");break;

case 5:t5.setText("O");break;

case 6:t6.setText("O");break;
case 7:t7.setText("O");break;

case 8:t8.setText("O");break;

case 9:t9.setText("O");break;

if ((t1.getText().equals("O") &&

t2.getText().equals("O") &&

t3.getText().equals("O"))||

(t4.getText().equals("O") &&

t5.getText().equals("O") &&

t6.getText().equals("O"))||

(t7.getText().equals("O") &&

t8.getText().equals("O") &&

t9.getText().equals("O"))||

(t1.getText().equals("O") &&

t4.getText().equals("O") &&

t7.getText().equals("O"))||

(t2.getText().equals("O") &&

t5.getText().equals("O") &&

t8.getText().equals("O"))||

(t3.getText().equals("O") &&

t6.getText().equals("O") &&

t9.getText().equals("O"))||

(t1.getText().equals("O") &&

t5.getText().equals("O") &&

t9.getText().equals("O"))||

(t3.getText().equals("O") &&

t5.getText().equals("O") &&

t7.getText().equals("O"))

JOptionPane.showMessageDialog(this,"Player 2 Wins");

else
if ( !t1.getText().equals("1") &&

!t2.getText().equals("2") &&

!t3.getText().equals("3") &&

!t4.getText().equals("4") &&

!t5.getText().equals("5") &&

!t6.getText().equals("6") &&

!t7.getText().equals("7") &&

!t8.getText().equals("8") &&

!t9.getText().equals("9"))

JOptionPane.showMessageDialog(this,"It is a DRAW...");

else

t10.setEditable(true);

jButton2.setEnabled(false);

jButton1.setEnabled(true);

t11.setEditable(false);

else

JOptionPane.showMessageDialog

(this,"Already Occupied Option RE-ENTER (1..9)");

t11.setText(""); // TODO add your handling code here:

Coding for exit button is as follows:

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {

System.exit(0);

You might also like