자바 오목 네트워크 버 전 실현
수요 분석:
인터넷 오목 의 경우 일반 오목 을 바탕 으로 다음 과 같은 기능 을 추가 해 야 한다.
1.서버 쪽 과 클 라 이언 트 가 있 으 면 클 라 이언 트 를 통 해 서버 에 로그 인 한 후 다른 로그 인 한 사용자 와 대국 할 수 있 습 니 다.
2.서버 는 여러 그룹의 사용자 가 동시에 대국 하 는 것 을 지원 합 니 다.
3.사용 자 는 서버 에 새 게임 을 만 들 거나 만 든 게임 에 가입 할 수 있 습 니 다.
4.사용자 가 바둑 을 둘 때 채 팅 을 할 수 있다.
위 에서 실현 해 야 할 기능 을 알 수 있다.
서버 와 클 라 이언 트 기능 제공
·서버 는 클 라 이언 트 의 로그 인 상황 을 감청 하고 여러 클 라 이언 트 의 로그 인 을 허용 합 니 다
·사용 자 는 클 라 이언 트 를 통 해 서버 에 접속 할 수 있 으 며,이후 서버 가 현재 접속 중인 다른 사용 자 를 볼 수 있 으 며,그들 과 채 팅 을 할 수 있 습 니 다.
·사용자 가 서버 에 로그 인하 면 새로운 오목 게임 을 만 들 거나 이미 만 든 오목 게임 에 가입 할 수 있 습 니 다
·사용 자 는 클 라 이언 트 를 통 해 일반 오목 처럼 다른 사용자 와 대국 할 수 있 습 니 다
기능 에 따라 네트워크 오목 을 4 개 모듈 로 나 누 었 다.즉,사용자 패 널 모듈,바둑판 패 널 모듈,오목 서버 모듈,오목 클 라 이언 트 모듈 이다.
다음은 사용자 패 널 모듈 을 컴 파일 하기 시작 합 니 다.
1.사용자 목록 패 널 개발
import java.awt.*;
/**
* Created by Administrator on 2016/11/21.
*/
// 10 “ “ , 10
// , “BorderLayout”
public class UserListPad extends Panel{
public List userList=new List(10);
public UserListPad(){
setLayout(new BorderLayout());
for(int i=0;i<10;i++){
userList.add(i+"."+" ");
}
add(userList,BorderLayout.CENTER);
}
}
2.사용자 채 팅 패 널 개발
import javax.swing.*;
import java.awt.*;
/**
* Created by Administrator on 2016/11/21.
*/
// TextArea , 。
// TextArea , “BorderLayout” 。
public class UserChatPad extends JPanel{
public JTextArea chatTextArea=new JTextArea(" ",18,20);
public UserChatPad(){
setLayout(new BorderLayout());
chatTextArea.setAutoscrolls(true);
chatTextArea.setLineWrap(true);
add(chatTextArea,BorderLayout.CENTER);
}
}
3.사용자 입력 패 널 개발
import javax.swing.*;
import java.awt.*;
/**
* Created by Administrator on 2016/11/21.
*/
//
//contentInpitted TextField ,
public class UserInputPad extends JPanel{
public JTextField contentInputted = new JTextField("",26);
public JComboBox userChoice = new JComboBox();
public UserInputPad(){
setLayout(new FlowLayout(FlowLayout.LEFT));
for(int i=0;i<50;i++){
userChoice.addItem(i+"."+" ");
}
userChoice.setSize(60,24);
add(userChoice);
add(contentInputted);
}
}
4.사용자 조작 패 널 개발
import javax.swing.*;
import java.awt.*;
/**
* Created by Administrator on 2016/11/21.
*/
public class UserControlPad extends JPanel {
public JLabel ipLabel = new JLabel("IP",JLabel.LEFT);
public JTextField ipInputted = new JTextField("localhost",10);
public JButton connectButton = new JButton(" ");
public JButton createButton = new JButton(" ");
public JButton joinButton = new JButton(" ");
public JButton cancelButton = new JButton(" ");
public JButton exitButton = new JButton(" ");
public UserControlPad(){
setLayout(new FlowLayout(FlowLayout.LEFT));
setBackground(Color.LIGHT_GRAY);
add(ipLabel);
add(ipInputted);
add(connectButton);
add(createButton);
add(joinButton);
add(cancelButton);
add(exitButton);
}
}
다음은 바둑판 패 널 모듈 개발 을 시작 하 겠 습 니 다.1.검 은 바둑 류 개발
import java.awt.*;
/**
* Created by Administrator on 2016/11/21.
*/
public class FIRPointBlack extends Canvas {
FIRPad padBelonged; //
public FIRPointBlack(FIRPad padBelonged)
{
setSize(20, 20); //
this.padBelonged = padBelonged;
}
public void paint(Graphics g)
{ //
g.setColor(Color.black);
g.fillOval(0, 0, 14, 14);
}
}
2.백기 류 개발
import java.awt.*;
/**
* Created by Administrator on 2016/11/21.
*/
public class FIRPointWhite extends Canvas{
FIRPad padBelonged; //
public FIRPointWhite(FIRPad padBelonged)
{
setSize(20, 20);
this.padBelonged = padBelonged;
}
public void paint(Graphics g)
{ //
g.setColor(Color.white);
g.fillOval(0, 0, 14, 14);
}
}
3.바둑판 패 널 개발
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.JTextField;
/**
* Created by Administrator on 2016/11/21.
*/
public class FIRPad extends Panel implements MouseListener,ActionListener{
//
public boolean isMouseEnabled = false;
//
public boolean isWinned = false;
//
public boolean isGaming = false;
// x
public int chessX_POS = -1;
// y
public int chessY_POS = -1;
//
public int chessColor = 1;
// x
public int chessBlack_XPOS[] = new int[200];
// y
public int chessBlack_YPOS[] = new int[200];
// x
public int chessWhite_XPOS[] = new int[200];
// y
public int chessWhite_YPOS[] = new int[200];
//
public int chessBlackCount = 0;
//
public int chessWhiteCount = 0;
//
public int chessBlackVicTimes = 0;
//
public int chessWhiteVicTimes = 0;
//
public Socket chessSocket;
public DataInputStream inputData;
public DataOutputStream outputData;
public String chessSelfName = null;
public String chessPeerName = null;
public String host = null;
public int port = 4331;
public TextField statusText = new TextField(" !");
public FIRThread firThread = new FIRThread(this);
public FIRPad()
{
setSize(440, 440);
setLayout(null);
setBackground(Color.LIGHT_GRAY);
addMouseListener(this);
add(statusText);
statusText.setBounds(new Rectangle(40, 5, 360, 24));
statusText.setEditable(false);
}
//
public boolean connectServer(String ServerIP, int ServerPort) throws Exception
{
try
{
//
chessSocket = new Socket(ServerIP, ServerPort);
//
inputData = new DataInputStream(chessSocket.getInputStream());
//
outputData = new DataOutputStream(chessSocket.getOutputStream());
firThread.start();
return true;
}
catch (IOException ex)
{
statusText.setText(" !
");
}
return false;
}
//
public void setVicStatus(int vicChessColor)
{
//
this.removeAll();
//
for (int i = 0; i <= chessBlackCount; i++)
{
chessBlack_XPOS[i] = 0;
chessBlack_YPOS[i] = 0;
}
//
for (int i = 0; i <= chessWhiteCount; i++)
{
chessWhite_XPOS[i] = 0;
chessWhite_YPOS[i] = 0;
}
//
chessBlackCount = 0;
//
chessWhiteCount = 0;
add(statusText);
statusText.setBounds(40, 5, 360, 24);
if (vicChessColor == 1)
{ //
chessBlackVicTimes++;
statusText.setText(" , : " + chessBlackVicTimes + ":" + chessWhiteVicTimes
+ ", , ...");
}
else if (vicChessColor == -1)
{ //
chessWhiteVicTimes++;
statusText.setText(" , : " + chessBlackVicTimes + ":" + chessWhiteVicTimes
+ ", , ...");
}
}
//
public void setLocation(int xPos, int yPos, int chessColor)
{
if (chessColor == 1)
{ //
chessBlack_XPOS[chessBlackCount] = xPos * 20;
chessBlack_YPOS[chessBlackCount] = yPos * 20;
chessBlackCount++;
}
else if (chessColor == -1)
{ //
chessWhite_XPOS[chessWhiteCount] = xPos * 20;
chessWhite_YPOS[chessWhiteCount] = yPos * 20;
chessWhiteCount++;
}
}
//
public boolean checkVicStatus(int xPos, int yPos, int chessColor)
{
int chessLinkedCount = 1; //
int chessLinkedCompare = 1; //
int chessToCompareIndex = 0; //
int closeGrid = 1; //
if (chessColor == 1)
{ //
chessLinkedCount = 1; // , 1
// for ,
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{ // 4
for (chessToCompareIndex = 0; chessToCompareIndex <= chessBlackCount; chessToCompareIndex++)
{ //
if (((xPos + closeGrid) * 20 == chessBlack_XPOS[chessToCompareIndex])
&& ((yPos * 20) == chessBlack_YPOS[chessToCompareIndex]))
{ // 4
chessLinkedCount = chessLinkedCount + 1; // 1
if (chessLinkedCount == 5)
{ // ,
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {// , ,
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessBlackCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessBlack_XPOS[chessToCompareIndex])
&& (yPos * 20 == chessBlack_YPOS[chessToCompareIndex]))
{ // 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
// for
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessBlackCount; chessToCompareIndex++)
{
if ((xPos * 20 == chessBlack_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessBlack_YPOS[chessToCompareIndex]))
{ // 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessBlackCount; chessToCompareIndex++)
{
if ((xPos * 20 == chessBlack_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessBlack_YPOS[chessToCompareIndex]))
{ // 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessBlackCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessBlack_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessBlack_YPOS[chessToCompareIndex]))
{ // 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessBlackCount; chessToCompareIndex++)
{
if (((xPos + closeGrid) * 20 == chessBlack_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessBlack_YPOS[chessToCompareIndex]))
{ // 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessBlackCount; chessToCompareIndex++)
{
if (((xPos + closeGrid) * 20 == chessBlack_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessBlack_YPOS[chessToCompareIndex]))
{ // 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessBlackCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessBlack_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessBlack_YPOS[chessToCompareIndex]))
{ // 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
}
else if (chessColor == -1)
{ //
chessLinkedCount = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos + closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& (yPos * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& (yPos * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if ((xPos * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if ((xPos * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos + closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
chessLinkedCount = 1;
chessLinkedCompare = 1;
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos + closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos + closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return true;
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
for (closeGrid = 1; closeGrid <= 4; closeGrid++)
{
for (chessToCompareIndex = 0; chessToCompareIndex <= chessWhiteCount; chessToCompareIndex++)
{
if (((xPos - closeGrid) * 20 == chessWhite_XPOS[chessToCompareIndex])
&& ((yPos - closeGrid) * 20 == chessWhite_YPOS[chessToCompareIndex]))
{// 4
chessLinkedCount++;
if (chessLinkedCount == 5)
{
return (true);
}
}
}
if (chessLinkedCount == (chessLinkedCompare + 1)) {
chessLinkedCompare++;
}
else {
break;
}
}
}
return false;
}
//
public void paint(Graphics g)
{
for (int i = 40; i <= 380; i = i + 20)
{
g.drawLine(40, i, 400, i);
}
g.drawLine(40, 400, 400, 400);
for (int j = 40; j <= 380; j = j + 20)
{
g.drawLine(j, 40, j, 400);
}
g.drawLine(400, 40, 400, 400);
g.fillOval(97, 97, 6, 6);
g.fillOval(337, 97, 6, 6);
g.fillOval(97, 337, 6, 6);
g.fillOval(337, 337, 6, 6);
g.fillOval(217, 217, 6, 6);
}
//
public void paintFirPoint(int xPos, int yPos, int chessColor)
{
FIRPointBlack firPBlack = new FIRPointBlack(this);
FIRPointWhite firPWhite = new FIRPointWhite(this);
if (chessColor == 1 && isMouseEnabled)
{ //
//
setLocation(xPos, yPos, chessColor);
//
isWinned = checkVicStatus(xPos, yPos, chessColor);
if (isWinned == false)
{ //
firThread.sendMessage("/" + chessPeerName + " /chess "
+ xPos + " " + yPos + " " + chessColor);
this.add(firPBlack); //
firPBlack.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16); //
statusText.setText(" ( " + chessBlackCount + " )"
+ xPos + " " + yPos + ", .");
isMouseEnabled = false; //
}
else
{ //
firThread.sendMessage("/" + chessPeerName + " /chess "
+ xPos + " " + yPos + " " + chessColor);
this.add(firPBlack);
firPBlack.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
setVicStatus(1); // ,
isMouseEnabled = false;
}
}
else if (chessColor == -1 && isMouseEnabled)
{ //
setLocation(xPos, yPos, chessColor);
isWinned = checkVicStatus(xPos, yPos, chessColor);
if (isWinned == false)
{
firThread.sendMessage("/" + chessPeerName + " /chess "
+ xPos + " " + yPos + " " + chessColor);
this.add(firPWhite);
firPWhite.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
statusText.setText(" ( " + chessWhiteCount + " )"
+ xPos + " " + yPos + ", .");
isMouseEnabled = false;
}
else
{
firThread.sendMessage("/" + chessPeerName + " /chess "
+ xPos + " " + yPos + " " + chessColor);
this.add(firPWhite);
firPWhite.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
setVicStatus(-1); // ,
isMouseEnabled = false;
}
}
}
//
public void paintNetFirPoint(int xPos, int yPos, int chessColor)
{
FIRPointBlack firPBlack = new FIRPointBlack(this);
FIRPointWhite firPWhite = new FIRPointWhite(this);
setLocation(xPos, yPos, chessColor);
if (chessColor == 1)
{
isWinned = checkVicStatus(xPos, yPos, chessColor);
if (isWinned == false)
{
this.add(firPBlack);
firPBlack.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
statusText.setText(" ( " + chessBlackCount + " )"
+ xPos + " " + yPos + ", .");
isMouseEnabled = true;
}
else
{
firThread.sendMessage("/" + chessPeerName + " /victory "
+ chessColor);//djr
this.add(firPBlack);
firPBlack.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
setVicStatus(1);
isMouseEnabled = true;
}
}
else if (chessColor == -1)
{
isWinned = checkVicStatus(xPos, yPos, chessColor);
if (isWinned == false)
{
this.add(firPWhite);
firPWhite.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
statusText.setText(" ( " + chessWhiteCount + " )"
+ xPos + " " + yPos + ", .");
isMouseEnabled = true;
}
else
{
firThread.sendMessage("/" + chessPeerName + " /victory "
+ chessColor);
this.add(firPWhite);
firPWhite.setBounds(xPos * 20 - 7,
yPos * 20 - 7, 16, 16);
setVicStatus(-1);
isMouseEnabled = true;
}
}
}
//
public void mousePressed(MouseEvent e)
{
if (e.getModifiers() == InputEvent.BUTTON1_MASK)
{
chessX_POS = (int) e.getX();
chessY_POS = (int) e.getY();
int a = (chessX_POS + 10) / 20, b = (chessY_POS + 10) / 20;
if (chessX_POS / 20 < 2 || chessY_POS / 20 < 2
|| chessX_POS / 20 > 19 || chessY_POS / 20 > 19)
{
// ,
}
else
{
paintFirPoint(a, b, chessColor); //
}
}
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e){}
public void mouseClicked(MouseEvent e){}
public void actionPerformed(ActionEvent e){}
}
4.바둑판 라인 개발
import java.util.StringTokenizer;
import java.io.IOException;
/**
* Created by Administrator on 2016/11/21.
*/
public class FIRThread extends Thread{
FIRPad currPad; //
public FIRThread(FIRPad currPad)
{
this.currPad = currPad;
}
//
public void dealWithMsg(String msgReceived)
{
if (msgReceived.startsWith("/chess "))
{ //
StringTokenizer userMsgToken = new StringTokenizer(msgReceived, " ");
// 、0 :x ;1 :y ;2 :
String[] chessInfo = { "-1", "-1", "0" };
int i = 0; //
String chessInfoToken;
while (userMsgToken.hasMoreTokens())
{
chessInfoToken = (String) userMsgToken.nextToken(" ");
if (i >= 1 && i <= 3)
{
chessInfo[i - 1] = chessInfoToken;
}
i++;
}
currPad.paintNetFirPoint(Integer.parseInt(chessInfo[0]), Integer
.parseInt(chessInfo[1]), Integer.parseInt(chessInfo[2]));
}
else if (msgReceived.startsWith("/yourname "))
{ //
currPad.chessSelfName = msgReceived.substring(10);
}
else if (msgReceived.equals("/error"))
{ //
currPad.statusText.setText(" , !");
}
}
//
public void sendMessage(String sndMessage)
{
try
{
currPad.outputData.writeUTF(sndMessage);
}
catch (Exception ea)
{
ea.printStackTrace();;
}
}
public void run()
{
String msgReceived = "";
try
{
while (true)
{ //
msgReceived = currPad.inputData.readUTF();
dealWithMsg(msgReceived);
}
}
catch (IOException es){}
}
}
다음은 서버 모듈 개발 을 시작 하 겠 습 니 다.1.서버 정보 패 널 개발
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextArea;
import javax.swing.JLabel;
/**
* Created by Administrator on 2016/11/21.
*/
public class ServerMsgPanel extends Panel {
public TextArea msgTextArea = new TextArea("", 22, 50,
TextArea.SCROLLBARS_VERTICAL_ONLY);
public JLabel statusLabel = new JLabel(" :", Label.LEFT);
public Panel msgPanel = new Panel();
public Panel statusPanel = new Panel();
public ServerMsgPanel()
{
setSize(350, 300);
setBackground(Color.LIGHT_GRAY);
setLayout(new BorderLayout());
msgPanel.setLayout(new FlowLayout());
msgPanel.setSize(210, 210);
statusPanel.setLayout(new BorderLayout());
statusPanel.setSize(210, 50);
msgPanel.add(msgTextArea);
statusPanel.add(statusLabel, BorderLayout.WEST);
add(msgPanel, BorderLayout.CENTER);
add(statusPanel, BorderLayout.NORTH);
}
}
2.서버 프로 세 스 개발
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
/**
* Created by Administrator on 2016/11/21.
*/
public class FIRServerThread extends Thread{
Socket clientSocket; //
Hashtable clientDataHash; // Hash
Hashtable clientNameHash; // Hash
Hashtable chessPeerHash; // Hash
ServerMsgPanel serverMsgPanel;
boolean isClientClosed = false;
public FIRServerThread(Socket clientSocket, Hashtable clientDataHash,
Hashtable clientNameHash, Hashtable chessPeerHash,
ServerMsgPanel server)
{
this.clientSocket = clientSocket;
this.clientDataHash = clientDataHash;
this.clientNameHash = clientNameHash;
this.chessPeerHash = chessPeerHash;
this.serverMsgPanel = server;
}
public void dealWithMsg(String msgReceived)
{
String clientName;
String peerName;
if (msgReceived.startsWith("/"))
{
if (msgReceived.equals("/list"))
{ //
Feedback(getUserList());
}
else if (msgReceived.startsWith("/creatgame [inchess]"))
{ //
String gameCreaterName = msgReceived.substring(20); //
synchronized (clientNameHash)
{ //
clientNameHash.put(clientSocket, msgReceived.substring(11));
}
synchronized (chessPeerHash)
{ //
chessPeerHash.put(gameCreaterName, "wait");
}
Feedback("/yourname " + clientNameHash.get(clientSocket));
sendGamePeerMsg(gameCreaterName, "/OK");
sendPublicMsg(getUserList());
}
else if (msgReceived.startsWith("/joingame "))
{ //
StringTokenizer userTokens = new StringTokenizer(msgReceived, " ");
String userToken;
String gameCreatorName;
String gamePaticipantName;
String[] playerNames = { "0", "0" };
int nameIndex = 0;
while (userTokens.hasMoreTokens())
{
userToken = (String) userTokens.nextToken(" ");
if (nameIndex >= 1 && nameIndex <= 2)
{
playerNames[nameIndex - 1] = userToken; //
}
nameIndex++;
}
gameCreatorName = playerNames[0];
gamePaticipantName = playerNames[1];
if (chessPeerHash.containsKey(gameCreatorName)
&& chessPeerHash.get(gameCreatorName).equals("wait"))
{ //
synchronized (clientNameHash)
{ //
clientNameHash.put(clientSocket,
("[inchess]" + gamePaticipantName));
}
synchronized (chessPeerHash)
{ //
chessPeerHash.put(gameCreatorName, gamePaticipantName);
}
sendPublicMsg(getUserList());
//
sendGamePeerMsg(gamePaticipantName,
("/peer " + "[inchess]" + gameCreatorName));
//
sendGamePeerMsg(gameCreatorName,
("/peer " + "[inchess]" + gamePaticipantName));
}
else
{ //
sendGamePeerMsg(gamePaticipantName, "/reject");
try
{
closeClient();
}
catch (Exception ez)
{
ez.printStackTrace();
}
}
}
else if (msgReceived.startsWith("/[inchess]"))
{ //
int firstLocation = 0, lastLocation;
lastLocation = msgReceived.indexOf(" ", 0);
peerName = msgReceived.substring((firstLocation + 1), lastLocation);
msgReceived = msgReceived.substring((lastLocation + 1));
if (sendGamePeerMsg(peerName, msgReceived))
{
Feedback("/error");
}
}
else if (msgReceived.startsWith("/giveup "))
{ //
String chessClientName = msgReceived.substring(8);
if (chessPeerHash.containsKey(chessClientName)
&& !((String) chessPeerHash.get(chessClientName))
.equals("wait"))
{ // ,
sendGamePeerMsg((String) chessPeerHash.get(chessClientName),
"/youwin");
synchronized (chessPeerHash)
{ //
chessPeerHash.remove(chessClientName);
}
}
if (chessPeerHash.containsValue(chessClientName))
{ // ,
sendGamePeerMsg((String) getHashKey(chessPeerHash,
chessClientName), "/youwin");
synchronized (chessPeerHash)
{//
chessPeerHash.remove((String) getHashKey(chessPeerHash,
chessClientName));
}
}
}
else
{ //
int lastLocation = msgReceived.indexOf(" ", 0);
if (lastLocation == -1)
{
Feedback(" ");
return;
}
}
}
else
{
msgReceived = clientNameHash.get(clientSocket) + ">" + msgReceived;
serverMsgPanel.msgTextArea.append(msgReceived + "
");
sendPublicMsg(msgReceived);
serverMsgPanel.msgTextArea.setCaretPosition(serverMsgPanel.msgTextArea.getText()
.length());
}
}
//
public void sendPublicMsg(String publicMsg)
{
synchronized (clientDataHash)
{
for (Enumeration enu = clientDataHash.elements(); enu
.hasMoreElements();)
{
DataOutputStream outputData = (DataOutputStream) enu.nextElement();
try
{
outputData.writeUTF(publicMsg);
}
catch (IOException es)
{
es.printStackTrace();
}
}
}
}
//
public boolean sendGamePeerMsg(String gamePeerTarget, String gamePeerMsg)
{
for (Enumeration enu = clientDataHash.keys(); enu.hasMoreElements();)
{ //
Socket userClient = (Socket) enu.nextElement();
if (gamePeerTarget.equals((String) clientNameHash.get(userClient))
&& !gamePeerTarget.equals((String) clientNameHash
.get(clientSocket)))
{ //
synchronized (clientDataHash)
{
//
DataOutputStream peerOutData = (DataOutputStream) clientDataHash
.get(userClient);
try
{
//
peerOutData.writeUTF(gamePeerMsg);
}
catch (IOException es)
{
es.printStackTrace();
}
}
return false;
}
}
return true;
}
//
public void Feedback(String feedBackMsg)
{
synchronized (clientDataHash)
{
DataOutputStream outputData = (DataOutputStream) clientDataHash
.get(clientSocket);
try
{
outputData.writeUTF(feedBackMsg);
}
catch (Exception eb)
{
eb.printStackTrace();
}
}
}
//
public String getUserList()
{
String userList = "/userlist";
for (Enumeration enu = clientNameHash.elements(); enu.hasMoreElements();)
{
userList = userList + " " + (String) enu.nextElement();
}
return userList;
}
// value Hashtable key
public Object getHashKey(Hashtable targetHash, Object hashValue)
{
Object hashKey;
for (Enumeration enu = targetHash.keys(); enu.hasMoreElements();)
{
hashKey = (Object) enu.nextElement();
if (hashValue.equals((Object) targetHash.get(hashKey)))
return hashKey;
}
return null;
}
//
public void sendInitMsg()
{
sendPublicMsg(getUserList());
Feedback("/yourname " + (String) clientNameHash.get(clientSocket));
Feedback("Java ");
Feedback("/list -- ");
Feedback("/<username> <talk> -- ");
Feedback(" : ");
}
public void closeClient()
{
serverMsgPanel.msgTextArea.append(" :" + clientSocket + "
");
synchronized (chessPeerHash)
{ //
if (chessPeerHash.containsKey(clientNameHash.get(clientSocket)))
{
chessPeerHash.remove((String) clientNameHash.get(clientSocket));
}
if (chessPeerHash.containsValue(clientNameHash.get(clientSocket)))
{
chessPeerHash.put((String) getHashKey(chessPeerHash,
(String) clientNameHash.get(clientSocket)),
"tobeclosed");
}
}
synchronized (clientDataHash)
{ //
clientDataHash.remove(clientSocket);
}
synchronized (clientNameHash)
{ //
clientNameHash.remove(clientSocket);
}
sendPublicMsg(getUserList());
serverMsgPanel.statusLabel.setText(" :" + clientDataHash.size());
try
{
clientSocket.close();
}
catch (IOException exx)
{
exx.printStackTrace();
}
isClientClosed = true;
}
public void run()
{
DataInputStream inputData;
synchronized (clientDataHash)
{
serverMsgPanel.statusLabel.setText(" :" + clientDataHash.size());
}
try
{ //
inputData = new DataInputStream(clientSocket.getInputStream());
sendInitMsg();
while (true)
{
String message = inputData.readUTF();
dealWithMsg(message);
}
}
catch (IOException esx){}
finally
{
if (!isClientClosed)
{
closeClient();
}
}
}
}
3.서버 개발
import java.io.*;
import java.net.*;
import java.awt.*;
import java.util.*;
import java.awt.event.*;
import javax.swing.JButton;
/**
* Created by Administrator on 2016/11/21.
*/
public class FIRServer extends Frame implements ActionListener{
JButton clearMsgButton = new JButton(" ");
JButton serverStatusButton = new JButton(" ");
JButton closeServerButton = new JButton(" ");
Panel buttonPanel = new Panel();
ServerMsgPanel serverMsgPanel = new ServerMsgPanel();
ServerSocket serverSocket;
Hashtable clientDataHash = new Hashtable(50); //
Hashtable clientNameHash = new Hashtable(50); //
Hashtable chessPeerHash = new Hashtable(50); //
public FIRServer()
{
super("Java ");
setBackground(Color.LIGHT_GRAY);
buttonPanel.setLayout(new FlowLayout());
clearMsgButton.setSize(60, 25);
buttonPanel.add(clearMsgButton);
clearMsgButton.addActionListener(this);
serverStatusButton.setSize(75, 25);
buttonPanel.add(serverStatusButton);
serverStatusButton.addActionListener(this);
closeServerButton.setSize(75, 25);
buttonPanel.add(closeServerButton);
closeServerButton.addActionListener(this);
add(serverMsgPanel, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.SOUTH);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
pack();
setVisible(true);
setSize(400, 300);
setResizable(false);
validate();
try
{
createServer(4331, serverMsgPanel);
}
catch (Exception e)
{
e.printStackTrace();
}
}
//
public void createServer(int port, ServerMsgPanel serverMsgPanel) throws IOException
{
Socket clientSocket; //
long clientAccessNumber = 1; //
this.serverMsgPanel = serverMsgPanel; //
try
{
serverSocket = new ServerSocket(port);
serverMsgPanel.msgTextArea.setText(" :"
+ InetAddress.getLocalHost() + ":" //djr
+ serverSocket.getLocalPort() + "
");
while (true)
{
//
clientSocket = serverSocket.accept();
serverMsgPanel.msgTextArea.append(" :" + clientSocket + "
");
//
DataOutputStream outputData = new DataOutputStream(clientSocket
.getOutputStream());
//
clientDataHash.put(clientSocket, outputData);
//
clientNameHash
.put(clientSocket, (" " + clientAccessNumber++));
//
FIRServerThread thread = new FIRServerThread(clientSocket,
clientDataHash, clientNameHash, chessPeerHash, serverMsgPanel);
thread.start();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == clearMsgButton)
{ //
serverMsgPanel.msgTextArea.setText("");
}
if (e.getSource() == serverStatusButton)
{ //
try
{
serverMsgPanel.msgTextArea.append(" :"
+ InetAddress.getLocalHost() + ":"
+ serverSocket.getLocalPort() + "
");
}
catch (Exception ee)
{
ee.printStackTrace();
}
}
if (e.getSource() == closeServerButton)
{ //
System.exit(0);
}
}
public static void main(String args[])
{
FIRServer firServer = new FIRServer();
}
}
클 라 이언 트 모듈 작성 시작1.클 라 이언 트 개발
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.JFrame;
import djr.chess.gui.UserChatPad;
import djr.chess.gui.UserControlPad;
import djr.chess.gui.UserInputPad;
import djr.chess.gui.UserListPad;
import djr.chess.pad.FIRPad;
/**
* Created by Administrator on 2016/11/21.
*/
public class FIRClient extends Frame implements ActionListener,KeyListener {
//
Socket clientSocket;
//
DataInputStream inputStream;
//
DataOutputStream outputStream;
//
String chessClientName = null;
//
String host = null;
//
int port = 4331;
//
boolean isOnChat = false;
//
boolean isOnChess = false;
//
boolean isGameConnected = false;
//
boolean isCreator = false;
//
boolean isParticipant = false;
//
UserListPad userListPad = new UserListPad();
//
UserChatPad userChatPad = new UserChatPad();
//
UserControlPad userControlPad = new UserControlPad();
//
UserInputPad userInputPad = new UserInputPad();
//
FIRPad firPad = new FIRPad();
//
Panel southPanel = new Panel();
Panel northPanel = new Panel();
Panel centerPanel = new Panel();
Panel eastPanel = new Panel();
// ,
public FIRClient()
{
super("Java ");
setLayout(new BorderLayout());
host = userControlPad.ipInputted.getText();
eastPanel.setLayout(new BorderLayout());
eastPanel.add(userListPad, BorderLayout.NORTH);
eastPanel.add(userChatPad, BorderLayout.CENTER);
eastPanel.setBackground(Color.LIGHT_GRAY);
userInputPad.contentInputted.addKeyListener(this);
firPad.host = userControlPad.ipInputted.getText();
centerPanel.add(firPad, BorderLayout.CENTER);
centerPanel.add(userInputPad, BorderLayout.SOUTH);
centerPanel.setBackground(Color.LIGHT_GRAY);
userControlPad.connectButton.addActionListener(this);
userControlPad.createButton.addActionListener(this);
userControlPad.joinButton.addActionListener(this);
userControlPad.cancelButton.addActionListener(this);
userControlPad.exitButton.addActionListener(this);
userControlPad.createButton.setEnabled(false);
userControlPad.joinButton.setEnabled(false);
userControlPad.cancelButton.setEnabled(false);
southPanel.add(userControlPad, BorderLayout.CENTER);
southPanel.setBackground(Color.LIGHT_GRAY);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
if (isOnChat)
{ //
try
{ //
clientSocket.close();
}
catch (Exception ed){}
}
if (isOnChess || isGameConnected)
{ //
try
{ //
firPad.chessSocket.close();
}
catch (Exception ee){}
}
System.exit(0);
}
});
add(eastPanel, BorderLayout.EAST);
add(centerPanel, BorderLayout.CENTER);
add(southPanel, BorderLayout.SOUTH);
pack();
setSize(670, 560);
setVisible(true);
setResizable(false);
this.validate();
}
// IP
public boolean connectToServer(String serverIP, int serverPort) throws Exception
{
try
{
//
clientSocket = new Socket(serverIP, serverPort);
//
inputStream = new DataInputStream(clientSocket.getInputStream());
//
outputStream = new DataOutputStream(clientSocket.getOutputStream());
//
FIRClientThread clientthread = new FIRClientThread(this);
// ,
clientthread.start();
isOnChat = true;
return true;
}
catch (IOException ex)
{
userChatPad.chatTextArea
.setText(" !
");
}
return false;
}
//
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == userControlPad.connectButton)
{ //
host = firPad.host = userControlPad.ipInputted.getText(); //
try
{
if (connectToServer(host, port))
{ // ,
userChatPad.chatTextArea.setText("");
userControlPad.connectButton.setEnabled(false);
userControlPad.createButton.setEnabled(true);
userControlPad.joinButton.setEnabled(true);
firPad.statusText.setText(" , !");
}
}
catch (Exception ei)
{
userChatPad.chatTextArea
.setText(" !
");
}
}
if (e.getSource() == userControlPad.exitButton)
{ //
if (isOnChat)
{ //
try
{ //
clientSocket.close();
}
catch (Exception ed){}
}
if (isOnChess || isGameConnected)
{ //
try
{ //
firPad.chessSocket.close();
}
catch (Exception ee){}
}
System.exit(0);
}
if (e.getSource() == userControlPad.joinButton)
{ //
String selectedUser = (String)userListPad.userList.getSelectedItem(); //
if (selectedUser == null || selectedUser.startsWith("[inchess]") ||
selectedUser.equals(chessClientName))
{ // , ,
firPad.statusText.setText(" !");
}
else
{ //
try
{
if (!isGameConnected)
{ //
if (firPad.connectServer(firPad.host, firPad.port))
{ //
isGameConnected = true;
isOnChess = true;
isParticipant = true;
userControlPad.createButton.setEnabled(false);
userControlPad.joinButton.setEnabled(false);
userControlPad.cancelButton.setEnabled(true);
firPad.firThread.sendMessage("/joingame "
+ (String)userListPad.userList.getSelectedItem() + " "
+ chessClientName);
}
}
else
{ //
isOnChess = true;
isParticipant = true;
userControlPad.createButton.setEnabled(false);
userControlPad.joinButton.setEnabled(false);
userControlPad.cancelButton.setEnabled(true);
firPad.firThread.sendMessage("/joingame "
+ (String)userListPad.userList.getSelectedItem() + " "
+ chessClientName);
}
}
catch (Exception ee)
{
isGameConnected = false;
isOnChess = false;
isParticipant = false;
userControlPad.createButton.setEnabled(true);
userControlPad.joinButton.setEnabled(true);
userControlPad.cancelButton.setEnabled(false);
userChatPad.chatTextArea
.setText(" :
" + ee);
}
}
}
if (e.getSource() == userControlPad.createButton)
{ //
try
{
if (!isGameConnected)
{ //
if (firPad.connectServer(firPad.host, firPad.port))
{ //
isGameConnected = true;
isOnChess = true;
isCreator = true;
userControlPad.createButton.setEnabled(false);
userControlPad.joinButton.setEnabled(false);
userControlPad.cancelButton.setEnabled(true);
firPad.firThread.sendMessage("/creatgame "
+ "[inchess]" + chessClientName);
}
}
else
{ //
isOnChess = true;
isCreator = true;
userControlPad.createButton.setEnabled(false);
userControlPad.joinButton.setEnabled(false);
userControlPad.cancelButton.setEnabled(true);
firPad.firThread.sendMessage("/creatgame "
+ "[inchess]" + chessClientName);
}
}
catch (Exception ec)
{
isGameConnected = false;
isOnChess = false;
isCreator = false;
userControlPad.createButton.setEnabled(true);
userControlPad.joinButton.setEnabled(true);
userControlPad.cancelButton.setEnabled(false);
ec.printStackTrace();
userChatPad.chatTextArea.setText(" :
"
+ ec);
}
}
if (e.getSource() == userControlPad.cancelButton)
{ //
if (isOnChess)
{ //
firPad.firThread.sendMessage("/giveup " + chessClientName);
firPad.setVicStatus(-1 * firPad.chessColor);
userControlPad.createButton.setEnabled(true);
userControlPad.joinButton.setEnabled(true);
userControlPad.cancelButton.setEnabled(false);
firPad.statusText.setText(" !");
}
if (!isOnChess)
{ //
userControlPad.createButton.setEnabled(true);
userControlPad.joinButton.setEnabled(true);
userControlPad.cancelButton.setEnabled(false);
firPad.statusText.setText(" !");
}
isParticipant = isCreator = false;
}
}
public void keyPressed(KeyEvent e)
{
TextField inputwords = (TextField) e.getSource();
if (e.getKeyCode() == KeyEvent.VK_ENTER)
{ //
if (userInputPad.userChoice.getSelectedItem().equals(" "))
{ //
try
{
//
outputStream.writeUTF(inputwords.getText());
inputwords.setText("");
}
catch (Exception ea)
{
userChatPad.chatTextArea
.setText(" !
");
userListPad.userList.removeAll();
userInputPad.userChoice.removeAll();
inputwords.setText("");
userControlPad.connectButton.setEnabled(true);
}
}
else
{ //
try
{
outputStream.writeUTF("/" + userInputPad.userChoice.getSelectedItem()
+ " " + inputwords.getText());
inputwords.setText("");
}
catch (Exception ea)
{
userChatPad.chatTextArea
.setText(" !
");
userListPad.userList.removeAll();
userInputPad.userChoice.removeAll();
inputwords.setText("");
userControlPad.connectButton.setEnabled(true);
}
}
}
}
public void keyTyped(KeyEvent e) {}
public void keyReleased(KeyEvent e) {}
public static void main(String args[])
{
FIRClient chessClient = new FIRClient();
}
}
2.클 라 이언 트 스 레 드 개발
import java.io.IOException;
import java.util.StringTokenizer;
import javax.swing.DefaultListModel;
import javax.swing.ListModel;
/**
* Created by Administrator on 2016/11/21.
*/
public class FIRClientThread extends Thread{
public FIRClient firClient;
public FIRClientThread(FIRClient firClient)
{
this.firClient = firClient;
}
public void dealWithMsg(String msgReceived)
{
if (msgReceived.startsWith("/userlist "))
{ //
StringTokenizer userToken = new StringTokenizer(msgReceived, " ");
int userNumber = 0;
//
firClient.userListPad.userList.removeAll();
//
firClient.userInputPad.userChoice.removeAll();
//
firClient.userInputPad.userChoice.addItem(" ");
while (userToken.hasMoreTokens())
{ //
String user = (String) userToken.nextToken(" "); //
if (userNumber > 0 && !user.startsWith("[inchess]"))
{ //
firClient.userListPad.userList.add(user);//
firClient.userInputPad.userChoice.addItem(user); //
}
userNumber++;
}
firClient.userInputPad.userChoice.setSelectedIndex(0);//
}
else if (msgReceived.startsWith("/yourname "))
{ //
firClient.chessClientName = msgReceived.substring(10); //
firClient.setTitle("Java " + " :"
+ firClient.chessClientName); // Frame
}
else if (msgReceived.equals("/reject"))
{ //
try
{
firClient.firPad.statusText.setText(" !");
firClient.userControlPad.cancelButton.setEnabled(false);
firClient.userControlPad.joinButton.setEnabled(true);
firClient.userControlPad.createButton.setEnabled(true);
}
catch (Exception ef)
{
firClient.userChatPad.chatTextArea
.setText("Cannot close!");
}
firClient.userControlPad.joinButton.setEnabled(true);
}
else if (msgReceived.startsWith("/peer "))
{ //
firClient.firPad.chessPeerName = msgReceived.substring(6);
if (firClient.isCreator)
{ //
firClient.firPad.chessColor = 1; //
firClient.firPad.isMouseEnabled = true;
firClient.firPad.statusText.setText(" ...");
}
else if (firClient.isParticipant)
{ //
firClient.firPad.chessColor = -1; //
firClient.firPad.statusText.setText(" , .");
}
}
else if (msgReceived.equals("/youwin"))
{ //
firClient.isOnChess = false;
firClient.firPad.setVicStatus(firClient.firPad.chessColor);
firClient.firPad.statusText.setText(" ");
firClient.firPad.isMouseEnabled = false;
}
else if (msgReceived.equals("/OK"))
{ //
firClient.firPad.statusText.setText(" ");
}
else if (msgReceived.equals("/error"))
{ //
firClient.userChatPad.chatTextArea.append(" , .
");
}
else
{
firClient.userChatPad.chatTextArea.append(msgReceived + "
");
firClient.userChatPad.chatTextArea.setCaretPosition(
firClient.userChatPad.chatTextArea.getText().length());
}
}
public void run()
{
String message = "";
try
{
while (true)
{
// , wait
message = firClient.inputStream.readUTF();
dealWithMsg(message);
}
}
catch (IOException es){}
}
}
이로써 인터넷 판 오목 은 개발 이 완 료 된 셈 이다.이렇게 많은 종류 와 가방 의 관 계 는 다음 과 같다.이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.