java程序设计五子棋Word下载.docx

上传人:b****3 文档编号:14869016 上传时间:2022-10-25 格式:DOCX 页数:44 大小:29.01KB
下载 相关 举报
java程序设计五子棋Word下载.docx_第1页
第1页 / 共44页
java程序设计五子棋Word下载.docx_第2页
第2页 / 共44页
java程序设计五子棋Word下载.docx_第3页
第3页 / 共44页
java程序设计五子棋Word下载.docx_第4页
第4页 / 共44页
java程序设计五子棋Word下载.docx_第5页
第5页 / 共44页
点击查看更多>>
下载资源
资源描述

java程序设计五子棋Word下载.docx

《java程序设计五子棋Word下载.docx》由会员分享,可在线阅读,更多相关《java程序设计五子棋Word下载.docx(44页珍藏版)》请在冰豆网上搜索。

java程序设计五子棋Word下载.docx

this.chess_x=chess_x;

publicintgetChess_y(){

returnchess_y;

publicvoidsetChess_y(intchess_y){

this.chess_y=chess_y;

publicintgetState(){

returnstate;

publicvoidsetState(intstate){

this.state=state;

publicintgetId(){

returnid;

publicvoidsetId(intid){

this.id=id;

publicvoiddrawChess(Graphicsg){

Colorcolor=null;

if(state==1){

color=newColor(255,255,255);

g.setColor(color);

g.fillOval(chess_x*30-radius,chess_y*30-radius,radius*2,radius*2);

}elseif(state==-1){

color=newColor(0,0,0);

}

}

publicclassChessBoard{

int[][]board=newint[16][16];

publicChessBoard(){

initialBoard();

publicvoidinitialBoard(){

for(inti=0;

i<

board.length;

i++){

for(intj=0;

j<

board[i].length;

j++){

board[i][j]=0;

//0无棋1白棋-1黑棋

}

publicvoiddraw(Graphicsg){

g.drawLine(25,25,455,25);

g.drawLine(455,25,455,455);

g.drawLine(25,455,455,455);

g.drawLine(25,25,25,455);

inti=1,j=1;

while(i<

board.length){

g.drawLine(i*30,30,i*30,15*30);

i++;

while(j<

g.drawLine(30,j*30,15*30,j*30);

j++;

}

publicintgetState(intx,inty){

if(x>

0&

y>

x<

16&

y<

16)returnboard[x][y];

elsereturn-2;

publicvoidsetState(intx,inty,intstate){

board[x][y]=state;

importjava.awt.BorderLayout;

importjava.awt.Dimension;

importjava.awt.Image;

importjava.awt.TextArea;

importjava.awt.Toolkit;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.awt.event.KeyListener;

importjava.awt.event.WindowAdapter;

importjava.awt.event.WindowEvent;

importjava.io.IOException;

import.ServerSocket;

import.Socket;

importjava.sql.Time;

importjavax.swing.ImageIcon;

importjavax.swing.JButton;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

importjavax.swing.JMenu;

importjavax.swing.JMenuBar;

importjavax.swing.JMenuItem;

importjavax.swing.JOptionPane;

importjavax.swing.JPanel;

importjavax.swing.JSplitPane;

importjavax.swing.JTextField;

importjavax.swing.border.Border;

publicclassChessServerextendsJFrameimplementsActionListener{

publicstaticfinalintframe_width=35;

//窗体的宽度

publicstaticfinalintframe_height=27;

//窗体的高度

publicstaticfinalintframe_opration=10;

//操作区域的宽度

publicstaticfinalintblock_width=20;

//单位宽度

publicstaticfinalintblock_height=20;

//单位高度

ServerWarjpz=newServerWar(this);

//创建服务器端主面板

JMenuBarmenubar=newJMenuBar();

//创建菜单条

JMenuJMenu("

文件"

);

JMenuItemone=newJMenuItem("

单人游戏"

JMenuItemtwo=newJMenuItem("

双人游戏"

JMenuItemexit=newJMenuItem("

退出"

JPaneljpy=newJPanel();

//创建操作区的面板

JLabeljlPort=newJLabel("

端口号"

//创建提示用户输入端口号的标签

JTextFieldjtfPort=newJTextField("

9999"

//创建用于输入端口号的文本框,默认是9999

JLabeljlNickName=newJLabel("

昵称"

//创建用于提示输入昵称的标签

JTextFieldjtfNickName=newJTextField("

Player2"

//创建用于输入昵称的文本框

JButtonjbNew=newJButton("

建主"

//创建"

"

停止"

开始"

三个动作按钮

JButtonjbStop=newJButton("

JButtonjbStart=newJButton("

JButtonjbSend=newJButton("

发送"

TextAreajaChat=newTextArea("

"

5000,1,TextArea.SCROLLBARS_VERTICAL_ONLY);

inttextIndex=0;

JTextFieldjtfMessage=newJTextField("

你好"

JSplitPanejsp=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,jpz,jpy);

//创建JSplitPane

ServerSocketss;

//声明ServerSocket引用

ServerThreadst;

//声明服务器线程

ServerAgentThreadsat;

//声明服务器代理线程引用

publicChessServer(){

this.addComponent();

//初始化窗体,将控件添加到窗体中

this.addListener();

//为相应控件注册监听器

this.initialFrame();

//初始化窗体

jpz.setFocusable(true);

jpz.requestFocus(true);

//使左边面板获得焦点

publicvoidaddComponent(){//添加控件的方法

jpy.setLayout(null);

//设为空布局

jlPort.setBounds(10,20,40,25);

jpy.add(jlPort);

//添加"

标签

jtfPort.setBounds(55,20,100,25);

jpy.add(jtfPort);

//添加输入端口号的文本框

jlNickName.setBounds(10,50,40,25);

jpy.add(jlNickName);

昵称"

jtfNickName.setBounds(55,50,100,25);

jpy.add(jtfNickName);

//添加输入昵称的文本框

jbNew.setBounds(20,85,60,20);

jpy.add(jbNew);

按钮

jbStop.setBounds(100,85,60,20);

jpy.add(jbStop);

jbStart.setBounds(20,120,140,30);

jpy.add(jbStart);

jaChat.setBounds(10,230,160,205);

jaChat.setForeground(Color.blue);

ja

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 文学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1