实验4计科.docx
- 文档编号:9664010
- 上传时间:2023-02-05
- 格式:DOCX
- 页数:43
- 大小:66.93KB
实验4计科.docx
《实验4计科.docx》由会员分享,可在线阅读,更多相关《实验4计科.docx(43页珍藏版)》请在冰豆网上搜索。
实验4计科
《Java程序设计》实验报告
年级、专业、班级
2011级计科3班
2011级计科3班
姓名
江唯伟
张桉
实验题目
网络白板的设计与实现
实验时间
2013.11.11
实验地点
主教0414
实验成绩
实验性质
□验证性□设计性■综合性
教师评价:
□算法/实验过程正确;□源程序/实验内容提交□程序结构/实验步骤合理;
□实验结果正确;□语法、语义正确;□报告规范;
其他:
评价教师签名:
一、实验目的
综合利用JavaGUI、JavaGraphics、多线程和网络技术编程实现网络白板程序。
网络白板是一种基于网络的程序,用户可以通过该程序将文字、图片等传输给其他用户查看。
二、实验项目内容
1、根据系统要求,完成系统需求分析。
2、设计并实现相关的数据交换协议。
3、设计并实现相应的数据同步协议。
4、实现简单的图元,如文字以及简单的几何图形的绘制。
5、实现简单图元的网络传输,以及用户之间的文字交流。
6、按照实验要求,更强大的功能活动更多的分数。
三、实验过程或算法(源程序)
要求:
写明设计思想、程序的结构、功能关系图、类的说明并按照UML的规范画出类之间的关系图、程序执行流程图,最后是源代码。
设计思想:
服务器:
创建对象输入输出流
实现网络通信
handleMessage
处理所有对基本图形的操作的消息
接收到客户端添加基本图形消息:
1.将添加对象加入到白板已有对象的类中
2.通知所有客户添加图形对象
用户移动图形的消息处理:
1.将原来位置的对象提取出来
2.添加到要被删除的列表中
3.通知所有客户更新画板
用户退出的消息处理
登陆界面比较简单,采取自定义布局。
程序的结构:
src文件夹里包含mywb文件夹和images文件夹,其中mywb文件夹中有23个java项目文件。
功能关系图:
部分UML图:
FillOvalObj():
setPara()
getType()
getBounds()
paint()
getColor()
LoginFrame():
LoginFrame()
init()
actionPerformed()
LoginMessage():
LoginMessage()
getList()
getRlines()
getId()
PaintObjects():
add()
addElementWithID()
replaceObject()
replaceObjWithID()
getObjectId()
elements()
clone()
ServerAddObjMessage():
ServerAddObjMessage()
getID()
getElement()
ServerReplacedMessage():
ServerReplacedMessage()
getOldID()
getID()
getObject()
WhiteBoardFrame():
WhiteBoardFrame()
init()
jbInit()
addMouseListener()
status()
destroy()
getLocalIP()
WhiteBoardPanel():
WhiteBoardPanel()
setType()
WBMouseListener()
mouseReleased()
WBMouseMotionListener()
setColor()
paint()
WhiteBoardServer():
WhiteBoardServer()
run()
handle()
handleMessage()
NotifyRanLine()
notifyAll()
WhiteBoardThread():
WhiteBoardThread()
run()
readMessage()
程序执行流程图:
开始
↓
输入姓名,可更改IP和端口
↓
选择自己喜欢的图形和颜色进行绘画
↓
退出
源代码:
主要代码如下:
WhiteBoardFrame:
publicclassWhiteBoardFrameextendsJFrame{
privateStringserIp=null;
privateStringserPort=null;
privateStringmyName=null;
publicbooleanactive=false;
privateBorderLayoutborderLayout1=newBorderLayout();
privateBorderLayoutborderLayout2=newBorderLayout();
privateBorderLayoutborderLayout3=newBorderLayout();
privateBorderLayoutborderLayout4=newBorderLayout();
privateBorderLayoutborderLayout5=newBorderLayout();
privateBorderLayoutborderLayout6=newBorderLayout();
privateBorderLayoutborderLayout7=newBorderLayout();
privateBorderLayoutborderLayout8=newBorderLayout();
privateBorderLayoutborderLayout9=newBorderLayout();
privateBorderLayoutborderLayout10=newBorderLayout();
privateBorderLayoutborderLayout11=newBorderLayout();
privateBorderLayoutborderLayout12=newBorderLayout();
privateBorderLayoutborderLayout13=newBorderLayout();
privateBorderLayoutborderLayout14=newBorderLayout();
privateBorderLayoutborderLayout15=newBorderLayout();
privateGridLayoutgridLayout1=newGridLayout();
privateGridLayoutgridLayout2=newGridLayout();
privateGridLayoutgridLayout3=newGridLayout();
privateGridLayoutgridLayout4=newGridLayout();
privateJPaneljPanel1=newJPanel();
privateJPaneljPanel2=newJPanel();
privateJPaneljPanel3=newJPanel();
privateJPaneljPanel4=newJPanel();
privateJPaneljPanel5=newJPanel();
privateJPaneljPanel6=newJPanel();
privateJPaneljPanel7=newJPanel();
privateJPaneljPanel8=newJPanel();
privateJPaneljPanel9=newJPanel();
privateJPanelselPane=newJPanel();
privateJPanelranLinePane=newJPanel();
privateJPanelfrectPanel=newJPanel();
privateJPanelrrecPanel=newJPanel();
privateJPanelfovalPanel=newJPanel();
privateJPanelovalPanel=newJPanel();
privateJPanelfrecPanel=newJPanel();
privateJPanelrecPanel=newJPanel();
privateJPanellinePanel=newJPanel();
privateJPanelgrayColorPanel=newJPanel();
privateJPanelblueColorPanel=newJPanel();
privateJPanelcyanColorPanel=newJPanel();
privateJPanelmagentaColorPanel=newJPanel();
privateJPanelgreenColorPanel=newJPanel();
privateJPanelorangeColorPanel=newJPanel();
privateJPanelredColorPanel=newJPanel();
privateJPanelblackColorPanel=newJPanel();
privateJButtonselBut=newJButton();
privateJButtonlineBut=newJButton();
privateJButtonrecBut=newJButton();
privateJButtonfrecBut=newJButton();
privateJButtonovalBut=newJButton();
privateJButtonfovalBut=newJButton();
privateJButtonrrecBut=newJButton();
privateJButtonfrrecBut=newJButton();
privateJButtonrlineBut=newJButton();
privateJLabeljLabel2=newJLabel();
privateJLabeljLabel3=newJLabel();
privateJLabeljLabel4=newJLabel();
privateJLabeljLabel5=newJLabel();
privateJLabeljLabel6=newJLabel();
privateJLabeljLabel7=newJLabel();
privateStringpath="./images/line.gif";
privateImageIconlineimage=newImageIcon(getClass().getResource(path));
privateStringpath1="./images/rline.gif";
privateImageIconrlinimage=newImageIcon(getClass().getResource(path1));
privateStringpath2="./images/rect.gif";
privateImageIconrectimage=newImageIcon(getClass().getResource(path2));
privateStringpath3="./images/rrect.gif";
privateImageIconrrectimage=newImageIcon(getClass().getResource(path3));
privateStringpath4="./images/oval.gif";
privateImageIconovalimage=newImageIcon(getClass().getResource(path4));
privateStringpath5="./images/foval.gif";
privateImageIconfovalimage=newImageIcon(getClass().getResource(path5));
privateStringpath6="./images/frect.gif";
privateImageIconfrectimage=newImageIcon(getClass().getResource(path6));
privateStringpath8="./images/frrect.gif";
privateImageIconfrrectimage=newImageIcon(getClass().getResource(path8));
privateStringpath9="./images/select.gif";
privateImageIconselectimage=newImageIcon(getClass().getResource(path9));
publicSocketclientSocket=null;
staticStringmessage=null;
publicstaticinti;
publicintcolorindex;
publicColorcolor=null;
publicintcurrentTool=0;
publicintx0,y0,x1,y1,width,height;
publicintxold,yold,wold,hold;
publicClasscl;
publicElementelement=null;
publicVectorelements=newVector();
publicWhiteBoardPanelwhiteBoard=null;
publicstaticStringname="";
publicWhiteBoardFrame(StringserIp,StringserPort,Stringname){
this.serIp=serIp;
this.serPort=serPort;
this.myName=name;
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(ClassNotFoundExceptione1){
e1.printStackTrace();
}catch(InstantiationExceptione1){
e1.printStackTrace();
}catch(IllegalAccessExceptione1){
e1.printStackTrace();
}catch(UnsupportedLookAndFeelExceptione1){
e1.printStackTrace();
}
init();
}
publicvoidinit(){
try{
jbInit();
}catch(Exceptione){
e.printStackTrace();
return;
}
color=Color.gray;
try{
intport=Integer.parseInt(serPort);
clientSocket=newSocket(serIp,port);
whiteBoard=newWhiteBoardPanel(clientSocket);
whiteBoard.setBackground(Color.white);
whiteBoard.setType(currentTool);
jPanel2.add(whiteBoard,BorderLayout.CENTER);
whiteBoard.setColor(color);
status(currentTool,0);
}catch(Exceptionex){
ex.printStackTrace();
System.out.println("failedtoconnecttowbServer");
}
}
privatevoidjbInit()throwsException{
this.setLayout(borderLayout1);
jPanel1.setLayout(borderLayout2);
jPanel3.setLayout(borderLayout4);
jPanel1.setBackground(Color.white);
jPanel1.setPreferredSize(newDimension(80,300));
jPanel3.setBorder(BorderFactory.createEtchedBorder());
jPanel3.setPreferredSize(newDimension(80,300));
jPanel3.addMouseListener(newMouseAdapter(){
});
jPanel4.setLayout(borderLayout6);
jPanel5.setLayout(gridLayout2);
gridLayout2.setHgap
(2);
gridLayout2.setVgap
(2);
jPanel6.setBorder(BorderFactory.createEtchedBorder());
jPanel6.setPreferredSize(newDimension(10,200));
jPanel6.setLayout(borderLayout5);
jPanel7.setPreferredSize(newDimension(10,20));
jPanel7.setLayout(gridLayout3);
jLabel2.setForeground(SystemColor.desktop);
jLabel2.setPreferredSize(newDimension(20,18));
jLabel2.setText("工具");
jLabel4.setForeground(SystemColor.desktop);
jLabel4.setText("");
jLabel6.setForeground(SystemColor.desktop);
jLabel6.setText("颜色");
jPanel9.setLayout(gridLayout1);
jPanel8.setLayout(gridLayout4);
gridLayout4.setColumns
(2);
gridLayout4.setHgap
(1);
gridLayout4.setRows(0);
gridLayout4.setVgap
(1);
gridLayout1.setColumns
(2);
gridLayout1.setHgap
(1);
gridLayout1.setRows(0);
gridLayout1.setVgap
(1);
selPane.setBorder(BorderFactory.createLineBorder(Color.black));
selPane.setToolTipText("");
selPane.setLayout(borderLayout7);
selBut.addMouseListener(newMouseAdapter(){
publicvoidmousePressed(MouseEvente){
select_mousePressed(e);
}
});
frectPanel.setBorder(BorderFactory.createLineBorder(Color.black));
frectPanel.setLayout(borderLayout14);
frrecBut.addMouseListener(newMouseAdapter(){
publicvoidmousePressed(MouseEvente){
frrect_mousePressed(e);
}
});
ranLinePane.setBorder(BorderFactory.createLineBorder(Color.black));
ranLinePane.setLayout(borderLayout15);
rlineBut.addMouseListener(newMouseAdapter(){
publicvoidmousePressed(MouseEvente){
rline_mousePressed(e);
}
});
rrecPanel.setBorder(BorderFactory.createLineBorder(Color.black));
rrecPanel.setLayout(borderLayout13);
rrecBut.addMouseListener(newMouseAdapter(){
publicvoidmousePressed(MouseEvente){
rrect_mousePressed(e);
}
});
ovalPanel.setBorder(BorderFactory.createLineBorder(Color.black));
ovalPanel.setLayout(borderLayout11);
ova
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 实验
![提示](https://static.bdocx.com/images/bang_tan.gif)