Vous êtes sur la page 1sur 5

http://classroom.google.

com/u/0/c/Mjc1MDU5NjY5MzVa

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package vn.hust.carochess;

import java.awt.Color;
import java.awt.Point;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.border.LineBorder;

/**
*
* @author phand
*/
public class CaroClient extends javax.swing.JFrame {
String host;
boolean startUser=true;
private int X0=20;
private int Y0=20;
private int Width=32;
private int Size=15;
private int currentColum=-1;
private int currentRow=-1;
private Point currentPoint = new Point();

private boolean user = false; //true: vi tri chan luu cac diem da danh cua
user1, false: vi tri le luu cac diem da danh cua user2

private Vector<Point> checked = new Vector<Point>();


PlayNow mySelf;
PlayNow you;
Socket socket=null;
ObjectInputStream in = null;
ObjectOutputStream out = null;
Socket socketGame = null;
ObjectInputStream ingame = null;
ObjectOutputStream outgame = null;
boolean isPause=true; //true: quan den di truoc, false: quan do di truoc
/**
* Creates new form JFrameBoard
*/
public CaroClient() {
initComponents();
host = JOptionPane.showInputDialog("Nhap host","");
mySelf = new PlayNow(myselfPanel);
you = new PlayNow(youPanel);
mySelf.start();
you.start();
mySelf.suspend();
class Listen extends Thread{
public Listen(){
start();

}
@Override
public void run(){
listenSocket();
}
}
new Listen();
class ListenGame extends Thread{
public ListenGame(){
start();
}

public void run(){


listenSocket();
}
}
}

/**
* 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.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

BoardPanel = new javax.swing.JPanel();


myselfPanel = new javax.swing.JPanel();
youPanel = new javax.swing.JPanel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

BoardPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new
java.awt.Color(0, 0, 0)));

javax.swing.GroupLayout BoardPanelLayout = new


javax.swing.GroupLayout(BoardPanel);
BoardPanel.setLayout(BoardPanelLayout);
BoardPanelLayout.setHorizontalGroup(

BoardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 488, Short.MAX_VALUE)
);
BoardPanelLayout.setVerticalGroup(

BoardPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 0, Short.MAX_VALUE)
);

javax.swing.GroupLayout myselfPanelLayout = new


javax.swing.GroupLayout(myselfPanel);
myselfPanel.setLayout(myselfPanelLayout);
myselfPanelLayout.setHorizontalGroup(

myselfPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
myselfPanelLayout.setVerticalGroup(

myselfPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);

javax.swing.GroupLayout youPanelLayout = new


javax.swing.GroupLayout(youPanel);
youPanel.setLayout(youPanelLayout);
youPanelLayout.setHorizontalGroup(

youPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
youPanelLayout.setVerticalGroup(

youPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(BoardPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(18, 18, 18)
.addComponent(myselfPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(youPanel, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(BoardPanel, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(youPanel,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(myselfPanel,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 271, Short.MAX_VALUE)))
.addContainerGap())
);

pack();
}// </editor-fold>
public void listenSocket(){

}
/**
* @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(CaroClient.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(CaroClient.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(CaroClient.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(CaroClient.class.getName()).log(java.util.loggin
g.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new CaroClient().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JPanel BoardPanel;
private javax.swing.JPanel myselfPanel;
private javax.swing.JPanel youPanel;
// End of variables declaration
}

Vous aimerez peut-être aussi