




免费预览已结束,剩余25页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Java 程序设计实验报告年级、专业、班级2011级计科3班2011级计科3班姓名江唯伟张桉实验题目网络白板的设计与实现实验时间2013.11.11实验地点主教0414实验成绩 实验性质验证性 设计性 综合性教师评价:算法/实验过程正确; 源程序/实验内容提交 程序结构/实验步骤合理;实验结果正确; 语法、语义正确; 报告规范; 其他: 评价教师签名:一、实验目的综合利用Java GUI、Java Graphics、多线程和网络技术编程实现网络白板程序。网络白板是一种基于网络的程序,用户可以通过该程序将文字、图片等传输给其他用户查看。二、实验项目内容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:public class WhiteBoardFrame extends JFrame private String serIp = null; private String serPort =null; private String myName = null; public boolean active = false ; private BorderLayout borderLayout1 = new BorderLayout(); private BorderLayout borderLayout2 = new BorderLayout(); private BorderLayout borderLayout3 = new BorderLayout(); private BorderLayout borderLayout4 = new BorderLayout(); private BorderLayout borderLayout5 = new BorderLayout(); private BorderLayout borderLayout6 = new BorderLayout(); private BorderLayout borderLayout7 = new BorderLayout(); private BorderLayout borderLayout8 = new BorderLayout(); private BorderLayout borderLayout9 = new BorderLayout(); private BorderLayout borderLayout10 = new BorderLayout(); private BorderLayout borderLayout11 = new BorderLayout(); private BorderLayout borderLayout12 = new BorderLayout(); private BorderLayout borderLayout13 = new BorderLayout(); private BorderLayout borderLayout14 = new BorderLayout(); private BorderLayout borderLayout15 = new BorderLayout(); private GridLayout gridLayout1 = new GridLayout(); private GridLayout gridLayout2 = new GridLayout(); private GridLayout gridLayout3 = new GridLayout(); private GridLayout gridLayout4 = new GridLayout(); private JPanel jPanel1 = new JPanel(); private JPanel jPanel2 = new JPanel(); private JPanel jPanel3 = new JPanel(); private JPanel jPanel4 = new JPanel(); private JPanel jPanel5 = new JPanel(); private JPanel jPanel6 = new JPanel(); private JPanel jPanel7 = new JPanel(); private JPanel jPanel8 = new JPanel(); private JPanel jPanel9 = new JPanel(); private JPanel selPane = new JPanel(); private JPanel ranLinePane = new JPanel(); private JPanel frectPanel = new JPanel(); private JPanel rrecPanel = new JPanel(); private JPanel fovalPanel = new JPanel(); private JPanel ovalPanel = new JPanel(); private JPanel frecPanel = new JPanel(); private JPanel recPanel = new JPanel(); private JPanel linePanel = new JPanel(); private JPanel grayColorPanel = new JPanel(); private JPanel blueColorPanel = new JPanel(); private JPanel cyanColorPanel = new JPanel(); private JPanel magentaColorPanel = new JPanel(); private JPanel greenColorPanel = new JPanel(); private JPanel orangeColorPanel = new JPanel(); private JPanel redColorPanel = new JPanel(); private JPanel blackColorPanel = new JPanel(); private JButton selBut = new JButton(); private JButton lineBut = new JButton(); private JButton recBut = new JButton(); private JButton frecBut = new JButton(); private JButton ovalBut = new JButton(); private JButton fovalBut = new JButton(); private JButton rrecBut = new JButton(); private JButton frrecBut = new JButton(); private JButton rlineBut = new JButton(); private JLabel jLabel2 = new JLabel(); private JLabel jLabel3 = new JLabel(); private JLabel jLabel4 = new JLabel(); private JLabel jLabel5 = new JLabel(); private JLabel jLabel6 = new JLabel(); private JLabel jLabel7 = new JLabel(); private String path = ./images/line.gif; private ImageIcon lineimage = new ImageIcon(getClass().getResource(path); private String path1 = ./images/rline.gif; private ImageIcon rlinimage = new ImageIcon(getClass().getResource(path1); private String path2 = ./images/rect.gif; private ImageIcon rectimage = new ImageIcon(getClass().getResource(path2); private String path3 = ./images/rrect.gif; private ImageIcon rrectimage = new ImageIcon(getClass().getResource(path3); private String path4 = ./images/oval.gif; private ImageIcon ovalimage = new ImageIcon(getClass().getResource(path4); private String path5 = ./images/foval.gif; private ImageIcon fovalimage = new ImageIcon(getClass().getResource(path5); private String path6 = ./images/frect.gif; private ImageIcon frectimage = new ImageIcon(getClass().getResource(path6); private String path8 = ./images/frrect.gif; private ImageIcon frrectimage = new ImageIcon(getClass().getResource(path8); private String path9 = ./images/select.gif; private ImageIcon selectimage = new ImageIcon(getClass().getResource(path9); public Socket clientSocket = null; static String message = null; public static int i; public int colorindex; public Color color = null; public int currentTool =0; public int x0, y0, x1, y1, width, height; public int xold, yold, wold, hold; public Class cl; public Element element = null; public Vector elements = new Vector(); public WhiteBoardPanel whiteBoard = null; public static String name = ; public WhiteBoardFrame(String serIp,String serPort,String name) this.serIp = serIp; this.serPort =serPort; this.myName = name; try UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName(); catch (ClassNotFoundException e1) e1.printStackTrace(); catch (InstantiationException e1) e1.printStackTrace(); catch (IllegalAccessException e1) e1.printStackTrace(); catch (UnsupportedLookAndFeelException e1) e1.printStackTrace(); init(); public void init() try jbInit(); catch (Exception e) e.printStackTrace();return; color = Color.gray; try int port = Integer.parseInt(serPort); clientSocket = new Socket(serIp,port); whiteBoard = new WhiteBoardPanel(clientSocket); whiteBoard.setBackground(Color.white); whiteBoard.setType(currentTool); jPanel2.add(whiteBoard,BorderLayout.CENTER); whiteBoard.setColor(color); status(currentTool,0); catch(Exception ex) ex.printStackTrace(); System.out.println(failed to connect to wbServer); private void jbInit() throws Exception this.setLayout(borderLayout1); jPanel1.setLayout(borderLayout2); jPanel3.setLayout(borderLayout4); jPanel1.setBackground(Color.white); jPanel1.setPreferredSize(new Dimension(80, 300); jPanel3.setBorder(BorderFactory.createEtchedBorder(); jPanel3.setPreferredSize(new Dimension(80, 300); jPanel3.addMouseListener(new MouseAdapter() ); jPanel4.setLayout(borderLayout6); jPanel5.setLayout(gridLayout2); gridLayout2.setHgap(2); gridLayout2.setVgap(2); jPanel6.setBorder(BorderFactory.createEtchedBorder(); jPanel6.setPreferredSize(new Dimension(10, 200); jPanel6.setLayout(borderLayout5); jPanel7.setPreferredSize(new Dimension(10, 20); jPanel7.setLayout(gridLayout3); jLabel2.setForeground(SystemColor.desktop); jLabel2.setPreferredSize(new Dimension(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(new MouseAdapter() public void mousePressed(MouseEvent e) select_mousePressed(e); ); frectPanel.setBorder(BorderFactory.createLineBorder(Color.black); frectPanel.setLayout(borderLayout14); frrecBut.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) frrect_mousePressed(e); ); ranLinePane.setBorder(BorderFactory.createLineBorder(Color.black); ranLinePane.setLayout(borderLayout15); rlineBut.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) rline_mousePressed(e); ); rrecPanel.setBorder(BorderFactory.createLineBorder(Color.black); rrecPanel.setLayout(borderLayout13); rrecBut.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) rrect_mousePressed(e); ); ovalPanel.setBorder(BorderFactory.createLineBorder(Color.black); ovalPanel.setLayout(borderLayout11); ovalBut.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) oval_mousePressed(e); ); fovalPanel.setBorder(BorderFactory.createLineBorder(Color.black); fovalPanel.setLayout(borderLayout12); fovalBut.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) foval_mousePressed(e); ); recPanel.setBorder(BorderFactory.createLineBorder(Color.black); recPanel.setLayout(borderLayout9); recBut.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) rect_mousePressed(e); ); frecPanel.setBorder(BorderFactory.createLineBorder(Color.black); frecPanel.setLayout(borderLayout10); frecBut.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) frect_mousePressed(e); ); linePanel.setBorder(BorderFactory.createLineBorder(Color.black); linePanel.setLayout(borderLayout8); lineBut.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) line_mousePressed(e); ); blueColorPanel.setBackground(Color.blue); blueColorPanel.setBorder(BorderFactory.createLineBorder(Color.black); blueColorPanel.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) blue_mousePressed(e); ); grayColorPanel.setBackground(Color.gray); grayColorPanel.setBorder(BorderFactory.createLineBorder(Color.black); grayColorPanel.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) gray_mousePressed(e); ); cyanColorPanel.setBackground(Color.cyan); cyanColorPanel.setBorder(BorderFactory.createLineBorder(Color.black); cyanColorPanel.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) cyan_mousePressed(e); ); magentaColorPanel.setBackground(Color.magenta); magentaColorPanel.setBorder(BorderFactory.createLineBorder(Color.black); magentaColorPanel.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) magenta_mousePressed(e); ); greenColorPanel.setBackground(Color.green); greenColorPanel.setBorder(BorderFactory.createLineBorder(Color.black); greenColorPanel.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) green_mousePressed(e); ); orangeColorPanel.setBackground(Color.orange); orangeColorPanel.setBorder(BorderFactory.createLineBorder(Color.black); orangeColorPanel.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) orange_mousePressed(e); ); redColorPanel.setBackground(Color.red); redColorPanel.setBorder(BorderFactory.createLineBorder(Color.black); redColorPanel.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) red_mousePressed(e); ); blackColorPanel.setBackground(Color.black); blackColorPanel.setBorder(BorderFactory.createLineBorder(Color.black); blackColorPanel.addMouseListener(new MouseAdapter() public void mousePressed(MouseEvent e) black_mousePressed(e); ); jPanel2.setLayout(borderLayout3); jPanel2.setBorder(BorderFactory.createEtchedBorder(); jPanel2.setPreferredSize(new Dimension(4, 30); jLabel7.addMouseListener(new MouseAdapter() ); jLabel5.addMouseListener(new MouseAdapter() ); lineBut.setForeground(Color.white); lineBut.setBorder(null); lineBut.setBorderPainted(false); lineBut.setIcon(lineimage); lineBut.setText(); recBut.setBackground(Color.white); recBut.setForeground(Color.white); recBut.setBorder(null); recBut.setBorderPainted(false); recBut.setContentAreaFilled(false); recBut.setIcon(rectimage); recBut.setText(); frecBut.setForeground(Color.white); frecBut.setBorder(null); frecBut.setBorderPainted(false); frecBut.setContentAreaFilled(false); frecBut.setIcon(frectimage); frecBut.setText(); ovalBut.setBackground(Color.white); ovalBut.setForeground(Color.white); ovalBut.setBorder(null); ovalBut.setBorderPainted(false); ovalBut.setContentAreaFilled(false); ovalBut.setIcon(ovalimage); ovalBut.setText(); fovalBut.setForeground(Color.white); fovalBut.setBorder(null); fovalBut.setIcon(fovalimage); fovalBut.setText(); rrecBut.setForeground(Color.white); rrecBut.setBorder(null); rrecBut.setIcon(rrectimage); rrecBut.setText(); frrecBut.setForeground(Color.white); frrecBut.setBorder(null); frrecBut.setIcon(frrectimage); frrecBut.setText(); rlineBut.setForeground(Color.white); rlineBut.setBorder(null); rlineBut.setBorderPainted(false); rlineBut.setContentAreaFilled(false); rlineBut.setIcon(rlinimage); rlineBut.setText(); jPanel9.setPreferredSize(new Dimension(40, 200); jPanel8.setPreferredSize(new Dimension(40, 80); jPanel4.setBackground(Color.white); jPanel4.setBorder(BorderFactory.createEtchedBorder(); jPanel4.setMinimumSize(new Dimension(0, 482); jPanel4.setPreferredSize(new Dimension(40, 300); selBut.setBackground(Color.white); selBut.setForeground(Color.white); selBut.setBorder(null); selBut.setBorderPainted(false); selBut.setContentAreaFilled(false); selBut.setIcon(selectimage); this.add(jPanel1, BorderLayout.WEST); jPanel1.add(jPanel4, BorderLayout.CENTER); jPanel4.add(jPanel8, BorderLayout.SOUTH); jPanel8.add(grayColorPanel, null); jPanel8.add(blackColorPanel, null); jPanel8.add(redColorPanel, null); jPanel8.add(orangeColorPanel, null); jPanel8.add(greenColorPanel, null); jPanel8.add(magentaColorPanel, null); jPanel8.add(cyanColorPanel, null); jPanel8.add(blueColorPanel, null); jPanel4.add(jPanel9, BorderLayout.CENTER); jPanel9.add(selPane, null); jPanel9.add(linePanel, null); jPanel9.add(recPanel, null); jPanel9.add(frecPanel, null); jPanel9.add(ovalPanel, null); jPanel9.add(fovalPanel, null); jPanel9.add(rrecPanel, null); jPanel9.add(frectPanel, null); jPanel9.add(ranLinePane, null); jPanel1.add(jPanel5, BorderLayout.SOUTH); this.add(jPanel7, BorderLayout.SOUTH); jPanel7.add(jLabel2, null); jPanel7.add(jLabel7, null); jPanel7.add(jLabel6, null); jPanel7.add(jLabel5, null); jPanel7.add(jLabel4, null); jPanel7.add(jLabel3, null); this.add(jPanel2, BorderLayout.CENTER); selPane.add(selBut, BorderLayout.CENTER); linePanel.add(lineBut, BorderLayout.CENTER); recPanel.add(recBut, BorderLayout.CENTER); frecPanel.add(frecBut, BorderLayout.CENT
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 发电考试题及答案
- 中级微观经济学(浙江大学)知到智慧树答案
- 中文写作(山东联盟)知到智慧树答案
- 银行会计习题及答案
- 2025年度内衣品牌企业信息化建设合作合同模板
- 2025年度泵车租赁及运输保险服务合同范本
- 2025年别墅房屋建设与室内外装饰一体化服务合同
- 2025年汽车质押借款合同车辆保险权益转让范本
- 2025年照明产品进出口贸易合同
- 2025版智能生产线全套设备交易及维护服务合同
- 危险品企业安全风险隐患排查治理手册
- 物业小区多种经营创收方案及应用
- 《建筑装饰设计收费》
- 设备预防性维修管理
- 去极端化自我剖析
- 生殖伦理培训课件
- 船舶压载水取样与检测技术
- 【种植活动中培养幼儿自主探究的实践研究4100字(论文)】
- 飞蚊症护理的课件
- 金融工程.郑振龙(全套课件560P)
- 古典诗歌的生命情怀
评论
0/150
提交评论