仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 997|回复: 18
打印 上一主题 下一主题

[学习教程] JAVA教程之java收集五子棋的源代码

[复制链接]
冷月葬花魂 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:42:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
为什么外国人还要写那些框架进行代码封装,他们不就是为了别人使用时可以更简单么!如果要达到一个企业级项目的不用框架是很难的。小一些的项目还行,大的光是MVC模式的设计的编码量就够大的了。还有性能方面,单轮windows,这个工具是微软写的,。收集|源代码上面的源代码分为4个文件;
chessClient.java:客户端主程序。
chessInterface.java:客户真个界面。
chessPad.java:棋盘的绘制。
chessServer.java:服务器端。
可同时包容50团体同时在线下棋,谈天。
没有加上具体正文,不外相对能够运转,j2sdk1.4下经由过程。


/*********************************************************************************************
1.chessClient.java
**********************************************************************************************/

importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjava.net.*;
importjava.util.*;


classclientThreadextendsThread
{
chessClientchessclient;

clientThread(chessClientchessclient)
{
this.chessclient=chessclient;
}

publicvoidacceptMessage(StringrecMessage)
{
if(recMessage.startsWith("/userlist"))
{
StringTokenizeruserToken=newStringTokenizer(recMessage,"");
intuserNumber=0;

chessclient.userpad.userList.removeAll();
chessclient.inputpad.userChoice.removeAll();
chessclient.inputpad.userChoice.addItem("一切人");
while(userToken.hasMoreTokens())
{
Stringuser=(String)userToken.nextToken("");
if(userNumber>0&&!user.startsWith("[inchess]"))
{
chessclient.userpad.userList.add(user);
chessclient.inputpad.userChoice.addItem(user);
}

userNumber++;
}
chessclient.inputpad.userChoice.select("一切人");
}
elseif(recMessage.startsWith("/yourname"))
{
chessclient.chessClientName=recMessage.substring(10);
chessclient.setTitle("Java五子棋客户端"+"用户名:"+chessclient.chessClientName);
}
elseif(recMessage.equals("/reject"))
{
try
{
chessclient.chesspad.statusText.setText("不克不及到场游戏");
chessclient.controlpad.cancelGameButton.setEnabled(false);
chessclient.controlpad.joinGameButton.setEnabled(true);
chessclient.controlpad.creatGameButton.setEnabled(true);
}
catch(Exceptionef)
{
chessclient.chatpad.chatLineArea.setText("chessclient.chesspad.chessSocket.close没法封闭");
}
chessclient.controlpad.joinGameButton.setEnabled(true);
}
elseif(recMessage.startsWith("/peer"))
{
chessclient.chesspad.chessPeerName=recMessage.substring(6);
if(chessclient.isServer)
{
chessclient.chesspad.chessColor=1;
chessclient.chesspad.isMouseEnabled=true;
chessclient.chesspad.statusText.setText("请黑棋下子");
}
elseif(chessclient.isClient)
{
chessclient.chesspad.chessColor=-1;
chessclient.chesspad.statusText.setText("已到场游戏,守候对方下子...");
}

}
elseif(recMessage.equals("/youwin"))
{
chessclient.isOnChess=false;
chessclient.chesspad.chessVictory(chessclient.chesspad.chessColor);
chessclient.chesspad.statusText.setText("对方加入,请点保持游戏加入毗连");
chessclient.chesspad.isMouseEnabled=false;
}
elseif(recMessage.equals("/OK"))
{
chessclient.chesspad.statusText.setText("创立游戏乐成,守候他人到场...");
}
elseif(recMessage.equals("/error"))
{
chessclient.chatpad.chatLineArea.append("传输毛病:请加入程序,从头到场
");
}
else
{
chessclient.chatpad.chatLineArea.append(recMessage+"
");
chessclient.chatpad.chatLineArea.setCaretPosition(
chessclient.chatpad.chatLineArea.getText().length());
}
}


publicvoidrun()
{
Stringmessage="";
try
{
while(true)
{
message=chessclient.in.readUTF();
acceptMessage(message);
}
}
catch(IOExceptiones)
{
}
}

}






publicclasschessClientextendsFrameimplementsActionListener,KeyListener
{
userPaduserpad=newuserPad();
chatPadchatpad=newchatPad();
controlPadcontrolpad=newcontrolPad();
chessPadchesspad=newchessPad();
inputPadinputpad=newinputPad();


SocketchatSocket;
DataInputStreamin;
DataOutputStreamout;
StringchessClientName=null;
Stringhost=null;
intport=4331;

booleanisOnChat=false;//在谈天?
booleanisOnChess=false;//鄙人棋?
booleanisGameConnected=false;//下棋的客户端毗连?
booleanisServer=false;//假如是下棋的主机
booleanisClient=false;//假如是下棋的客户端

PanelsouthPanel=newPanel();
PanelnorthPanel=newPanel();
PanelcenterPanel=newPanel();
PanelwestPanel=newPanel();
PaneleastPanel=newPanel();

chessClient()
{
super("Java五子棋客户端");
setLayout(newBorderLayout());
host=controlpad.inputIP.getText();

westPanel.setLayout(newBorderLayout());
westPanel.add(userpad,BorderLayout.NORTH);
westPanel.add(chatpad,BorderLayout.CENTER);
westPanel.setBackground(Color.pink);

inputpad.inputWords.addKeyListener(this);
chesspad.host=controlpad.inputIP.getText();

centerPanel.add(chesspad,BorderLayout.CENTER);
centerPanel.add(inputpad,BorderLayout.SOUTH);
centerPanel.setBackground(Color.pink);

controlpad.connectButton.addActionListener(this);
controlpad.creatGameButton.addActionListener(this);
controlpad.joinGameButton.addActionListener(this);
controlpad.cancelGameButton.addActionListener(this);
controlpad.exitGameButton.addActionListener(this);

controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(false);

southPanel.add(controlpad,BorderLayout.CENTER);
southPanel.setBackground(Color.pink);


addWindowListener(newWindowAdapter()
{
publicvoidwindowClosing(WindowEvente)
{
if(isOnChat)
{
try
{
chatSocket.close();
}
catch(Exceptioned)
{
}
}
if(isOnChess||isGameConnected)
{
try
{
chesspad.chessSocket.close();
}
catch(Exceptionee)
{
}
}
System.exit(0);
}
publicvoidwindowActivated(WindowEventea)
{

}
});

add(westPanel,BorderLayout.WEST);
add(centerPanel,BorderLayout.CENTER);
add(southPanel,BorderLayout.SOUTH);

pack();
setSize(670,548);
setVisible(true);
setResizable(false);
validate();
}



publicbooleanconnectServer(StringserverIP,intserverPort)throwsException
{
try
{
chatSocket=newSocket(serverIP,serverPort);
in=newDataInputStream(chatSocket.getInputStream());
out=newDataOutputStream(chatSocket.getOutputStream());

clientThreadclientthread=newclientThread(this);
clientthread.start();
isOnChat=true;
returntrue;
}
catch(IOExceptionex)
{
chatpad.chatLineArea.setText("chessClient:connectServer:没法毗连,倡议从头启动程序
");
}
returnfalse;
}


publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==controlpad.connectButton)
{
host=chesspad.host=controlpad.inputIP.getText();
try
{
if(connectServer(host,port))
{
chatpad.chatLineArea.setText("");
controlpad.connectButton.setEnabled(false);
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
chesspad.statusText.setText("毗连乐成,请创立游戏或到场游戏");
}


}
catch(Exceptionei)
{
chatpad.chatLineArea.setText("controlpad.connectButton:没法毗连,倡议从头启动程序
");
}
}
if(e.getSource()==controlpad.exitGameButton)
{
if(isOnChat)
{
try
{
chatSocket.close();
}
catch(Exceptioned)
{
}
}
if(isOnChess||isGameConnected)
{
try
{
chesspad.chessSocket.close();
}
catch(Exceptionee)
{
}
}
System.exit(0);

}
if(e.getSource()==controlpad.joinGameButton)
{
StringselectedUser=userpad.userList.getSelectedItem();
if(selectedUser==null||selectedUser.startsWith("[inchess]")||
selectedUser.equals(chessClientName))
{
chesspad.statusText.setText("必需先选定一个无效用户");
}
else
{
try
{
if(!isGameConnected)
{
if(chesspad.connectServer(chesspad.host,chesspad.port))
{
isGameConnected=true;
isOnChess=true;
isClient=true;
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(true);
chesspad.chessthread.sendMessage("/joingame"+userpad.userList.getSelectedItem()+""+chessClientName);
}
}
else
{
isOnChess=true;
isClient=true;
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(true);
chesspad.chessthread.sendMessage("/joingame"+userpad.userList.getSelectedItem()+""+chessClientName);
}


}
catch(Exceptionee)
{
isGameConnected=false;
isOnChess=false;
isClient=false;
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
controlpad.cancelGameButton.setEnabled(false);
chatpad.chatLineArea.setText("chesspad.connectServer没法毗连
"+ee);
}

}
}
if(e.getSource()==controlpad.creatGameButton)
{
try
{
if(!isGameConnected)
{
if(chesspad.connectServer(chesspad.host,chesspad.port))
{
isGameConnected=true;
isOnChess=true;
isServer=true;
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(true);
chesspad.chessthread.sendMessage("/creatgame"+"[inchess]"+chessClientName);
}
}
else
{
isOnChess=true;
isServer=true;
controlpad.creatGameButton.setEnabled(false);
controlpad.joinGameButton.setEnabled(false);
controlpad.cancelGameButton.setEnabled(true);
chesspad.chessthread.sendMessage("/creatgame"+"[inchess]"+chessClientName);
}
}
catch(Exceptionec)
{
isGameConnected=false;
isOnChess=false;
isServer=false;
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
controlpad.cancelGameButton.setEnabled(false);
ec.printStackTrace();
chatpad.chatLineArea.setText("chesspad.connectServer没法毗连
"+ec);
}

}
if(e.getSource()==controlpad.cancelGameButton)
{
if(isOnChess)
{
chesspad.chessthread.sendMessage("/giveup"+chessClientName);
chesspad.chessVictory(-1*chesspad.chessColor);
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
controlpad.cancelGameButton.setEnabled(false);
chesspad.statusText.setText("请创建游戏大概到场游戏");
}
if(!isOnChess)
{
controlpad.creatGameButton.setEnabled(true);
controlpad.joinGameButton.setEnabled(true);
controlpad.cancelGameButton.setEnabled(false);
chesspad.statusText.setText("请创建游戏大概到场游戏");
}
isClient=isServer=false;
}

}



publicvoidkeyPressed(KeyEvente)
{
TextFieldinputWords=(TextField)e.getSource();


if(e.getKeyCode()==KeyEvent.VK_ENTER)
{
if(inputpad.userChoice.getSelectedItem().equals("一切人"))
{
try
{
out.writeUTF(inputWords.getText());
inputWords.setText("");
}
catch(Exceptionea)
{
chatpad.chatLineArea.setText("chessClient:KeyPressed没法毗连,倡议从头毗连
");
userpad.userList.removeAll();
inputpad.userChoice.removeAll();
inputWords.setText("");
controlpad.connectButton.setEnabled(true);
}
}
else
{
try
{
out.writeUTF("/"+inputpad.userChoice.getSelectedItem()+""+inputWords.getText());
inputWords.setText("");
}
catch(Exceptionea)
{
chatpad.chatLineArea.setText("chessClient:KeyPressed没法毗连,倡议从头毗连
");
userpad.userList.removeAll();
inputpad.userChoice.removeAll();
inputWords.setText("");
controlpad.connectButton.setEnabled(true);
}
}
}

}

publicvoidkeyTyped(KeyEvente)
{
}
publicvoidkeyReleased(KeyEvente)
{
}



publicstaticvoidmain(Stringargs[])
{
chessClientchessClient=newchessClient();
}
}






/******************************************************************************************
上面是:chessInteface.java
******************************************************************************************/

importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjava.net.*;

classuserPadextendsPanel
{
ListuserList=newList(10);

userPad()
{
setLayout(newBorderLayout());

for(inti=0;i<50;i++)
{
userList.add(i+"."+"没有效户");
}
add(userList,BorderLayout.CENTER);

}

}

classchatPadextendsPanel
{
TextAreachatLineArea=newTextArea("",18,30,TextArea.SCROLLBARS_VERTICAL_ONLY);

chatPad()
{
setLayout(newBorderLayout());

add(chatLineArea,BorderLayout.CENTER);
}

}



classcontrolPadextendsPanel
{
LabelIPlabel=newLabel("IP",Label.LEFT);
TextFieldinputIP=newTextField("localhost",10);
ButtonconnectButton=newButton("毗连主机");
ButtoncreatGameButton=newButton("创建游戏");
ButtonjoinGameButton=newButton("到场游戏");
ButtoncancelGameButton=newButton("保持游戏");
ButtonexitGameButton=newButton("封闭程序");

controlPad()
{
setLayout(newFlowLayout(FlowLayout.LEFT));
setBackground(Color.pink);

add(IPlabel);
add(inputIP);
add(connectButton);
add(creatGameButton);
add(joinGameButton);
add(cancelGameButton);
add(exitGameButton);
}

}

classinputPadextendsPanel
{
TextFieldinputWords=newTextField("",40);
ChoiceuserChoice=newChoice();

inputPad()
{
setLayout(newFlowLayout(FlowLayout.LEFT));
for(inti=0;i<50;i++)
{
userChoice.addItem(i+"."+"没有效户");
}
userChoice.setSize(60,24);
add(userChoice);
add(inputWords);
}
}



/**********************************************************************************************
上面是:chessPad.java
**********************************************************************************************/
importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjava.net.*;
importjava.util.*;

classchessThreadextendsThread
{
chessPadchesspad;

chessThread(chessPadchesspad)
{
this.chesspad=chesspad;
}

publicvoidsendMessage(StringsndMessage)
{
try
{
chesspad.outData.writeUTF(sndMessage);
}
catch(Exceptionea)
{
System.out.println("chessThread.sendMessage:"+ea);
}
}


publicvoidacceptMessage(StringrecMessage)
{
if(recMessage.startsWith("/chess"))
{
StringTokenizeruserToken=newStringTokenizer(recMessage,"");
StringchessToken;
String[]chessOpt={"-1","-1","0"};
intchessOptNum=0;

while(userToken.hasMoreTokens())
{
chessToken=(String)userToken.nextToken("");
if(chessOptNum>=1&&chessOptNum<=3)
{
chessOpt[chessOptNum-1]=chessToken;

}
chessOptNum++;
}
chesspad.netChessPaint(Integer.parseInt(chessOpt[0]),Integer.parseInt(chessOpt[1]),Integer.parseInt(chessOpt[2]));

}
elseif(recMessage.startsWith("/yourname"))
{
chesspad.chessSelfName=recMessage.substring(10);
}
elseif(recMessage.equals("/error"))
{
chesspad.statusText.setText("毛病:没有这个用户,请加入程序,从头到场");
}
else
{
//System.out.println(recMessage);
}
}


publicvoidrun()
{
Stringmessage="";
try
{
while(true)
{
message=chesspad.inData.readUTF();
acceptMessage(message);
}
}
catch(IOExceptiones)
{
}
}

}




classchessPadextendsPanelimplementsMouseListener,ActionListener
{
intchessPoint_x=-1,chessPoint_y=-1,chessColor=1;
intchessBlack_x[]=newint[200];
intchessBlack_y[]=newint[200];
intchessWhite_x[]=newint[200];
intchessWhite_y[]=newint[200];
intchessBlackCount=0,chessWhiteCount=0;
intchessBlackWin=0,chessWhiteWin=0;
booleanisMouseEnabled=false,isWin=false,isInGame=false;
TextFieldstatusText=newTextField("请先毗连服务器");

SocketchessSocket;
DataInputStreaminData;
DataOutputStreamoutData;

StringchessSelfName=null;
StringchessPeerName=null;
Stringhost=null;
intport=4331;
chessThreadchessthread=newchessThread(this);

chessPad()
{
setSize(440,440);
setLayout(null);
setBackground(Color.pink);
addMouseListener(this);
add(statusText);
statusText.setBounds(40,5,360,24);
statusText.setEditable(false);
}


publicbooleanconnectServer(StringServerIP,intServerPort)throwsException
{
try
{
chessSocket=newSocket(ServerIP,ServerPort);
inData=newDataInputStream(chessSocket.getInputStream());
outData=newDataOutputStream(chessSocket.getOutputStream());
chessthread.start();
returntrue;
}
catch(IOExceptionex)
{
statusText.setText("chessPad:connectServer:没法毗连
");
}
returnfalse;
}


publicvoidchessVictory(intchessColorWin)
{
this.removeAll();
for(inti=0;i<=chessBlackCount;i++)
{
chessBlack_x[i]=0;
chessBlack_y[i]=0;
}
for(inti=0;i<=chessWhiteCount;i++)
{
chessWhite_x[i]=0;
chessWhite_y[i]=0;
}
chessBlackCount=0;
chessWhiteCount=0;
add(statusText);
statusText.setBounds(40,5,360,24);

if(chessColorWin==1)
{chessBlackWin++;
statusText.setText("黑棋胜,黑:白为"+chessBlackWin+":"+chessWhiteWin+",从头残局,守候白棋下子...");
}
elseif(chessColorWin==-1)
{
chessWhiteWin++;
statusText.setText("白棋胜,黑:白为"+chessBlackWin+":"+chessWhiteWin+",从头残局,守候黑棋下子...");
}
}



publicvoidgetLocation(inta,intb,intcolor)
{

if(color==1)
{
chessBlack_x[chessBlackCount]=a*20;
chessBlack_y[chessBlackCount]=b*20;
chessBlackCount++;
}
elseif(color==-1)
{
chessWhite_x[chessWhiteCount]=a*20;
chessWhite_y[chessWhiteCount]=b*20;
chessWhiteCount++;
}
}


publicbooleancheckWin(inta,intb,intcheckColor)
{
intstep=1,chessLink=1,chessLinkTest=1,chessCompare=0;
if(checkColor==1)
{
chessLink=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if(((a+step)*20==chessBlack_x[chessCompare])&&((b*20)==chessBlack_y[chessCompare]))
{
chessLink=chessLink+1;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if(((a-step)*20==chessBlack_x[chessCompare])&&(b*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
chessLink=1;
chessLinkTest=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if((a*20==chessBlack_x[chessCompare])&&((b+step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if((a*20==chessBlack_x[chessCompare])&&((b-step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
chessLink=1;
chessLinkTest=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if(((a-step)*20==chessBlack_x[chessCompare])&&((b+step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if(((a+step)*20==chessBlack_x[chessCompare])&&((b-step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
chessLink=1;
chessLinkTest=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if(((a+step)*20==chessBlack_x[chessCompare])&&((b+step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessBlackCount;chessCompare++)
{
if(((a-step)*20==chessBlack_x[chessCompare])&&((b-step)*20==chessBlack_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
}
elseif(checkColor==-1)
{
chessLink=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessWhiteCount;chessCompare++)
{
if(((a+step)*20==chessWhite_x[chessCompare])&&(b*20==chessWhite_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessWhiteCount;chessCompare++)
{
if(((a-step)*20==chessWhite_x[chessCompare])&&(b*20==chessWhite_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
chessLink=1;
chessLinkTest=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessWhiteCount;chessCompare++)
{
if((a*20==chessWhite_x[chessCompare])&&((b+step)*20==chessWhite_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessWhiteCount;chessCompare++)
{
if((a*20==chessWhite_x[chessCompare])&&((b-step)*20==chessWhite_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
chessLink=1;
chessLinkTest=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessWhiteCount;chessCompare++)
{
if(((a-step)*20==chessWhite_x[chessCompare])&&((b+step)*20==chessWhite_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessWhiteCount;chessCompare++)
{
if(((a+step)*20==chessWhite_x[chessCompare])&&((b-step)*20==chessWhite_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
chessLink=1;
chessLinkTest=1;
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessWhiteCount;chessCompare++)
{
if(((a+step)*20==chessWhite_x[chessCompare])&&((b+step)*20==chessWhite_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
for(step=1;step<=4;step++)
{
for(chessCompare=0;chessCompare<=chessWhiteCount;chessCompare++)
{
if(((a-step)*20==chessWhite_x[chessCompare])&&((b-step)*20==chessWhite_y[chessCompare]))
{
chessLink++;
if(chessLink==5)
{
return(true);
}
}
}
if(chessLink==(chessLinkTest+1))
chessLinkTest++;
else
break;
}
}
return(false);
}





publicvoidpaint(Graphicsg)
{
for(inti=40;i<=380;i=i+20)
{
g.drawLine(40,i,400,i);
}
g.drawLine(40,400,400,400);
for(intj=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);
}


publicvoidchessPaint(intchessPoint_a,intchessPoint_b,intcolor)
{
chessPoint_blackchesspoint_black=newchessPoint_black(this);
chessPoint_whitechesspoint_white=newchessPoint_white(this);

if(color==1&&isMouseEnabled)
{
getLocation(chessPoint_a,chessPoint_b,color);
isWin=checkWin(chessPoint_a,chessPoint_b,color);
if(isWin==false)
{
chessthread.sendMessage("/"+chessPeerName+"/chess"+chessPoint_a+""+chessPoint_b+""+color);
this.add(chesspoint_black);
chesspoint_black.setBounds(chessPoint_a*20-7,chessPoint_b*20-7,16,16);
statusText.setText("黑(第"+chessBlackCount+"步)"+chessPoint_a+""+chessPoint_b+",请白棋下子");
isMouseEnabled=false;
}
else
{
chessthread.sendMessage("/"+chessPeerName+"/chess"+chessPoint_a+""+chessPoint_b+""+color);
this.add(chesspoint_black);
chesspoint_black.setBounds(chessPoint_a*20-7,chessPoint_b*20-7,16,16);
chessVictory(1);
isMouseEnabled=false;
}
}
elseif(color==-1&&isMouseEnabled)
{
getLocation(chessPoint_a,chessPoint_b,color);
isWin=checkWin(chessPoint_a,chessPoint_b,color);
if(isWin==false)
{
chessthread.sendMessage("/"+chessPeerName+"/chess"+chessPoint_a+""+chessPoint_b+""+color);
this.add(chesspoint_white);
chesspoint_white.setBounds(chessPoint_a*20-7,chessPoint_b*20-7,16,16);
statusText.setText("白(第"+chessWhiteCount+"步)"+chessPoint_a+""+chessPoint_b+",请黑棋下子");
isMouseEnabled=false;
}
else
{
chessthread.sendMessage("/"+chessPeerName+"/chess"+chessPoint_a+""+chessPoint_b+""+color);
this.add(chesspoint_white);
chesspoint_white.setBounds(chessPoint_a*20-7,chessPoint_b*20-7,16,16);
chessVictory(-1);
isMouseEnabled=false;
}
}
}


publicvoidnetChessPaint(intchessPoint_a,intchessPoint_b,intcolor)
{
chessPoint_blackchesspoint_black=newchessPoint_black(this);
chessPoint_whitechesspoint_white=newchessPoint_white(this);
getLocation(chessPoint_a,chessPoint_b,color);
if(color==1)
{
isWin=checkWin(chessPoint_a,chessPoint_b,color);
if(isWin==false)
{

this.add(chesspoint_black);
chesspoint_black.setBounds(chessPoint_a*20-7,chessPoint_b*20-7,16,16);
statusText.setText("黑(第"+chessBlackCount+"步)"+chessPoint_a+""+chessPoint_b+",请白棋下子");
isMouseEnabled=true;
}
else
{
this.add(chesspoint_black);
chesspoint_black.setBounds(chessPoint_a*20-7,chessPoint_b*20-7,16,16);
chessVictory(1);
isMouseEnabled=true;
}
}
elseif(color==-1)
{
isWin=checkWin(chessPoint_a,chessPoint_b,color);
if(isWin==false)
{
this.add(chesspoint_white);
chesspoint_white.setBounds(chessPoint_a*20-7,chessPoint_b*20-7,16,16);
statusText.setText("白(第"+chessWhiteCount+"步)"+chessPoint_a+""+chessPoint_b+",请黑棋下子");
isMouseEnabled=true;
}
else
{
chessthread.sendMessage("/"+chessPeerName+"/victory"+color);
this.add(chesspoint_white);
chesspoint_white.setBounds(chessPoint_a*20-7,chessPoint_b*20-7,16,16);
chessVictory(-1);
isMouseEnabled=true;
}
}
}


publicvoidmousePressed(MouseEvente)
{
if(e.getModifiers()==InputEvent.BUTTON1_MASK)
{
chessPoint_x=(int)e.getX();
chessPoint_y=(int)e.getY();
inta=(chessPoint_x+10)/20,b=(chessPoint_y+10)/20;
if(chessPoint_x/20<2||chessPoint_y/20<2||chessPoint_x/20>19||chessPoint_y/20>19)
{}
else
{
chessPaint(a,b,chessColor);
}
}
}

publicvoidmouseReleased(MouseEvente){}
publicvoidmouseEntered(MouseEvente){}
publicvoidmouseExited(MouseEvente){}
publicvoidmouseClicked(MouseEvente){}

publicvoidactionPerformed(ActionEvente)
{

}
}


classchessPoint_blackextendsCanvasimplementsMouseListener
{
chessPadchesspad=null;
chessPoint_black(chessPadp)
{
setSize(20,20);
chesspad=p;
addMouseListener(this);
}

publicvoidpaint(Graphicsg)
{
g.setColor(Color.black);
g.fillOval(0,0,14,14);
}

publicvoidmousePressed(MouseEvente)
{
//if(e.getModifiers()==InputEvent.BUTTON3_MASK)
//{
//chesspad.remove(this);
//chesspad.chessColor=1;
//chesspad.text_2.setText("");
//chesspad.text_1.setText("请黑棋下子");
//}
}
publicvoidmouseReleased(MouseEvente){}
publicvoidmouseEntered(MouseEvente){}
publicvoidmouseExited(MouseEvente){}
publicvoidmouseClicked(MouseEvente){}
}


classchessPoint_whiteextendsCanvasimplementsMouseListener
{
chessPadchesspad=null;
chessPoint_white(chessPadp)
{
setSize(20,20);
addMouseListener(this);
chesspad=p;
}

publicvoidpaint(Graphicsg)
{
g.setColor(Color.white);
g.fillOval(0,0,14,14);
}

publicvoidmousePressed(MouseEvente)
{
//if(e.getModifiers()==InputEvent.BUTTON3_MASK)
//{
//chesspad.remove(this);
//chesspad.chessColor=-1;
//chesspad.text_2.setText("请白旗下子");
//chesspad.text_1.setText("");
//}
}
publicvoidmouseReleased(MouseEvente){}
publicvoidmouseEntered(MouseEvente){}
publicvoidmouseExited(MouseEvente){}
publicvoidmouseClicked(MouseEvente)
{
//if(e.getClickCount()>=2)
//chesspad.remove(this);
}
}


/******************************************************************************************
最初是:chessServer.java
*******************************************************************************************/
importjava.io.*;
importjava.net.*;
importjava.awt.*;
importjava.util.*;
importjava.awt.event.*;

classMessageServerextendsPanel//implementsActionListener
{
TextAreamessageBoard=newTextArea("",22,50,TextArea.SCROLLBARS_VERTICAL_ONLY);
LabelstatusLabel=newLabel("以后毗连数:",Label.LEFT);
PanelboardPanel=newPanel();
PanelstatusPanel=newPanel();

MessageServer()
{
setSize(350,300);
setBackground(Color.pink);
setLayout(newBorderLayout());
boardPanel.setLayout(newFlowLayout());
boardPanel.setSize(210,210);
statusPanel.setLayout(newBorderLayout());
statusPanel.setSize(210,50);
boardPanel.add(messageBoard);
statusPanel.add(statusLabel,BorderLayout.WEST);
add(boardPanel,BorderLayout.CENTER);
add(statusPanel,BorderLayout.NORTH);
}
}


classServerThreadextendsThread
{
SocketclientSocket;
HashtableclientDataHash;
HashtableclientNameHash;
HashtablechessPeerHash;
MessageServerserver;

booleanisClientClosed=false;

ServerThread(SocketclientSocket,HashtableclientDataHash,HashtableclientNameHash,HashtablechessPeerHash,MessageServerserver)
{
this.clientSocket=clientSocket;
this.clientDataHash=clientDataHash;
this.clientNameHash=clientNameHash;
this.chessPeerHash=chessPeerHash;
this.server=server;
}



publicvoidmessageTransfer(Stringmessage)
{
StringclientName,peerName;

if(message.startsWith("/"))
{

if(message.startsWith("/changename"))
{
clientName=message.substring(12);
if(clientName.length()<=0||clientName.length()>20||
clientName.startsWith("/")||clientNameHash.containsValue(clientName)||
clientName.startsWith("changename")||clientName.startsWith("list")||
clientName.startsWith("[inchess]")||clientName.startsWith("creatgame")||
clientName.startsWith("joingame")||clientName.startsWith("yourname")||
clientName.startsWith("userlist")||clientName.startsWith("chess")||
clientName.startsWith("OK")||clientName.startsWith("reject")||
clientName.startsWith("peer")||clientName.startsWith("peername")||
clientName.startsWith("giveup")||clientName.startsWith("youwin")||
clientName.startsWith("一切人"))
{
message="有效命令";
Feedback(message);
}
else
{
if(clientNameHash.containsValue(("[inchess]"+(String)clientNameHash.get(clientSocket))))
{
synchronized(clientNameHash)
{
clientNameHash.put((Socket)getHashKey(clientNameHash,("[inchess]"+clientNameHash.get(clientSocket))),
("[inchess]"+clientName));
chessPeerTalk(("[inchess]"+clientName),("/yourname"+("[inchess]"+clientName)));
}
}
elseif(chessPeerHash.containsKey(clientNameHash.get(clientSocket)))
{
//游戏客户端更名字
synchronized(clientNameHash)
{
clientNameHash.put((Socket)getHashKey(clientNameHash,("[inchess]"+clientNameHash.get(clientSocket))),
("[inchess]"+clientName));
}

synchronized(chessPeerHash)
{
//chessPeerHash增加新名字映照
chessPeerHash.put(clientName,chessPeerHash.get(clientNameHash.get(clientSocket)));
//chessPeerHash删除旧映照
chessPeerHash.remove(clientNameHash.get(clientSocket));
}
//向游戏客户端发送新名字
chessPeerTalk(("[inchess]"+clientName),("/yourname"+("[inchess]"+clientName)));
//向peer游戏客户端发送
chessPeerTalk((String)chessPeerHash.get(clientName),("/peer"+"[inchess]"+clientName));

}
elseif(chessPeerHash.containsValue(clientNameHash.get(clientSocket)))
{
synchronized(clientNameHash)
{
//游戏客户端更名字
clientNameHash.put((Socket)getHashKey(clientNameHash,("[inchess]"+clientNameHash.get(clientSocket))),
("[inchess]"+clientName));
}
synchronized(chessPeerHash)
{
//chessPeerHash从头映照
chessPeerHash.put((String)getHashKey(chessPeerHash,clientNameHash.get(clientSocket)),clientName);
//向游戏客户端发送新名字
chessPeerTalk(("[inchess]"+clientName),("/yourname"+("[inchess]"+clientName)));
}
//向peer游戏客户端发送
chessPeerTalk((String)getHashKey(chessPeerHash,clientName),("/peer"+"[inchess]"+clientName));

}

message=clientNameHash.get(clientSocket)+"更名为:"+clientName;
synchronized(clientNameHash)
{
clientNameHash.put(clientSocket,clientName);
}
publicTalk(message);
Feedback("/yourname"+(String)clientNameHash.get(clientSocket));
publicTalk(getUserList());

}

}
elseif(message.equals("/list"))
{
Feedback(getUserList());
}
elseif(message.startsWith("/creatgame[inchess]"))
{
StringchessServerName=message.substring(20);
synchronized(clientNameHash)
{
clientNameHash.put(clientSocket,message.substring(11));
}
synchronized(chessPeerHash)
{
chessPeerHash.put(chessServerName,"wait");
}
Feedback("/yourname"+clientNameHash.get(clientSocket));
chessPeerTalk(chessServerName,"/OK");
publicTalk(getUserList());
}
elseif(message.startsWith("/joingame"))
{
StringTokenizeruserToken=newStringTokenizer(message,"");
StringgetUserToken,serverName,selfName;
String[]chessNameOpt={"0","0"};
intgetOptNum=0;

while(userToken.hasMoreTokens())
{
getUserToken=(String)userToken.nextToken("");
if(getOptNum>=1&&getOptNum<=2)
{
chessNameOpt[getOptNum-1]=getUserToken;
}
getOptNum++;
}
serverName=chessNameOpt[0];
selfName=chessNameOpt[1];

if(chessPeerHash.containsKey(serverName)&&chessPeerHash.get(serverName).equals("wait"))
{
synchronized(clientNameHash)
{
clientNameHash.put(clientSocket,("[inchess]"+selfName));
}
synchronized(chessPeerHash)
{
chessPeerHash.put(serverName,selfName);
}
publicTalk(getUserList());
chessPeerTalk(selfName,("/peer"+"[inchess]"+serverName));
chessPeerTalk(serverName,("/peer"+"[inchess]"+selfName));
}
else
{
chessPeerTalk(selfName,"/reject");
try
{
clientClose();
}
catch(Exceptionez)
{
}
}
}
elseif(message.startsWith("/[inchess]"))
{
intfirstLocation=0,lastLocation;

lastLocation=message.indexOf("",0);

peerName=message.substring((firstLocation+1),lastLocation);
message=message.substring((lastLocation+1));
if(chessPeerTalk(peerName,message))
{
Feedback("/error");
}
}
elseif(message.startsWith("/giveup"))
{
StringchessClientName=message.substring(8);
if(chessPeerHash.containsKey(chessClientName)&&!((String)chessPeerHash.get(chessClientName)).equals("wait"))
{
chessPeerTalk((String)chessPeerHash.get(chessClientName),"/youwin");
synchronized(chessPeerHash)
{
chessPeerHash.remove(chessClientName);
}
}
if(chessPeerHash.containsValue(chessClientName))
{
chessPeerTalk((String)getHashKey(chessPeerHash,chessClientName),"/youwin");
synchronized(chessPeerHash)
{
chessPeerHash.remove((String)getHashKey(chessPeerHash,chessClientName));
}
}
}
else
{

intfirstLocation=0,lastLocation;

lastLocation=message.indexOf("",0);
if(lastLocation==-1)
{
Feedback("有效命令");
return;
}
else
{
peerName=message.substring((firstLocation+1),lastLocation);
message=message.substring((lastLocation+1));
message=(String)clientNameHash.get(clientSocket)+">"+message;
if(peerTalk(peerName,message))
{
Feedback("没有这个用户:"+peerName+"
");
}
}

}

}

else
{
message=clientNameHash.get(clientSocket)+">"+message;
server.messageBoard.append(message+"
");
publicTalk(message);
server.messageBoard.setCaretPosition(server.messageBoard.getText().length());
}




}


publicvoidpublicTalk(StringpublicTalkMessage)
{

synchronized(clientDataHash)
{
for(Enumerationenu=clientDataHash.elements();enu.hasMoreElements();)
{
DataOutputStreamoutData=(DataOutputStream)enu.nextElement();
try
{
outData.writeUTF(publicTalkMessage);
}
catch(IOExceptiones)
{
es.printStackTrace();
}
}
}

}



publicbooleanpeerTalk(StringpeerTalk,StringtalkMessage)
{

for(Enumerationenu=clientDataHash.keys();enu.hasMoreElements();)
{
SocketuserClient=(Socket)enu.nextElement();

if(peerTalk.equals((String)clientNameHash.get(userClient))&&!peerTalk.equals((String)clientNameHash.get(clientSocket)))
{
synchronized(clientDataHash)
{
DataOutputStreampeerOutData=(DataOutputStream)clientDataHash.get(userClient);
try
{
peerOutData.writeUTF(talkMessage);
}
catch(IOExceptiones)
{
es.printStackTrace();
}
}
Feedback(talkMessage);
return(false);
}
elseif(peerTalk.equals((String)clientNameHash.get(clientSocket)))
{
Feedback(talkMessage);
return(false);
}
}


return(true);

}


publicbooleanchessPeerTalk(StringchessPeerTalk,StringchessTalkMessage)
{

for(Enumerationenu=clientDataHash.keys();enu.hasMoreElements();)
{
SocketuserClient=(Socket)enu.nextElement();

if(chessPeerTalk.equals((String)clientNameHash.get(userClient))&&!chessPeerTalk.equals((String)clientNameHash.get(clientSocket)))
{
synchronized(clientDataHash)
{
DataOutputStreampeerOutData=(DataOutputStream)clientDataHash.get(userClient);
try
{
peerOutData.writeUTF(chessTalkMessage);
}
catch(IOExceptiones)
{
es.printStackTrace();
}
}
return(false);
}
}
return(true);
}


publicvoidFeedback(StringfeedbackString)
{
synchronized(clientDataHash)
{
DataOutputStreamoutData=(DataOutputStream)clientDataHash.get(clientSocket);
try
{
outData.writeUTF(feedbackString);
}
catch(Exceptioneb)
{
eb.printStackTrace();
}
}

}



publicStringgetUserList()
{
StringuserList="/userlist";

for(Enumerationenu=clientNameHash.elements();enu.hasMoreElements();)
{
userList=userList+""+(String)enu.nextElement();
}
return(userList);
}


publicObjectgetHashKey(HashtabletargetHash,ObjecthashValue)
{
ObjecthashKey;
for(Enumerationenu=targetHash.keys();enu.hasMoreElements();)
{
hashKey=(Object)enu.nextElement();
if(hashValue.equals((Object)targetHash.get(hashKey)))
return(hashKey);
}
return(null);
}

publicvoidfirstCome()
{
publicTalk(getUserList());
Feedback("/yourname"+(String)clientNameHash.get(clientSocket));
Feedback("Java五子棋谈天客户端");
Feedback("/changename<你的名字>--变动名字");
Feedback("/list--更新用户列表");
Feedback("/<用户名><要说的话>--私聊");
Feedback("注重:用命令的时分,先把发言的对象定为一切人");
}



publicvoidclientClose()
{
server.messageBoard.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);
}
publicTalk(getUserList());
server.statusLabel.setText("以后毗连数:"+clientDataHash.size());
try
{
clientSocket.close();
}
catch(IOExceptionexx)
{
}

isClientClosed=true;

}


publicvoidrun()
{
DataInputStreaminData;
synchronized(clientDataHash)
{
server.statusLabel.setText("以后毗连数:"+clientDataHash.size());
}
try
{
inData=newDataInputStream(clientSocket.getInputStream());
firstCome();
while(true)
{
Stringmessage=inData.readUTF();
messageTransfer(message);
}
}
catch(IOExceptionesx)
{
}
finally
{
if(!isClientClosed)
{
clientClose();
}
}
}


}






publicclasschessServerextendsFrameimplementsActionListener
{

ButtonmessageClearButton=newButton("扫除显现");
ButtonserverStatusButton=newButton("服务器形态");
ButtonserverOffButton=newButton("封闭服务器");
PanelbuttonPanel=newPanel();

MessageServerserver=newMessageServer();
ServerSocketserverSocket;
HashtableclientDataHash=newHashtable(50);
HashtableclientNameHash=newHashtable(50);
HashtablechessPeerHash=newHashtable(50);

chessServer()
{
super("Java五子棋服务器");
setBackground(Color.pink);


buttonPanel.setLayout(newFlowLayout());
messageClearButton.setSize(60,25);
buttonPanel.add(messageClearButton);
messageClearButton.addActionListener(this);
serverStatusButton.setSize(75,25);
buttonPanel.add(serverStatusButton);
serverStatusButton.addActionListener(this);
serverOffButton.setSize(75,25);
buttonPanel.add(serverOffButton);
serverOffButton.addActionListener(this);

add(server,BorderLayout.CENTER);
add(buttonPanel,BorderLayout.SOUTH);

addWindowListener(newWindowAdapter()
{
publicvoidwindowClosing(WindowEvente)
{
System.exit(0);
}
});
pack();
setVisible(true);
setSize(400,450);
setResizable(false);
validate();
try
{
makeMessageServer(4331,server);
}
catch(Exceptione)
{
System.out.println("e");
}
}

publicvoidmakeMessageServer(intport,MessageServerserver)throwsIOException
{
SocketclientSocket;
longclientAccessNumber=1;
this.server=server;

try
{
serverSocket=newServerSocket(port);
server.messageBoard.setText("服务器入手下手于:"+serverSocket.getInetAddress().getLocalHost()+":"+serverSocket.getLocalPort()+"
");

while(true)
{
clientSocket=serverSocket.accept();
server.messageBoard.append("用户毗连:"+clientSocket+"
");

DataOutputStreamoutData=newDataOutputStream(clientSocket.getOutputStream());

clientDataHash.put(clientSocket,outData);
clientNameHash.put(clientSocket,("新来客"+clientAccessNumber++));

ServerThreadthread=newServerThread(clientSocket,clientDataHash,clientNameHash,chessPeerHash,server);

thread.start();
}
}
catch(IOExceptionex)
{
System.out.println("已有服务器在运转.
");
}


}

publicvoidactionPerformed(ActionEvente)
{
if(e.getSource()==messageClearButton)
{
server.messageBoard.setText("");
}
if(e.getSource()==serverStatusButton)
{
try
{
server.messageBoard.append("服务器信息:"+serverSocket.getInetAddress().getLocalHost()+":"+serverSocket.getLocalPort()+"
");
}
catch(Exceptionee)
{
System.out.println("serverSocket.getInetAddress().getLocalHost()error
");
}
}
if(e.getSource()==serverOffButton)
{
System.exit(0);
}
}

publicstaticvoidmain(Stringargs[])
{
chessServerchessServer=newchessServer();
}
}




对于一个大型项目,如果用java来作,可能需要9个月,并且可能需要翻阅10本以上的书,但如果用ruby来作,3个月,3本书就足够了,而.net也不过3,4本书足以,这就是区别。
小妖女 该用户已被删除
沙发
发表于 2015-1-29 13:46:23 | 只看该作者
还好,SUN提供了Javabean可以把你的JSP中的 Java代码封装起来,便于调用也便于重用。
简单生活 该用户已被删除
板凳
发表于 2015-2-5 16:13:37 | 只看该作者
吧,现在很流行的Structs就是它的一种实现方式,不过Structs用起来实在是很繁,我们只要学习其精髓即可,我们完全可以设计自己的MVC结构。然后你再研究一下软件Refactoring (重构)和极限XP编程,相信你又会上一个台阶。 做完这些,你不如整理一下你的Java代码,把那些经典的程序和常见的应用整理出来,再精心打造一番,提高其重用性和可扩展性。你再找几个志同道合的朋友成立一个工作室吧
愤怒的大鸟 该用户已被删除
地板
发表于 2015-2-12 22:48:12 | 只看该作者
任职于太阳微系统的詹姆斯·高斯林等人于1990年代初开发Java语言的雏形,最初被命名为Oak,目标设置在家用电器等小型系统的程序语言
admin 该用户已被删除
5#
发表于 2015-2-20 10:51:13 | 只看该作者
你就该学一学Servlet了。Servlet就是服务器端小程序,他负责生成发送给客户端的HTML文件。JSP在执行时,也是先转换成Servlet再运行的。虽说JSP理论上可以完全取代Servlet,这也是SUN推出JSP的本意,可是Servlet用来控制流程跳转还是挺方便的,也令程序更清晰。接下来你应该学习一下Javabean了,可能你早就看不管JSP在HTML中嵌Java代码的混乱方式了,这种方式跟ASP又有什么区别呢?
爱飞 该用户已被删除
6#
发表于 2015-3-6 16:56:41 | 只看该作者
让你能够真正掌握接口或抽象类的应用,从而在原来的Java语言基础上跃进一步,更重要的是,设计模式反复向你强调一个宗旨:要让你的程序尽可能的可重用。
只想知道 该用户已被删除
7#
发表于 2015-3-13 04:21:52 | 只看该作者
如果你学过HTML,那么事情要好办的多,如果没有,那你快去补一补HTML基础吧。其实JSP中的Java语法也不多,它更象一个脚本语言,有点象ASP。
分手快乐 该用户已被删除
8#
发表于 2015-3-14 05:20:50 | 只看该作者
科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
因胸联盟 该用户已被删除
9#
发表于 2015-3-16 03:59:00 | 只看该作者
Java自面世后就非常流行,发展迅速,对C++语言形成了有力冲击。Java 技术具有卓越的通用性、高效性、平台移植性和安全性,广泛应用于个人PC、数据中心、游戏控制台
小女巫 该用户已被删除
10#
发表于 2015-3-22 19:53:07 | 只看该作者
[url]http://www.jdon.com/[/url]去下载,或到同济技术论坛的服务器[url]ftp://nro.shtdu.edu.cn[/url]去下,安装上有什么问题,可以到论坛上去提问。
山那边是海 该用户已被删除
11#
发表于 2015-4-4 20:58:16 | 只看该作者
不过,每次的执行编译后的字节码需要消耗一定的时间,这同时也在一定程度上降低了 Java 程序的运行效率。
莫相离 该用户已被删除
12#
发表于 2015-4-5 04:47:14 | 只看该作者
吧,现在很流行的Structs就是它的一种实现方式,不过Structs用起来实在是很繁,我们只要学习其精髓即可,我们完全可以设计自己的MVC结构。然后你再研究一下软件Refactoring (重构)和极限XP编程,相信你又会上一个台阶。 做完这些,你不如整理一下你的Java代码,把那些经典的程序和常见的应用整理出来,再精心打造一番,提高其重用性和可扩展性。你再找几个志同道合的朋友成立一个工作室吧
若相依 该用户已被删除
13#
发表于 2015-4-12 23:35:11 | 只看该作者
那么我书也看了,程序也做了,别人问我的问题我都能解决了,是不是就成为高手了呢?当然没那么简单,这只是万里长征走完了第一步。不信?那你出去接一个项目,你知道怎么下手吗,你知道怎么设计吗,你知道怎么组织人员进行开发吗?你现在脑子里除了一些散乱的代码之外,可能再没有别的东西了吧!
第二个灵魂 该用户已被删除
14#
发表于 2015-5-5 02:36:53 | 只看该作者
Java 编程语言的风格十分接近C、C++语言。
冷月葬花魂 该用户已被删除
15#
 楼主| 发表于 2015-5-12 05:42:23 | 只看该作者
是一种突破用户端机器环境和CPU
小魔女 该用户已被删除
16#
发表于 2015-6-17 20:20:01 | 只看该作者
你可以去承接一些项目做了,一开始可能有些困难,可是你有技术积累,又考虑周全,接下项目来可以迅速作完,相信大家以后都会来找你的,所以Money就哗啦啦的。。。。。。
17#
发表于 2015-6-23 20:49:53 | 只看该作者
如果你学过HTML,那么事情要好办的多,如果没有,那你快去补一补HTML基础吧。其实JSP中的Java语法也不多,它更象一个脚本语言,有点象ASP。
蒙在股里 该用户已被删除
18#
发表于 2015-7-1 18:36:39 | 只看该作者
关于设计模式的资料,还是向大家推荐banq的网站 [url]http://www.jdon.com/[/url],他把GOF的23种模式以通俗易懂的方式诠释出来,纯Java描述,真是经典中的经典。
飘灵儿 该用户已被删除
19#
发表于 2015-7-7 02:32:08 | 只看该作者
是一种使用者不需花费很多时间学习的语言
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-3 18:58

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表