//@SUDHIRTAWANIYA'S PRODUCTION
import java.awt.event.KeyEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
public class NewJFrame1 extends javax.swing.JFrame {
public NewJFrame1() {
initComponents();
B9.grabFocus();
I=9;
}
private void initComponents() {
b4 = new javax.swing.JButton();
b3 = new javax.swing.JButton();
b2 = new javax.swing.JButton();
b1 = new javax.swing.JButton();
b8 = new javax.swing.JButton();
b9 = new javax.swing.JButton();
b5 = new javax.swing.JButton();
b6 = new javax.swing.JButton();
B6 = new javax.swing.JButton();
b7 = new javax.swing.JButton();
B5 = new javax.swing.JButton();
B7 = new javax.swing.JButton();
B4 = new javax.swing.JButton();
B3 = new javax.swing.JButton();
B2 = new javax.swing.JButton();
B1 = new javax.swing.JButton();
B9 = new javax.swing.JButton();
B8 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("TAWANIYA's GAME");
getContentPane().setLayout(null);
b4.setContentAreaFilled(false);
getContentPane().add(b4);
b4.setBounds(950, 60, 60, 90);
b3.setContentAreaFilled(false);
b3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b3ActionPerformed(evt);
}
});
getContentPane().add(b3);
b3.setBounds(960, 290, 50, 110);
b2.setContentAreaFilled(false);
b2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b2ActionPerformed(evt);
}
});
b2.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
b2KeyPressed(evt);
}
});
getContentPane().add(b2);
b2.setBounds(940, 560, 70, 80);
b1.setContentAreaFilled(false);
b1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
b1KeyPressed(evt);
}
});
getContentPane().add(b1);
b1.setBounds(480, 560, 40, 80);
b8.setContentAreaFilled(false);
getContentPane().add(b8);
b8.setBounds(9, 560, 40, 80);
b9.setContentAreaFilled(false);
b9.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
b9KeyPressed(evt);
}
});
getContentPane().add(b9);
b9.setBounds(480, 300, 50, 100);
b5.setContentAreaFilled(false);
b5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b5ActionPerformed(evt);
}
});
getContentPane().add(b5);
b5.setBounds(470, 50, 70, 100);
b6.setContentAreaFilled(false);
getContentPane().add(b6);
b6.setBounds(0, 40, 40, 100);
B6.setContentAreaFilled(false);
B6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B6ActionPerformed(evt);
}
});
B6.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B6KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B6KeyReleased(evt);
}
});
getContentPane().add(B6);
B6.setBounds(0, 70, 70, 100);
b7.setContentAreaFilled(false);
b7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
b7ActionPerformed(evt);
}
});
getContentPane().add(b7);
b7.setBounds(10, 320, 30, 80);
B5.setContentAreaFilled(false);
B5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B5ActionPerformed(evt);
}
});
B5.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B5KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B5KeyReleased(evt);
}
});
getContentPane().add(B5);
B5.setBounds(460, 50, 80, 90);
B7.setContentAreaFilled(false);
B7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B7ActionPerformed(evt);
}
});
B7.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B7KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B7KeyReleased(evt);
}
});
getContentPane().add(B7);
B7.setBounds(10, 330, 70, 80);
B4.setContentAreaFilled(false);
B4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B4ActionPerformed(evt);
}
});
B4.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B4KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B4KeyReleased(evt);
}
});
getContentPane().add(B4);
B4.setBounds(920, 90, 73, 90);
B3.setContentAreaFilled(false);
B3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B3ActionPerformed(evt);
}
});
B3.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B3KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B3KeyReleased(evt);
}
});
getContentPane().add(B3);
B3.setBounds(910, 320, 90, 110);
B2.setContentAreaFilled(false);
B2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B2ActionPerformed(evt);
}
});
B2.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B2KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B2KeyReleased(evt);
}
});
getContentPane().add(B2);
B2.setBounds(920, 540, 79, 90);
B1.setContentAreaFilled(false);
B1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B1ActionPerformed(evt);
}
});
B1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B1KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B1KeyReleased(evt);
}
});
getContentPane().add(B1);
B1.setBounds(439, 540, 110, 90);
B9.setContentAreaFilled(false);
B9.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B9ActionPerformed(evt);
}
});
B9.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B9KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B9KeyReleased(evt);
}
});
getContentPane().add(B9);
B9.setBounds(450, 320, 100, 80);
B8.setContentAreaFilled(false);
B8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
B8ActionPerformed(evt);
}
});
B8.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyPressed(java.awt.event.KeyEvent evt) {
B8KeyPressed(evt);
}
public void keyReleased(java.awt.event.KeyEvent evt) {
B8KeyReleased(evt);
}
});
getContentPane().add(B8);
B8.setBounds(10, 560, 80, 70);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/TIGAA.jpg"))); // NOI18N
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jButton1.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
jButton1KeyReleased(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(0, 100, 1000, 536);
jButton2.setBackground(new java.awt.Color(51, 255, 153));
jButton2.setFont(new java.awt.Font("Verdana", 1, 24)); // NOI18N
jButton2.setForeground(new java.awt.Color(0, 204, 153));
jButton2.setText("TIGA");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(0, 0, 1000, 100);
pack();
}// </editor-fold>
int a[]={0,0,0,0,0,0,0,0,0};
int b=1;
static int c=1;
int d[]={0,0,0,0,0,0,0,0,0};
int e[]={0,0,0,0,0,0,0,0,0};
int f[]={0,0,0,0,0,0,0,0,0,0};
Icon m=new ImageIcon("C:\\Users\\USER\\Documents\\NetBeansProjects\\TIGAA\\src\\g2-removebg-preview.png");
Icon l=new ImageIcon("C:\\Users\\USER\\Documents\\NetBeansProjects\\TIGAA\\src\\l-removebg-preview.png");
Icon n=new ImageIcon("");
Icon N=new ImageIcon("C:\\Users\\USER\\Documents\\NetBeansProjects\\TIGAA\\src\\goti1.jpg");
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void b5ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void b7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void B1ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{
if(g==0)
{
if(d[0]==0)
{
if(b%2==1)
{
b1.setIcon(l);
b++;
a[0]=1;
}
else
{
b1.setIcon(m);
b++;
a[0]=2;
}
c++;
d[0]=1;
} else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[1]==1||e[0]==1)||(e[7]==1||e[8]==1))
{
if(d[0]==0)
{
if(b%2==1)
{
b1.setIcon(l);
b++;
a[0]=1;
}
else
{
b1.setIcon(m);
b++;
a[0]=2;
}
c++;
d[0]=1;
e[0]=0; e[8]=0; e[7]=0; e[1]=0;
} else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[7]==1 && d[1]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[0]==1)
{
if(b%2==1)
{
b1.setIcon(n);
c--;
e[0]=1;
d[0]=0;
e[0]=1;
a[0]=0;
} else{
nc();
}
}
else if(a[0]==2){
if(b%2!=1)
{
b1.setIcon(n);
c--;
e[0]=1;
d[0]=0;
a[0]=0;
}
else{
nc();
}
}
}
t();
} win();
}
private void B2ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{if(g==0)
{
if(d[1]==0)
{
if(b%2==1)
{
b2.setIcon(l);
b++;
a[1]=1;
}
else
{
b2.setIcon(m);
b++;
a[1]=2;
}
c++;
d[1]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[0]==1||e[1]==1)||(e[2]==1||e[8]==1))
{
if(d[1]==0)
{
if(b%2==1)
{
b2.setIcon(l);
b++;
a[1]=1;
}
else
{
b2.setIcon(m);
b++;
a[1]=2;
}
c++;
d[1]=1;
e[1]=0; e[8]=0; e[2]=0; e[0]=0;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[0]==1 && d[2]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[1]==1)
{
if(b%2==1)
{
b2.setIcon(n);
c--;
d[1]=0;
e[1]=1;
a[1]=0;
} else{
nc();
}
}
else if(a[1]==2){
if(b%2!=1)
{
b2.setIcon(n);
c--;
d[1]=0;
e[1]=1;
a[1]=0;
}
else{
nc();
}
}
}
t(); }win();
}
private void B3ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{
if(g==0)
{
if(d[2]==0)
{
if(b%2==1)
{
b3.setIcon(l);
b++;
a[2]=1;
}
else
{
b3.setIcon(m);
b++;
a[2]=2;
}
c++;
d[2]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[3]==1||e[2]==1)||(e[1]==1||e[8]==1))
{
if(d[2]==0)
{
if(b%2==1)
{
b3.setIcon(l);
b++;
a[2]=1;
}
else
{
b3.setIcon(m);
b++;
a[2]=2;
}
c++;
d[2]=1;
e[2]=0; e[8]=0; e[1]=0; e[3]=0; }
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(d[1]==1 && d[3]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(c==7)
{
if(a[2]==1)
{
if(b%2==1)
{
b3.setIcon(n);
c--;
e[2]=1;
d[2]=0;
a[2]=0;
} else{
nc();
}
}
else if(a[2]==2){
if(b%2!=1)
{
b3.setIcon(n);
e[2]=1;
c--;
d[2]=0;
a[2]=0;
}
else{
nc();
}
}
}
t(); }win();
}
private void B4ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{
if(g==0)
{
if(d[3]==0)
{
if(b%2==1)
{
b4.setIcon(l);
b++;
a[3]=1;
}
else
{
b4.setIcon(m);
b++;
a[3]=2;
}
c++;
d[3]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}}
else{
if((e[2]==1||e[3]==1)||(e[4]==1||e[8]==1))
{
if(d[3]==0)
{
if(b%2==1)
{
b4.setIcon(l);
b++;
a[3]=1;
}
else
{
b4.setIcon(m);
b++;
a[3]=2;
}
c++;
d[3]=1;
e[3]=0; e[8]=0; e[4]=0; e[2]=0;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[4]==1 && d[2]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[3]==1)
{
if(b%2==1)
{
b4.setIcon(n);
c--;
d[3]=0;
e[3]=1;
a[3]=0;
} else{
nc();
}
}
else if(a[3]==2){
if(b%2!=1)
{
b4.setIcon(n);
c--;
d[3]=0;
e[3]=1;
a[3]=0;
}
else{
nc();
}
}
}
t(); }win();
}
private void B5ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{
if(g==0)
{
if(d[4]==0)
{
if(b%2==1)
{
b5.setIcon(l);
b++;
a[4]=1;
}
else
{
b5.setIcon(m);
b++;
a[4]=2;
}
c++;
d[4]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[5]==1||e[4]==1)||(e[3]==1||e[8]==1))
{
if(d[4]==0)
{
if(b%2==1)
{
b5.setIcon(l);
b++;
a[4]=1;
}
else
{
b5.setIcon(m);
b++;
a[4]=2;
}
c++;
d[4]=1;
e[4]=0; e[5]=0; e[3]=0; e[8]=0;}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[5]==1 && d[3]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[4]==1)
{
if(b%2==1)
{
b5.setIcon(n);
c--;
e[4]=1;
d[4]=0;
a[4]=0;
} else{
nc();
}
}
else if(a[4]==2){
if(b%2!=1)
{
b5.setIcon(n);
c--;
e[4]=1;
d[4]=0;
a[4]=0;
}
else{
nc();
}
}
}
t(); }win();
}
private void B6ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{
if(g==0)
{
if(d[5]==0)
{
if(b%2==1)
{
b6.setIcon(l);
b++;
a[5]=1;
}
else
{
b6.setIcon(m);
b++;
a[5]=2;
}
c++;
d[5]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[4]==1||e[5]==1)||(e[6]==1||e[8]==1))
{
if(d[5]==0)
{
if(b%2==1)
{
b6.setIcon(l);
b++;
a[5]=1;
}
else
{
b6.setIcon(m);
b++;
a[5]=2;
}
c++;
d[5]=1;
e[5]=0;e[4]=0;e[6]=0;e[8]=0;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[4]==1 && d[6]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[5]==1)
{
if(b%2==1)
{
b6.setIcon(n);
c--;
e[5]=1;
d[5]=0;
a[5]=0;
} else{
nc();
}
}
else if(a[5]==2){
if(b%2!=1)
{
b6.setIcon(n);
c--;
e[5]=1;
d[5]=0;
a[5]=0;
}
else{
nc();
}
}
}
t();}win();
}
private void B7ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{
if(g==0)
{
if(d[6]==0)
{
if(b%2==1)
{
b7.setIcon(l);
b++;
a[6]=1;
}
else
{
b7.setIcon(m);
b++;
a[6]=2;
}
c++;
d[6]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[5]==1||e[6]==1)||(e[7]==1||e[8]==1))
{
if(d[6]==0)
{
if(b%2==1)
{
b7.setIcon(l);
b++;
a[6]=1;
}
else
{
b7.setIcon(m);
b++;
a[6]=2;
}
c++;
d[6]=1;
e[6]=0;
e[8]=0;e[7]=0;e[5]=0;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[7]==1 && d[5]==1 && d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[6]==1)
{
if(b%2==1)
{
b7.setIcon(n);
c--;
e[6]=1;
d[6]=0;
a[6]=0;
} else{
nc();
}
}
else if(a[6]==2){
if(b%2!=1)
{
b7.setIcon(n);
c--;
e[6]=1;
d[6]=0;
a[6]=0;
}
else{
nc();
}
}
}
t(); }win();
}
private void B8ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{
if(g==0)
{
if(d[7]==0)
{
if(b%2==1)
{
b8.setIcon(l);
b++;
a[7]=1;
}
else
{
b8.setIcon(m);
b++;
a[7]=2;
}
c++;
d[7]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[6]==1||e[7]==1)||(e[0]==1||e[8]==1))
{
if(d[7]==0)
{
if(b%2==1)
{
b8.setIcon(l);
b++;
a[7]=1;
}
else
{
b8.setIcon(m);
b++;
a[7]=2;
}
c++;
d[7]=1;
e[7]=0;
e[6]=0;e[0]=0;e[8]=0; }
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[6]==1 && d[0]==1 && d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[7]==1)
{
if(b%2==1)
{
b8.setIcon(n);
c--;
e[7]=1;
d[7]=0;
a[7]=0;
} else{
nc();
}
}
else if(a[7]==2){
if(b%2!=1)
{
b8.setIcon(n);
c--;
e[7]=1;
d[7]=0;
a[7]=0;
}
else{
nc();
}
}
}
t(); }win();
}
private void B9ActionPerformed(java.awt.event.ActionEvent evt) {
t();
if(c<=6)
{
if(d[8]==0)
{
if(b%2==1)
{
b9.setIcon(l);
b++;
a[8]=1;
e[8]=0;
for(int i=0;i<9;i++)
{
e[i]=0;
}
}
else
{
b9.setIcon(m);
b++;
a[8]=2;
e[8]=0;
for(int i=0;i<9;i++)
{
e[i]=0;
}
}
c++;
d[8]=1;
} else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else
{
if(c==7)
{
if(a[8]==1)
{
if(b%2==1)
{
b9.setIcon(n);
c--;
e[8]=1;
d[8]=0;
e[8]=1;
a[8]=0;
} else{
nc();
}
}
else if(a[8]==2){
if(b%2!=1)
{
b9.setIcon(n);
c--;
e[8]=1;
d[8]=0;
a[8]=0;
}
else{
nc();
}
}
}
t(); }win();
}
private void b9KeyPressed(java.awt.event.KeyEvent evt) {
}
private void b1KeyPressed(java.awt.event.KeyEvent evt) {
}
private void b2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void b2KeyPressed(java.awt.event.KeyEvent evt) {
}
private void b3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
int I=0;
private void B9KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_RIGHT)
{
B3.grabFocus();
I=3;
}
if(evt.getKeyCode()==KeyEvent.VK_LEFT)
{
B7.grabFocus();
I=7;
}
if(evt.getKeyCode()==KeyEvent.VK_UP)
{
B5.grabFocus();
I=5;
}
if(evt.getKeyCode()==KeyEvent.VK_DOWN)
{
B1.grabFocus();
I=1;
}
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{
if(d[8]==0)
{
if(b%2==1)
{
b9.setIcon(l);
b++;
a[8]=1;
e[8]=0;
for(int i=0;i<9;i++)
{
e[i]=0;
}
}
else
{
b9.setIcon(m);
b++;
a[8]=2;
e[8]=0;
for(int i=0;i<9;i++)
{
e[i]=0;
}
}
c++;
d[8]=1;
} else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else
{
if(c==7)
{
if(a[8]==1)
{
if(b%2==1)
{
b9.setIcon(n);
c--;
e[8]=1;
d[8]=0;
a[8]=0;
} else{
nc();
}
}
else if(a[8]==2){
if(b%2!=1)
{
b9.setIcon(n);
c--;
e[8]=1;
d[8]=0;
a[8]=0;
}
else{
nc();
}
}
}
t(); }win();
}
}
private void B1KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_UP)
{
B9.grabFocus();
I=9;
}
if(evt.getKeyCode()==KeyEvent.VK_RIGHT)
{
B2.grabFocus();
I=2;
}
if(evt.getKeyCode()==KeyEvent.VK_LEFT)
{
B8.grabFocus();
I=8;
}// TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{
if(g==0)
{
if(d[0]==0)
{
if(b%2==1)
{
b1.setIcon(l);
b++;
a[0]=1;
}
else
{
b1.setIcon(m);
b++;
a[0]=2;
}
c++;
d[0]=1;
} else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[1]==1||e[0]==1)||(e[7]==1||e[8]==1))
{
if(d[0]==0)
{
if(b%2==1)
{
b1.setIcon(l);
b++;
a[0]=1;
}
else
{
b1.setIcon(m);
b++;
a[0]=2;
}
c++;
d[0]=1;
e[0]=0; e[8]=0; e[7]=0; e[1]=0;
} else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[7]==1 && d[1]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[0]==1)
{
if(b%2==1)
{
b1.setIcon(n);
c--;
e[0]=1;
d[0]=0;
a[0]=0;
e[0]=1;
} else{
nc();
}
}
else if(a[0]==2){
if(b%2!=1)
{
b1.setIcon(n);
c--;
a[0]=0;
e[0]=1;
d[0]=0;
}
else{
nc();
}
}
}
t();
} win();
}
}
private void B2KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_LEFT)
{
B1.grabFocus();
I=1;
}
if(evt.getKeyCode()==KeyEvent.VK_UP)
{
B3.grabFocus();
I=3;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{if(g==0)
{
if(d[1]==0)
{
if(b%2==1)
{
b2.setIcon(l);
b++;
a[1]=1;
}
else
{
b2.setIcon(m);
b++;
a[1]=2;
}
c++;
d[1]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[0]==1||e[1]==1)||(e[2]==1||e[8]==1))
{
if(d[1]==0)
{
if(b%2==1)
{
b2.setIcon(l);
b++;
a[1]=1;
}
else
{
b2.setIcon(m);
b++;
a[1]=2;
}
c++;
d[1]=1;
e[1]=0; e[8]=0; e[2]=0; e[0]=0;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[0]==1 && d[2]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[1]==1)
{
if(b%2==1)
{
b2.setIcon(n);
c--;
d[1]=0;
e[1]=1;
a[1]=0;
} else{
nc();
}
}
else if(a[1]==2){
if(b%2!=1)
{
b2.setIcon(n);
c--;
d[1]=0;
e[1]=1;
a[1]=0;
}
else{
nc();
}
}
}
t(); }win();
}
}
private void B3KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_LEFT)
{
B9.grabFocus();
I=9;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_UP)
{
B4.grabFocus();
I=4;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_DOWN)
{
B2.grabFocus();
I=2;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{
if(g==0)
{
if(d[2]==0)
{
if(b%2==1)
{
b3.setIcon(l);
b++;
a[2]=1;
}
else
{
b3.setIcon(m);
b++;
a[2]=2;
}
c++;
d[2]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[3]==1||e[2]==1)||(e[1]==1||e[8]==1))
{
if(d[2]==0)
{
if(b%2==1)
{
b3.setIcon(l);
b++;
a[2]=1;
}
else
{
b3.setIcon(m);
b++;
a[2]=2;
}
c++;
d[2]=1;
e[2]=0; e[8]=0; e[1]=0; e[3]=0; }
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(d[1]==1 && d[3]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(c==7)
{
if(a[2]==1)
{
if(b%2==1)
{
b3.setIcon(n);
c--;
e[2]=1;
d[2]=0;
a[2]=0;
} else{
nc();
}
}
else if(a[2]==2){
if(b%2!=1)
{
b3.setIcon(n);
e[2]=1;
c--;
d[2]=0;
a[2]=0;
}
else{
nc();
}
}
}
t(); }win();
}
}
private void B5KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_DOWN)
{
B9.grabFocus();
I=9;
}
if(evt.getKeyCode()==KeyEvent.VK_LEFT)
{
B6.grabFocus();
I=6;
}
if(evt.getKeyCode()==KeyEvent.VK_RIGHT)
{
B4.grabFocus();
I=4;
}
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{
if(g==0)
{
if(d[4]==0)
{
if(b%2==1)
{
b5.setIcon(l);
b++;
a[4]=1;
}
else
{
b5.setIcon(m);
b++;
a[4]=2;
}
c++;
d[4]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[5]==1||e[4]==1)||(e[3]==1||e[8]==1))
{
if(d[4]==0)
{
if(b%2==1)
{
b5.setIcon(l);
b++;
a[4]=1;
}
else
{
b5.setIcon(m);
b++;
a[4]=2;
}
c++;
d[4]=1;
e[4]=0; e[5]=0; e[3]=0; e[8]=0;}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[5]==1 && d[3]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[4]==1)
{
if(b%2==1)
{
b5.setIcon(n);
c--;
e[4]=1;
d[4]=0;
a[4]=0;
} else{
nc();
}
}
else if(a[4]==2){
if(b%2!=1)
{
b5.setIcon(n);
c--;
e[4]=1;
d[4]=0;
a[4]=0;
}
else{
nc();
}
}
}
t(); }win();
}// TODO add your handling code here:// TODO add your handling code here:// TODO add your handling code here:
}
private void B6KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_RIGHT)
{
B5.grabFocus();
I=5;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_DOWN)
{
B7.grabFocus();
I=7;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{
if(g==0)
{
if(d[5]==0)
{
if(b%2==1)
{
b6.setIcon(l);
b++;
a[5]=1;
}
else
{
b6.setIcon(m);
b++;
a[5]=2;
}
c++;
d[5]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[4]==1||e[5]==1)||(e[6]==1||e[8]==1))
{
if(d[5]==0)
{
if(b%2==1)
{
b6.setIcon(l);
b++;
a[5]=1;
}
else
{
b6.setIcon(m);
b++;
a[5]=2;
}
c++;
d[5]=1;
e[5]=0;e[4]=0;e[6]=0;e[8]=0;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[4]==1 && d[6]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[5]==1)
{
if(b%2==1)
{
b6.setIcon(n);
c--;
e[5]=1;
d[5]=0;
a[5]=0;
} else{
nc();
}
}
else if(a[5]==2){
if(b%2!=1)
{
b6.setIcon(n);
c--;
e[5]=1;
d[5]=0;
a[5]=0;
}
else{
nc();
}
}
}
t();}win();
}
}
private void B7KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_UP)
{
B6.grabFocus();
I=6;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_DOWN)
{
B8.grabFocus();
I=8;
}
if(evt.getKeyCode()==KeyEvent.VK_RIGHT)
{
B9.grabFocus();
I=9;
}
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{
if(g==0)
{
if(d[6]==0)
{
if(b%2==1)
{
b7.setIcon(l);
b++;
a[6]=1;
}
else
{
b7.setIcon(m);
b++;
a[6]=2;
}
c++;
d[6]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[5]==1||e[6]==1)||(e[7]==1||e[8]==1))
{
if(d[6]==0)
{
if(b%2==1)
{
b7.setIcon(l);
b++;
a[6]=1;
}
else
{
b7.setIcon(m);
b++;
a[6]=2;
}
c++;
d[6]=1;
e[6]=0;
e[8]=0;e[7]=0;e[5]=0;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[7]==1 && d[5]==1 && d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[6]==1)
{
if(b%2==1)
{
b7.setIcon(n);
c--;
e[6]=1;
d[6]=0;
a[6]=0;
} else{
nc();
}
}
else if(a[6]==2){
if(b%2!=1)
{
b7.setIcon(n);
c--;
e[6]=1;
d[6]=0;
a[6]=0;
}
else{
nc();
}
}
}
t(); }win();
} // TODO add your handling code here:// TODO add your handling code here:
}
private void B8KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_UP)
{
B7.grabFocus();
I=7;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_RIGHT)
{
B1.grabFocus();
I=1;
}
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{
if(g==0)
{
if(d[7]==0)
{
if(b%2==1)
{
b8.setIcon(l);
b++;
a[7]=1;
}
else
{
b8.setIcon(m);
b++;
a[7]=2;
}
c++;
d[7]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
else{
if((e[6]==1||e[7]==1)||(e[0]==1||e[8]==1))
{
if(d[7]==0)
{
if(b%2==1)
{
b8.setIcon(l);
b++;
a[7]=1;
}
else
{
b8.setIcon(m);
b++;
a[7]=2;
}
c++;
d[7]=1;
e[7]=0;
e[6]=0;e[0]=0;e[8]=0; }
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[6]==1 && d[0]==1 && d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[7]==1)
{
if(b%2==1)
{
b8.setIcon(n);
c--;
e[7]=1;
d[7]=0;
a[7]=0;
} else{
nc();
}
}
else if(a[7]==2){
if(b%2!=1)
{
b8.setIcon(n);
c--;
e[7]=1;
d[7]=0;
a[7]=0;
}
else{
nc();
}
}
}
t(); }win();
} // TODO add your handling code here:// TODO add your handling code here:
}
private void B4KeyPressed(java.awt.event.KeyEvent evt) {
if(evt.getKeyCode()==KeyEvent.VK_DOWN)
{
B3.grabFocus();
I=3;
} // TODO add your handling code here:
if(evt.getKeyCode()==KeyEvent.VK_LEFT)
{
B5.grabFocus();
I=5;
}
if(evt.getKeyCode()==KeyEvent.VK_ENTER)
{
t();
if(c<=6)
{
if(g==0)
{
if(d[3]==0)
{
if(b%2==1)
{
b4.setIcon(l);
b++;
a[3]=1;
}
else
{
b4.setIcon(m);
b++;
a[3]=2;
}
c++;
d[3]=1;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}}
else{
if((e[2]==1||e[3]==1)||(e[4]==1||e[8]==1))
{
if(d[3]==0)
{
if(b%2==1)
{
b4.setIcon(l);
b++;
a[3]=1;
}
else
{
b4.setIcon(m);
b++;
a[3]=2;
}
c++;
d[3]=1;
e[3]=0; e[8]=0; e[4]=0; e[2]=0;
}
else{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER OLREADY EXITS");
}
}
}
}
else
{
if(c==7)
{
if(d[4]==1 && d[2]==1&& d[8]==1){
JOptionPane.showMessageDialog(NewJFrame1.this,"LOCKED");
}
else if(a[3]==1)
{
if(b%2==1)
{
b4.setIcon(n);
c--;
d[3]=0;
e[3]=1;
a[3]=0;
} else{
nc();
}
}
else if(a[3]==2){
if(b%2!=1)
{
b4.setIcon(n);
c--;
d[3]=0;
e[3]=1;
a[3]=0;
}
else{
nc();
}
}
}
t(); }win();
} // TODO add your handling code here:// TODO add your handling code here:
}
public void she()
{
B1.setIcon(n);
B2.setIcon(n);
B3.setIcon(n);
B4.setIcon(n);
B5.setIcon(n);
B6.setIcon(n);
B7.setIcon(n);
B8.setIcon(n);
B9.setIcon(n);
}
private void B9KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==9)
{
B9.setIcon(N);
}
}
private void B8KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==8)
{
B8.setIcon(N);
}// TODO add your handling code here:
}
private void jButton1KeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
}
private void B7KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==7)
{
B7.setIcon(N);
} // TODO add your handling code here:
}
private void B6KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==6)
{
B6.setIcon(N);
} // TODO add your handling code here:
}
private void B5KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==5)
{
B5.setIcon(N);
} // TODO add your handling code here:
}
private void B4KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==4)
{
B4.setIcon(N);
} // TODO add your handling code here:
}
private void B3KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==3)
{
B3.setIcon(N);
} // TODO add your handling code here:
}
private void B2KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==2)
{
B2.setIcon(N);
} // TODO add your handling code here:
}
private void B1KeyReleased(java.awt.event.KeyEvent evt) {
she();
if(I==1)
{
B1.setIcon(N);
} // TODO add your handling code here:
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
new NewJFrame().setVisible(true);
JButton s=b9;
new NewJFrame1().setVisible(false);
// TODO add your handling code here:
}
public void nc()
{
JOptionPane.showMessageDialog(NewJFrame1.this,"NOT YOUR CHANCE");
}
static int g=0;
public void t()
{
if(c==7)
{
g=1;
}
}
public void win()
{
if(a[4]==a[8]&&a[8]==a[0]&&a[8]!=0)
{
if(a[4]==1)
{
winner1();
}
if(a[4]==2)
{
winner2();
}
}
if(a[5]==a[8]&&a[1]==a[8]&&a[8]!=0)
{
if(a[8]==1)
{
winner1();
}
if(a[8]==2)
{
winner2();
}
}
if(a[3]==a[8]&&a[8]==a[7]&&a[8]!=0)
{
if(a[8]==1)
{
winner1();
}
if(a[8]==2)
{
winner2();
}
}
if(a[6]==a[8]&&a[2]==a[6]&&a[8]!=0)
{
if(a[6]==1)
{
winner1();
}
if(a[6]==2)
{
winner2();
}
}
if(a[5]==a[6]&&a[7]==a[6]&&a[6]!=0)
{
if(a[5]==1)
{
winner1();
}
if(a[5]==2)
{
winner2();
}
}
if(a[4]==a[5]&&a[3]==a[5]&&a[5]!=0)
{
if(a[3]==1)
{
winner1();
}
if(a[3]==2)
{
winner2();
}
}
if(a[3]==a[2]&&a[1]==a[3]&&a[3]!=0)
{
if(a[3]==1)
{
winner1();
}
if(a[3]==2)
{
winner2();
}
}
if(a[7]==a[0]&&a[1]==a[0]&&a[1]!=0)
{
if(a[7]==1)
{
winner1();
}
if(a[7]==2)
{
winner2();
}
}
}
public void winner1()
{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER 1 WIN");
reset();
}
public void winner2()
{
JOptionPane.showMessageDialog(NewJFrame1.this,"PLAYER 2 WIN");
reset();
}
public void reset()
{
for(int k=0;k<9;k++)
{
a[k]=0;
d[k]=0;
e[k]=0;
f[k]=0;
}
b=1;
c=1;
g=0;
b1.setIcon(n);
b2.setIcon(n);
b3.setIcon(n);
b4.setIcon(n);
b5.setIcon(n);
b6.setIcon(n);
b7.setIcon(n);
b8.setIcon(n);
b9.setIcon(n);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
NewJFrame1 r=new NewJFrame1();
r.setSize(1003,667);
new NewJFrame1().setVisible(false);
r.setVisible(true);
r.setResizable(false);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton B1;
private javax.swing.JButton B2;
private javax.swing.JButton B3;
private javax.swing.JButton B4;
private javax.swing.JButton B5;
private javax.swing.JButton B6;
private javax.swing.JButton B7;
private javax.swing.JButton B8;
private javax.swing.JButton B9;
private javax.swing.JButton b1;
private javax.swing.JButton b2;
private javax.swing.JButton b3;
private javax.swing.JButton b4;
private javax.swing.JButton b5;
private javax.swing.JButton b6;
private javax.swing.JButton b7;
private javax.swing.JButton b8;
private javax.swing.JButton b9;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
// End of variables declaration
}
Comments
Post a Comment