Answer» So my project is due tomorrow and I'm not sure (Actually I have no idea) what's wrong with it, it's all working good except somehow the if conditions are wrong because it NEVER sets text in the jlabel to say win, here's the code
Server main Code: [Select]/* * Main.java * * Created on November 10, 2010, 10:57 PM * * To change this template, choose Tools | Template Manager * and OPEN the template in the editor. */
package server;
/** * * @author Jamaica */ public class Main { public static void main(STRING args[]) { final serverFrame b=new serverFrame(); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { b.setVisible(true); } }); b.recieve(); }
} Server frame Code: [Select]/* * serverFrame.java * * Created on November 10, 2010, 9:53 PM */
package finalserver;
import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.ServerSocket; import java.net.Socket;
/** * * @author essam * */ public class serverFrame extends javax.swing.JFrame { int x; ServerSocket ss=null; Socket s1=null; ObjectOutputStream out=null; ObjectInputStream in=null; String msg=null; /** Creates new form serverFrame */ public serverFrame() { initComponents(); try { ss=new ServerSocket(2000); s1=ss.accept(); out=new ObjectOutputStream(s1.getOutputStream()); in=new ObjectInputStream(s1.getInputStream()); } catch (IOException ex) { ex.printStackTrace(); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() {
jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });
jButton2.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });
jButton3.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } });
jButton4.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } });
jButton5.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } });
jButton6.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } });
jButton7.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } });
jButton8.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } });
jButton9.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } });
jLabel2.addComponentListener(new java.awt.event.ComponentAdapter() { public void componentShown(java.awt.event.ComponentEvent evt) { jLabel2ComponentShown(evt); } });
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE) .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, 98, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE) .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 115, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE) .addComponent(jButton6, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)) .addContainerGap()) .addGroup(layout.createSequentialGroup() .addGap(46, 46, 46) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 248, Short.MAX_VALUE) .addGap(54, 54, 54)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 79, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 80, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 61, Short.MAX_VALUE) .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)) );
pack(); }// </editor-fold> private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton9.setText("O"); jButton9.setEnabled(false); x=1; send("9"); } } private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton8.setText("O"); jButton8.setEnabled(false); x=1; send("8"); } } private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton7.setText("O"); jButton7.setEnabled(false); x=1; send("7"); } } private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton6.setText("O"); jButton6.setEnabled(false); x=1; send("6"); } } private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton5.setText("O"); jButton5.setEnabled(false); x=1; send("5"); } } private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton4.setText("O"); jButton4.setEnabled(false); x=1; send("4"); } } private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton3.setText("O"); jButton3.setEnabled(false); x=1; send("3"); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton2.setText("O"); jButton2.setEnabled(false); x=1; send("2"); }// TODO add your handling code here: } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { if (x==0){ jButton1.setText("O"); jButton1.setEnabled(false); x=1; send("1"); } }
private void jLabel2ComponentShown(java.awt.event.ComponentEvent evt) { // TODO add your handling code here: } public void send(String x){ try { out.writeObject(x); } catch (IOException ex) { ex.printStackTrace(); } } public void recieve(){ while (true){ try { msg=(String) in.readObject(); check(msg); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } } public void check(String y){ if (y.equals("1")){ jButton1.setText("X"); jButton1.setEnabled(false); x=0; } if (y.equals("2")){ jButton2.setText("X"); jButton2.setEnabled(false); x=0; } if (y.equals("3")){ jButton3.setText("X"); jButton3.setEnabled(false); x=0; } if (y.equals("4")){ jButton4.setText("X"); jButton4.setEnabled(false); x=0; } if (y.equals("5")){ jButton5.setText("X"); jButton5.setEnabled(false); x=0; } if (y.equals("6")){ jButton6.setText("X"); jButton6.setEnabled(false); x=0; } if (y.equals("7")){ jButton7.setText("X"); jButton7.setEnabled(false); x=0; } if (y.equals("8")){ jButton8.setText("X"); jButton8.setEnabled(false); x=0; } if (y.equals("9")){ jButton9.setText("X"); jButton9.setEnabled(false); x=0; } } public void cwin(){ if(jButton1.getText().equals(jButton2.getText()) && jButton3.getText().equals(jButton1.getText())&&jButton1.getText().equals("o")) { jLabel2.setText("You win"); CLOSE(); } else if(jButton4.getText().equals(jButton5.getText()) && jButton4.getText().equals(jButton6.getText()) && jButton4.getText().equals("O")) { jLabel2.setText("You win"); close(); } else if(jButton7.getText().equals(jButton8.getText()) && jButton7.getText().equals(jButton9.getText()) && jButton7.getText().equals("O")) { jLabel2.setText("You win"); close(); } else if(jButton1.getText().equals(jButton4.getText()) && jButton1.getText().equals(jButton7.getText()) && jButton1.getText().equals("O")) { jLabel2.setText("You win"); close(); } else if(jButton2.getText().equals(jButton5.getText()) && jButton2.getText().equals(jButton8.getText()) && jButton2.getText().equals("O")) { jLabel2.setText("You win"); close(); } else if(jButton4.getText().equals(jButton5.getText()) && jButton4.getText().equals(jButton6.getText()) && jButton4.getText().equals("O")) { jLabel2.setText("You win"); close(); } else if(jButton3.getText().equals(jButton6.getText()) && jButton3.getText().equals(jButton9.getText()) && jButton3.getText().equals("O")) { jLabel2.setText("You win"); close(); } else if(jButton1.getText().equals(jButton5.getText()) && jButton1.getText().equals(jButton9.getText()) && jButton1.getText().equals("O")) { jLabel2.setText("You win"); close(); } else if(jButton4.getText().equals(jButton5.getText()) && jButton4.getText().equals(jButton6.getText()) && jButton4.getText().equals("O")){ jLabel2.setText("You Win"); close();
} else if(jButton3.getText().equals(jButton5.getText()) && jButton3.getText().equals(jButton7.getText()) && jButton3.getText().equals("O")) { jLabel2.setText("You win"); close();
} } private void close() { throw new UnsupportedOperationException("Not yet implemented"); } private void sendmassege(String string) { throw new UnsupportedOperationException("Not yet implemented"); } /** * @param args the command line arguments */ // Variables declaration - do not modify private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JButton jButton3; private javax.swing.JButton jButton4; private javax.swing.JButton jButton5; private javax.swing.JButton jButton6; private javax.swing.JButton jButton7; private javax.swing.JButton jButton8; private javax.swing.JButton jButton9; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; // End of variables declaration }
Client main Code: [Select]/* * Main.java * * Created on November 10, 2010, 10:56 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */
package client;
/** * * @author Jamaica * */ public class Main { public static void main(String args[]) { final clientFrame c=new clientFrame(); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { c.setVisible(true); } }); c.recieve(); }
/** Creates a new instance of Main */ }
Client's frame [code] /* * clientFrame.java * * Created on November 10, 2010, 9:53 PM */
package client;
import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.Socket; import java.net.UnknownHostException;
/** * * @author essam */ public class clientFrame extends javax.swing.JFrame { int X; Socket s1=null; ObjectOutputStream out=null; ObjectInputStream in=null; String msg=null; public clientFrame() { initComponents(); try { s1=new Socket("localhost",2000); out=new ObjectOutputStream(s1.getOutputStream()); in=new ObjectInputStream(s1.getInputStream()); } catch (UnknownHostException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // private void initComponents() {
jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); jButton5 = new javax.swing.JButton(); jButton6 = new javax.swing.JButton(); jButton7 = new javax.swing.JButton(); jButton8 = new javax.swing.JButton(); jButton9 = new javax.swing.JButton(); jLabel1 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLO SE);
jButton1.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } });
jButton2.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } });
jButton3.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } });
jButton4.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } });
jButton5.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton5.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton5ActionPerformed(evt); } });
jButton6.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton6.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton6ActionPerformed(evt); } });
jButton7.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton7.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton7ActionPerformed(evt); } });
jButton8.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton8.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton8ActionPerformed(evt); } });
jButton9.setFont(new java.awt.Font("Tahoma", 1, 24)); jButton9.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton9ActionPerformed(evt); } });
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG, false) .addGroup(layout.createSequentialGroup() .addGap(10, 10, 10) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 113, Short.MAX_VALUE)) .addGap(10, 10, 10) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addGroup(javax.swing.GroupLayout.Alignment.TRAIL ING, layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addComponent(jButton8, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE) .addComponent(jButton5, javax.swing.GroupLayout.Alignment.TRAIL ING, javax.swing.GroupLayout.DEFAULT_SIZE, 110, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE) .addComponent(jButton9, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE))) .addGroup(layout.createSequentialGroup() .addGap(21, 21, 21) .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE) .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE) .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE) .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE) .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, 75, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.RELATED) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI NG) .addGroup(layout.createSequentialGroup() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAIL ING, false) .addComponent(jButton8, javax.swing.GroupLayout.Alignment.LEADI NG, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(jButton9, javax.swing.GroupLayout.Alignment.LEADI NG, javax.swing.GroupLayout.DEFAULT_SIZE, 83, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.RELATED) .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 53, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addComponent(jButton7, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacem ent.UNRELATED) .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE) .addContainerGap()))) );
pack(); }//
private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton9.setText("X"); jButton9.setEnabled(false); X=1; send("9"); } }
private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton8.setText("X"); jButton8.setEnabled(false); X=1; send("8"); } }
private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton7.setText("X"); jButton7.setEnabled(false); X=1; send("7"); } }
private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton6.setText("X"); jButton6.setEnabled(false); X=1; send("6"); } }
private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton5.setText("X"); jButton5.setEnabled(false); X=1; send("5"); } }
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton4.setText("X"); jButton4.setEnabled(false); X=1; send("4"); } }
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton3.setText("X"); jButton3.setEnabled(false); X=1; send("3"); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton2.setText("X"); jButton2.setEnabled(false); X=1; send("2"); } } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { if (X==0){ jButton1.setText("X"); jButton1.setEnabled(false); X=1; send("1"); } } public void send(String X){ try { out.writeObject(X); } catch (IOException ex) { ex.printStackTrace(); } } public void recieve(){ while (true){ try { msg=(String) in.readObject(); check(msg); } catch (ClassNotFoundException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } } public void check(String B){ if(B.equals("1")){ jButton1.setText("O"); jButton1.setEnabled(false); X=0; } if(B.equals("2")){ jButton2.setText("O"); jButton2.setEnabled(false); X=0; } if(B.equals("3")){ jButton3.setText("O"); jButton3.setEnabled(false); X=0; } if(B.equals("4")){ jButton4.setText("O"); jButton4.setEnabled(false); X=0; } if(B.equals("5")){ jButton5.setText("O"); jButton5.setEnabled(false); X=0; } if(B.equals("6")){ jButton6.setText("O"); jButton6.setEnabled(false); X=0; } if(B.equals("7")){ jButton7.setText("O"); jButton7.setEnabled(false); X=0; } if(B.equals("8")){ jButton8.setText("O"); jButton8.setEnabled(false); X=0; } if(B.equals("9")){ jButton9.setText("O"); jButton9.setEnabled(false); X=0; } } public void cwin(){ if(jButton1.getText().equals(jButton2.getText()) && jButton1.getText().equals(jButton3.getText()) && jButton1.getText().equals("X")) { jLabel1.setText("You win"); sendmessage("You lose"); close(); } if(jButton4.getText().equals(jButton5.getText()) && jButton4.getText().equals(jButton6.getText()) && jButton4.getText().equals("X")) { jLabel1.setText("You win"); sendmessage("You lose"); close(); } else if(jButton7.getText().equals(jButton8.getText()) && jButton7.getText().equals(jButton9.getText()) && jButton7.getText().equals("X")) { jLabel1.setText("You win"); sendmessage("You lose"); close(); } else if(jButton1.getText().equals(jButton4.getText()) && jButton1.getText().equals(jButton7.getText()) && jButton1.getText().equals("X")) { jLabel1.setText("You win"); sendmessage("You lose"); close(); } else if(jButton2.getText().equals(jButton5.getText()) && jButton2.getText().equals(jButton8.getText()) && jButton2.getText().equals("X"))
{ jLabel1.setText("You win"); sendmessage("You lose"); close(); } else if(jButton4.getText().equals(jButton5.getText()) && jButton4.getText().equals(jButton6.getText()) && jButton4.getText().equals("X")) { jLabel1.setText("You win"); sendmessage("You lose"); close(); } else if(jButton3.getText().equals(jButton6.getText()) && jButton3.getText().equals(jButton9.getText()) && jButton3.getText().equals("X")) { jLabel1.setText("You win"); sendmessage("You lose"); close(); } else if(jButton1.getText().equals(jButton5.getText()) && jButton1.getText().equals(jButton9.getText()) && jButton1.getText().equals("X"))
{ jLabel1.setText("You win"); sendmessage("You lose"); close(); }
else if(jButton4.getText().equals(jButton5.getText()) && jButton4.getText().equals(jButton6.getText()) && jButton4.getText().equals("X")){ jLabel1.setText("You Win"); sendmessage("You lose");
close(); } else if(jButton3.getText().equals(jButton5.getText()) && jButton3.getText().equals(jButton7.getText()) && jButton3.getText().equals("X")){ jLabel1.setText("You Win"); sendmessage("You lose");
close();
}
} private void sendmessage(String string) { throw new UnsupportedOperationException("Not yet iQuote Code: [Select]if(jButton1.getText().equals(jButton2.getText()) && jButton3.getText().equals(jButton1.getText())&&jButton1.getText().equals("o")) {
The last condition is checking wether it's equal to "o" but you have been setting them to "O" (capitalized).
|