记念一下个人Java课设...

记念一下个人Java课设

前言: 从上周周日到本周周六下午两点,其间天天睡眠时间没超过五小时(我以为是比较累的,固然也是颇有收获的一次经历)

问题描述

**结合JavaSocket编程开发文本处理程序。java

一、自行下载最喜好的小说1部。存到服务器中,格式自定。通常存储为文本文档。要求长篇小说,20万字以上。举例说明:下载《三国演义》保存在服务器端。ios

二、该软件支持从服务器载入小说,对小说中的文本进行分析。举例说明:服务器端保存《三国演义》,客户端进行分析。正则表达式

三、首先运行服务器。服务器运行以后,能够链接1个客户端。编程

四、运行客户端。用户可以输入昵称,肯定,则链接到服务器。链接成功,便可出现功能界面。数组

客户端功能界面以下:服务器

一、功能1:载入小说。可以选择服务器端的小说。举例说明:客户端点击按钮,选择服务器端的文件名,《三国演义》传输到客户端。网络

二、功能2:任意设置10我的姓名(能够预设置在客户端界面上),将这10我的在小说中的存在感进行排名,用柱状图表示。如何计算存在感?本身定义。点击按钮,存在感排名的柱状图能够保存到服务器端。举例说明:界面上设置“刘备、曹操、张飞、关羽、赵云、诸葛亮、吕布、貂蝉、董卓、孙权”,点击按钮,出现一个柱状图,显示存在感排名为:刘备、曹操、张飞、关羽、诸葛亮、赵云、孙权、吕布、董卓、貂蝉(只是举例说明)。app

三、每一个人在小说中活跃的位置是不同的。任意输入10人中的1人,显示他在小说中出现的密度,画出密度图。建议用颜色深浅表示密度。点击按钮,密度图能够保存到服务器端。举例说明:输入“刘备”,在小说中前面部分密度大,后面部分密度小。框架

四、若是两人在相距较短的一段文字中出现,咱们认为两人有关系,距离越短,关系越近;若是屡次在较短篇幅出现,则关系更近。对这10我的,根据他们关系的紧密程度进行归类,看看能够归为哪几类?并用图形形式直观表示。如何定义关系紧密程度?本身定义。点击按钮,紧密程度归类的图像内容,能够保存到服务器端。举例说明:这10我的,自动分为“刘备、张飞、关羽、赵云、诸葛亮”以及“曹操”、“吕布、董卓、貂蝉”、“孙权”(只是举例)。ssh

五、附加题,不检查,作了不加分不减分。任意输入一我的,显示他最恨谁,最喜欢谁,最喜欢吃什么,常常去哪里活动,杀人多很少,是好人仍是坏人?

看与你的直觉是否符合?若是不太符合,说明可能的缘由。

检查流程,共提三个问题:根据回答打分:档次为A+, A-,B+, B-,C。

问题1:功能2展现,以及解释源代码。

问题2:功能3展现,以及解释源代码。

问题3:功能4展现,以及解释源代码。

我的设计思路

​ 简单来讲就是,客户端,服务器端各一个类,因为要设计出好看的图形界面,全部不得不本身编写一个Mypanel类继承JPanel类,重写里面的paintComponent方法。此外,登陆界面,功能一二三各须写一个类(面板类,继承JPanel)功能四核心是本身的思想,图像界面是次要的,所以须要额外编写为一个JFrame类而且实现Serializable借口以便和服务器端交流,一样,功能2,3的实现也要额外编写一个能够和服务器交流的类。最后须要编写的就是能够上传文件给服务器端的upload函数,利用构造函数重载实现一个类传三个功能的结果对象的功能,减小代码量。

很少说,直接上代码

1.首先是服务器类

package MYDESIGN;
import java.net.*;
import javax.swing.*;
import java.io.*;     //该类表明服务器
public class Server extends JFrame {  
	public static ServerSocket ss;
    public static  Socket socket;    //服务器链接所需成员
	private InputStream insClient;
	private BufferedReader brClient;
	private OutputStream osClient;
	private PrintStream psClient;  //服务器与客户端联系所需的输入输出流
	private String order;          //记录命令的字符串
	private static String Download = "!@#下载文件"; 
	private static String Continue = "!@#继续传输";
	private static String Over = "!@#传输完成";
	private static String Receive = "!@#接收客户端文件";
	    //服务器端的基本指令集
	Server(){ 
		super("服务器端");
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(400,200);
		this.setVisible(true);
	   try{
		   ss = new ServerSocket(9999);
		   socket =  ss.accept();  //等待客户端的链接
		   insClient = socket.getInputStream();
		   osClient = socket.getOutputStream();
		   brClient = new BufferedReader(new InputStreamReader(insClient));
		   psClient = new PrintStream(osClient);                 //与客户端创建联系
		   String Clientname = brClient.readLine();
		   this.setTitle(Clientname+"已经链接上");   
	   }catch(Exception ex){
		   ex.printStackTrace();
	   }
	}       //该构造函数完成的任务是,打开服务器,与客户端创建联系,而且更新本身的标题
	void downloadfile(){
		File file = new File("D:\\CourseDesign\\WaterMargin.txt");
		try{ 
			FileReader fd = new FileReader(file);
			BufferedReader bfile = new BufferedReader(fd);
			String line;  //文件读入
			String or;    //命令读入
			while(true){
			line = bfile.readLine();
			if(line == null){
				psClient.println(this.Over);
				break;}   //传输完成就告诉客户端已经传输完成了
			psClient.println(line);  //不断传输一行信息
			or = brClient.readLine();  
			if(or.equals(this.Continue)){
				continue;   //只有在收到能够继续传输的时候才会继续传输,避免速度不匹配
			}
}

			fd.close();
			bfile.close();  //传输完成,关闭文件相关输入输出流
		}catch(Exception ex){}
	}
	
	void receivefile(){    //接收客户端传来的文件信息
		try{
			String line = brClient.readLine();
			FileOutputStream fos = new FileOutputStream("D:\\CourseDesign\\"+line+".txt");
			PrintStream printfile = new PrintStream(fos);  
			while(true){
				line = brClient.readLine();
				if(line.equals(Server.Over))
					break;
				printfile.println(line);
				printfile.flush();
				psClient.println(Server.Continue);
			}
			
			fos.close();
			printfile.close();
		}catch(Exception ex){}
		
		
	}
	
	//构造函数
	void Receiver(){
		
		try{
			this.order = brClient.readLine();  //一直处于等待接受客户端命令的状态
		    if(this.order.equals(this.Download)){  
		    	 downloadfile();   //调用downloadfile函数以异步通讯方式完成传输
		    }else if(this.order.equals(this.Receive)){
		    	 receivefile();
		    }
		}catch(Exception ex){}
	}//服务器端的接受命令函数,用于从客户端接受命令而且作出相应处理
	
	
	public static void  main(String [] args)throws Exception{
		Server mine = new Server();
		while(true){
  		  
  		  mine.Receiver();  //一直处于接受命令的状态
  	  }
      }
	 
}
  1. 客户端类

    package MYDESIGN;
    import java.net.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import MYDESIGN.*; //该类是客户端,也就是功能端
    public class Customer extends JFrame{
    	private INIT initINT;
    	private FUNCTION function;
    	public static Socket socket;
    	public static InputStream insServer;
    	public static BufferedReader brServer;
    	public static OutputStream osServer;
    	public static PrintStream psServer;
    	public static boolean isdownload = false;
    	Customer(){
    		initINT = new INIT(this.function);//INIT界面已经包含了让客户端与服务器端创建联系的操做
    }   //客户端构造函数,用于打开登陆界面,链接服务器用
    	public static void main(String [] args){
    		new Customer();
    	}
    }

3.本身手写的面板类,用于加入背景图片

package MYDESIGN;
import javax.swing.*;
import java.awt.*;
public class Mypanel extends JPanel{     //Mypanel继承了JPanel使得其能够设置背景图片
	private ImageIcon img;
	Mypanel(String filename){
		this.img = new ImageIcon(filename);
	}  //传入文件路径设置背景图片
	public void paintComponent(Graphics g){
		g.drawImage(img.getImage(),0,0,this.getWidth(),this.getHeight(),this);
	}
}

4.下面是登陆界面类

package MYDESIGN;
import java.net.*;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import MYDESIGN.*;  //该类是初始登陆界面
public class INIT extends JFrame implements ActionListener{                        //初始登录界面	

	 private Mypanel jpl = new Mypanel("D:\\CourseDesign2\\读书.jpg");
	 private JLabel jlb1 = new JLabel("请输入有效的服务器地址:");
	 private JTextField jtf1 = new JTextField(20);
	 private JLabel jlb2 = new JLabel("请输入您的昵称(不然默认匿名用户):");
	 private JTextField jtf2 = new JTextField(20);
	 private JButton jbt1 = new JButton("登陆");  
	 private JButton jbt2 = new JButton("取消");          //以上控件是客户端登陆界面出现的控件                                           
	 private String IPAD;
	 public String nickname = "匿名用户";                           //用于存储有效的界面信息的成员变量
	 private FUNCTION fun;
	 INIT(FUNCTION funinter){
		 this.fun = funinter;
		 jbt1.setFont(new Font("楷体",Font.PLAIN,17));
		 jbt2.setFont(new Font("楷体",Font.PLAIN,17));
		 jtf1.addActionListener(this);
		 jtf2.addActionListener(this);
		 jbt1.addActionListener(this);
		 jbt2.addActionListener(this);
		 jlb1.setForeground(Color.black);
		 jlb1.setFont(new Font("楷体",Font.PLAIN,17));
		 jpl.add(jlb1);
		 jpl.add(jtf1);
		 jpl.add(jlb2);
		 jlb2.setForeground(Color.black);
		 jlb2.setFont(new Font("楷体",Font.PLAIN,17));
		 jpl.add(jtf2);
		 jpl.add(jbt1);
		 jpl.add(jbt2);                        
        this.add(jpl);                          //将这控件加入到初始面板上
        this.setSize(300,400);
        this.setVisible(true);
        this.setTitle("登陆界面");
        this.setLocation(700,300);
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	 }
	 public void actionPerformed(ActionEvent e){
		  if(e.getSource()==jbt1){
			this.IPAD = jtf1.getText();
			this.nickname = jtf2.getText();
			if(!IPAD.equals("127.0.0.1")){
				UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
				UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
				JOptionPane.showMessageDialog(null,"没法链接到有效服务器请从新输入。");
			    jtf1.setText("");
			}
			else{
				try{
					Customer.socket = new Socket(IPAD,9999);
					try{
						Customer.insServer = Customer.socket.getInputStream();
					    Customer.osServer = Customer.socket.getOutputStream();
					    Customer.brServer = new BufferedReader(new InputStreamReader(Customer.insServer));
					    Customer.psServer = new PrintStream(Customer.osServer);  //全局静态输入输出流
					    }catch (Exception ex){}
					Customer.psServer.println(this.nickname);
				    this.fun = new FUNCTION(this.nickname);	
					UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
				    UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
				    JOptionPane.showMessageDialog(null,"您能够阅读其余书籍,但本功能只支持分析《水浒传》");
                    this.dispose();
				}catch(Exception ex){}
			}
		 }
		 else if(e.getSource()==jbt2){
			 this.dispose();
		 }
	 }      //针对不一样状况下不一样的事件处理
  
}

5.功能主面板

package MYDESIGN;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;

import java.awt.event.*;
import MYDESIGN.*;
import java.awt.*;

class FUNCTION extends JFrame implements ActionListener{   //功能界面,也是主框架
	private JButton jbt1 = new JButton("功能1");
	private JButton jbt2 = new JButton("功能2");
	private JButton jbt3 = new JButton("功能3");
	private JButton jbt4 = new JButton("功能4");
	private JButton jbt5 = new JButton("退出");
	private Mypanel jpl = new Mypanel("D:\\CourseDesign2\\fengmian.jpg");
	private FUN1 fun1 = new FUN1(jpl,this);     //功能1所要切换的面板,功能1最终要切换回来
	private FUN2 fun2 = new FUN2(jpl,this);
	private FUN3 fun3 = new FUN3(jpl,this);
	private FUN4 fun4;
	FUNCTION(String name){
		super("欢迎"+name+"登陆使用");
		jbt1.setPreferredSize(new Dimension(100,50));
		jbt2.setPreferredSize(new Dimension(100,50));
		jbt3.setPreferredSize(new Dimension(100,50));
		jbt4.setPreferredSize(new Dimension(100,50));
		jbt5.setPreferredSize(new Dimension(100,50));
		jbt1.setFont(new Font("宋体",Font.PLAIN,25));
		jbt2.setFont(new Font("宋体",Font.PLAIN,25));
		jbt3.setFont(new Font("宋体",Font.PLAIN,25));
		jbt4.setFont(new Font("宋体",Font.PLAIN,25));
		jbt5.setFont(new Font("宋体",Font.PLAIN,25));
		jbt1.addActionListener(this);
		jbt2.addActionListener(this);
		jbt3.addActionListener(this);
		jbt4.addActionListener(this);
		jbt5.addActionListener(this);
		jpl.add(jbt1);
		jpl.add(new JPanel());
		jpl.add(jbt2);
		jpl.add(new JPanel());
		jpl.add(jbt3);
		jpl.add(new JPanel());
		jpl.add(jbt4);
		jpl.add(new JPanel());
		jpl.add(jbt5);
		this.add(jpl);
		this.setSize(800,950);
		this.setLocation(500,70);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==this.jbt1){
			this.setContentPane(fun1);
			this.revalidate();
	}else if(e.getSource()==this.jbt2){
		    this.setContentPane(fun2);
		    this.revalidate();
	}else if(e.getSource()==this.jbt3){
		    this.setContentPane(fun3);
	        this.revalidate();
	        UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 14)));
		    UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 14)));
		    JOptionPane.showMessageDialog(null,"本功能实现的是分析人物在书本中出现密度");
	}else if(e.getSource()==this.jbt4){
		if(Customer.isdownload==false){
			UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
		    UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
			JOptionPane.showMessageDialog(null,"客户端暂时还未下载文件,请点击功能1完成下载");
		}else{
			fun4 = new FUN4();
		}
	}else if(e.getSource()==jbt5){
		this.dispose();
	}
}
	}

6.功能1所要切换到的切换面板

package MYDESIGN;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import MYDESIGN.*;
import javax.swing.plaf.*;
import java.awt.*;
public class FUN1 extends Mypanel implements ActionListener{    //功能1的跳转面板
    public static  JTextArea jta = new JTextArea(180,240);             //而且能够实现跳转回主框架
	private JScrollPane jsp = new JScrollPane(jta);
	private JButton jbtdl = new JButton("选择读本");
	private JButton jbtex = new JButton("当即阅读");
	private JButton jbtf1 = new JButton("返回");
	private BorderLayout bdl = new BorderLayout(30,30);
	private Mypanel update;
	private JFrame Father;
	private JPanel jplfun = new JPanel();
	private JPanel gap = new JPanel();
	public static int linenum = 0;
	public static boolean isread = false;
	FUN1(Mypanel father,JFrame JF){
		super("D:\\CourseDesign2\\WaterMargin.jfif");
		this.jta.setLineWrap(true);
		this.update = father;
		this.Father = JF;
		this.setLayout(bdl);
		this.jta.setFont(new Font("楷体",Font.PLAIN,19));
		this.jbtf1.addActionListener(this);
		this.jbtdl.addActionListener(this);
		this.jbtex.addActionListener(this);
		this.jbtf1.setPreferredSize(new Dimension(180,80));
		this.jbtf1.setFont(new Font("宋体",Font.PLAIN,30));
		this.jbtdl.setPreferredSize(new Dimension(220,80));
		this.jbtdl.setFont(new Font("宋体",Font.PLAIN,30));
		this.jbtex.setPreferredSize(new Dimension(220,80));
		this.jbtex.setFont(new Font("宋体",Font.PLAIN,30));
		this.jplfun.add(jbtdl);
		this.jplfun.add(gap);
		this.jplfun.add(jbtex);
		this.jplfun.add(new JPanel());
		this.jplfun.add(jbtf1);
		this.add(jplfun,bdl.SOUTH);
		this.add(jsp,bdl.CENTER);
		this.add(new JPanel(),BorderLayout.NORTH);
		this.add(new JPanel(),BorderLayout.EAST);
		this.add(new JPanel(),BorderLayout.WEST);		
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==jbtf1){
			Father.setContentPane(this.update);    //将要设置父框架的父面板
			Father.revalidate();
		}else if(e.getSource()==jbtdl){
			 new DIA(this.Father,"读本选择",true);
		}else if(e.getSource()==jbtex){
			File file = new File("D:\\CourseDesign2\\水浒.txt");
		 try{
			 FileReader fd = new FileReader("D:\\CourseDesign2\\水浒.txt");
			 BufferedReader bff = new BufferedReader(fd);
			 String linefile;
			 while(true){
			 linefile = bff.readLine();
			 if(linefile == null)
				 break;
			 this.jta.append(linefile);
			 this.jta.append("\n");}
			 jta.setCaretPosition(0);  //将光标移到初始位置,符合读者要求
			 fd.close();
			 bff.close();
		 }catch(Exception ex){}   
		}
	}
}

class DIA extends JDialog implements ActionListener{    //功能1附加窗口
	private JLabel jlb = new JLabel("请选择想得到哪本读物");
	private JComboBox jcb = new JComboBox();
	private JButton jbt = new JButton("肯定");
	private Mypanel jpladd = new Mypanel("D:\\CourseDesign2\\book.jpeg");
	private Mypanel jpl = new Mypanel("D:\\CourseDesign2\\choosecover.png");
	private FileOutputStream filefos;
	private PrintStream fileps;   //存储到文件的相关流
	DIA(Frame own,String s,boolean bool){	
		super(own,s,bool);
		this.jpl.setLayout(new BorderLayout());
		this.jpladd.add(jcb);
		this.jpl.add(jlb,BorderLayout.NORTH);
		this.jpl.add(jpladd,BorderLayout.CENTER);
		this.jpl.add(jbt,BorderLayout.SOUTH);
		jbt.addActionListener(this);
		this.jcb.addItem("三国演义");
		this.jcb.addItem("水浒传");
		this.jcb.addItem("红楼梦");
		this.jcb.addItem("西游记");
		this.jlb.setPreferredSize(new Dimension(450,50));
		this.jlb.setFont(new Font("楷体",Font.BOLD,25));
		this.jcb.setPreferredSize(new Dimension(450,58));
		this.jcb.setFont(new Font("楷体",Font.PLAIN,25));
		this.jbt.setPreferredSize(new Dimension(330,50));
		this.jbt.setFont(new Font("楷体",Font.PLAIN,27));
		this.add(jpl);
		this.setSize(550,500);
		this.setLocation(625,300);
		this.setVisible(true);
		this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	}
	public void actionPerformed(ActionEvent e){
		String s = (String)jcb.getSelectedItem();
		if(s.equals("水浒传")){
			try{
			  Customer.psServer.println("!@#下载文件");  //将传输文件的命令发送出去
			  filefos = new FileOutputStream("D:\\CourseDesign2\\水浒.txt");
			  fileps = new PrintStream(filefos);
			  String line;
			  while(true){
				  line = Customer.brServer.readLine();
				  if(line.equals("!@#传输完成")){
					  break;}
				  fileps.println(line);
				  fileps.flush();
				  if(FUN1.isread==false)
				     FUN1.linenum++;
				 Customer.psServer.println("!@#继续传输");
			  }
			  Customer.isdownload = true;  //下载完成,告诉客户端已经下载好能够访问了
			  FUN1.isread = true;  //为后继不重复计算行数作依据
			  filefos.close();
		      fileps.close();   //关闭全部的输入输出流,异步通讯结束
		      this.dispose();
			}catch(Exception ex){}
		                              	
		}else{
			UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
			UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
			JOptionPane.showMessageDialog(null,"很抱歉"+s+"暂时没有相关资源");
		}
		
	}
}

7.功能2所要切换的面板

package MYDESIGN;
import MYDESIGN.*;
import java.io.*;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.*;
import java.awt.event.*;
import java.util.regex.*;
class graph extends JFrame{     //人物图像显示框架类
	private Mypanel mp;
	graph(String name,String path){
		super(name);
		this.mp= new Mypanel(path);
		this.add(mp);
		this.setSize(400,400);
		this.setLocation(700,310);
		this.setVisible(true);
	}
 }                                   

public class FUN2 extends Mypanel implements ActionListener{
    private JFrame father;
    private JPanel jplorigin;   //切换所需主框架和主面板
    private JButton jbt0 = new JButton("人物存在感分析");
    private JButton jbt1 = new JButton("宋江");
    private JButton jbt2 = new JButton("晁盖");
    private JButton jbt3 = new JButton("武松");
    private JButton jbt4 = new JButton("吴用");
    private JButton jbt5 = new JButton("李逵");
    private JButton jbt6 = new JButton("林冲");
    private JButton jbt7 = new JButton("鲁智深");
    private JButton jbt8 = new JButton("呼延灼");
	private JButton jbt9 = new JButton("柴进");
	private JButton jbt10 = new JButton("卢俊义");  //所选的十我的物
	private JButton jbt11 = new JButton("分析结果查看");
	private JButton jbt12 = new JButton("上传结果"); 
	private JButton jbt13 = new JButton("返回");
	private JPanel jpl1 = new JPanel();
	private JPanel jpl2 = new JPanel();
	private JPanel jpl3 = new JPanel();
	private int[] num = new int[10]; //十个数字分别标记以前顺序下的十个角色出现次数
	private int sum = 0;    //为了求出占比而须要的辅助的总和记录
	private FileReader fdr;
	private BufferedReader bfder;
    public float[] ratio = new float[10]; //记录这十位角色的占比
	private boolean flag = false; //记录是第一次调用仍是第二次调用 后期优化的时候再来搞
	public String[] ss = {"宋江","晁盖","武松","吴用","李逵","林冲","鲁智深","呼延灼","柴进","卢俊义"};
	private Pattern[] p = new Pattern[10];//模式类数组
	private Matcher[] m = new Matcher[10]; //匹配类
	private graphvis gpv;
	
	
	private void sort(int num,String[] name,float[] ratio){   //对所得比率进行大小排序,按照从低到高的顺序
		int pos;
		float temp1;
		String temp2;
		for(int i=0;i<num-1;i++){
			pos = i;
			for(int j = i+1;j<num;j++){
				if(ratio[j]<ratio[pos])
					pos = j;
			}
			if(pos == i){
				continue;
			}else{
				temp1 = ratio[i];
				ratio[i] = ratio[pos];
				ratio[pos]=temp1;
				temp2 = name[i];
				name[i] = name[pos];
				name[pos] = temp2;   //交换实现
			}
		}
	}
	
	
	FUN2(JPanel jp,JFrame JF){
		super("D:\\CourseDesign2\\FUN2.jpg");
		for(int i:this.num){
			i = 0;  //初始化出现次数
		}
		this.father = JF;
		this.jplorigin = jp;
		this.setLayout(new BorderLayout(20,20));
		jpl1.setBackground(null);
		jpl1.setOpaque(false);
		jpl2.setBackground(null);
		jpl2.setOpaque(false);
		jpl2.setLayout(new GridLayout(6,3,20,30));
		jpl3.setBackground(null);
		jpl3.setOpaque(false);
		jpl1.add(jbt0);
		jpl2.add(jbt1);
		jpl2.add(jbt2);
		jpl2.add(jbt3);
		jpl2.add(jbt4);
		jpl2.add(jbt5);
		jpl2.add(jbt6);
		jpl2.add(jbt7);
		jpl2.add(jbt8);
		jpl2.add(jbt9);
		jpl2.add(jbt10);
		jpl3.add(jbt11);
		jpl3.add(jbt12);
		jpl3.add(jbt13);
		jbt0.setPreferredSize(new Dimension(600,60));
		jbt0.setFont(new Font("楷体",Font.BOLD,50));
		jbt0.setContentAreaFilled(false);
		jbt0.setForeground(Color.yellow);
		jbt1.setPreferredSize(new Dimension(200,80));
		jbt1.setFont(new Font("楷体",Font.BOLD,50));
		jbt1.setContentAreaFilled(false);
		jbt1.setForeground(Color.green);
		jbt1.addActionListener(this);
		jbt2.setPreferredSize(new Dimension(200,80));
		jbt2.setFont(new Font("楷体",Font.BOLD,50));
		jbt2.setContentAreaFilled(false);
		jbt2.setForeground(Color.green);
		jbt2.addActionListener(this);
		jbt3.setPreferredSize(new Dimension(200,80));
		jbt3.setFont(new Font("楷体",Font.BOLD,50));	
		jbt3.setContentAreaFilled(false);
		jbt3.addActionListener(this);
		jbt3.setForeground(Color.green);
		jbt4.setPreferredSize(new Dimension(200,80));
		jbt4.setFont(new Font("楷体",Font.BOLD,50));
		jbt4.setContentAreaFilled(false);
		jbt4.setForeground(Color.green);
		jbt4.addActionListener(this);
		jbt5.setPreferredSize(new Dimension(200,80));
		jbt5.setFont(new Font("楷体",Font.BOLD,50));
		jbt5.setContentAreaFilled(false);
		jbt5.setForeground(Color.green);
		jbt5.addActionListener(this);
		jbt6.setPreferredSize(new Dimension(200,80));
		jbt6.setFont(new Font("楷体",Font.BOLD,50));
		jbt6.setContentAreaFilled(false);
		jbt6.setForeground(Color.green);
		jbt6.addActionListener(this);
		jbt7.setPreferredSize(new Dimension(200,80));
		jbt7.setFont(new Font("楷体",Font.BOLD,50));
		jbt7.setContentAreaFilled(false);
		jbt7.setForeground(Color.green);
		jbt7.addActionListener(this);
		jbt8.setPreferredSize(new Dimension(200,80));
		jbt8.setFont(new Font("楷体",Font.BOLD,50));
		jbt8.setContentAreaFilled(false);
		jbt8.setForeground(Color.green);
		jbt8.addActionListener(this);
		jbt9.setPreferredSize(new Dimension(200,80));
		jbt9.setFont(new Font("楷体",Font.BOLD,50));
		jbt9.setContentAreaFilled(false);
		jbt9.setForeground(Color.green);
		jbt9.addActionListener(this);
		jbt10.setPreferredSize(new Dimension(200,80));
		jbt10.setFont(new Font("楷体",Font.BOLD,50));
		jbt10.setContentAreaFilled(false);
		jbt10.setForeground(Color.green);
		jbt10.addActionListener(this);
		jbt11.setPreferredSize(new Dimension(210,80));
		jbt11.setFont(new Font("楷体",Font.BOLD,25));
		jbt11.setContentAreaFilled(false);
		jbt11.setForeground(Color.red);
		jbt11.addActionListener(this);
		jbt12.setPreferredSize(new Dimension(210,80));
		jbt12.setFont(new Font("楷体",Font.BOLD,25));
		jbt12.setContentAreaFilled(false);
		jbt12.setForeground(Color.red);
		jbt12.addActionListener(this);
		jbt13.setPreferredSize(new Dimension(130,80));
		jbt13.setFont(new Font("楷体",Font.BOLD,25));
		jbt13.setContentAreaFilled(false);
		jbt13.setForeground(Color.red);	
		jbt13.addActionListener(this);
		this.add(jpl1,BorderLayout.NORTH);
		this.add(jpl2,BorderLayout.CENTER);
		this.add(jpl3,BorderLayout.SOUTH);
	}
    public void actionPerformed(ActionEvent e){
    	if(e.getSource()==jbt1){
    	           new graph("宋江","D:\\CourseDesign2\\songjiang.jpg");
    	}else if(e.getSource()==jbt2){
    		        new graph("晁盖","D:\\CourseDesign2\\chaogai.jfif");
    	}else if(e.getSource()==jbt3){
    		        new graph("武松","D:\\CourseDesign2\\wusong.jpg");
    	}else if(e.getSource()==jbt4){
    		        new graph("吴用","D:\\CourseDesign2\\wuyong.jpg");
    	}else if(e.getSource()==jbt5){
    		        new graph("李逵","D:\\CourseDesign2\\likui.jpg");
    	}else if(e.getSource()==jbt6){
    		        new graph("林冲","D:\\CourseDesign2\\linchong.jpg");
    	}else if(e.getSource()==jbt7){
    		        new graph("鲁智深","D:\\CourseDesign2\\luzhishen.jpeg");
    	}else if(e.getSource()==jbt8){
    		        new graph("呼延灼","D:\\CourseDesign2\\huyanzhuo.jfif");
    	}else if(e.getSource()==jbt9){
    		        new graph("柴进","D:\\CourseDesign2\\chaijin.jpg");
    	}else if(e.getSource()==jbt10){
    		        new graph("卢俊义","D:\\CourseDesign2\\lujunyi.jpg");
    	}else if(e.getSource()==jbt11){
    		 if(Customer.isdownload == false){
    			 UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
 			     UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));	
    			 JOptionPane.showMessageDialog(null,"客户端暂时还未下载文件,请点击功能1完成下载");
    		    }else{
    		 File file  = new File("D:\\CourseDesign2\\水浒.txt");
    		 try{
    		   fdr = new FileReader(file);
    		   bfder = new BufferedReader(fdr);  //文件读入流
    		 
    		 String line;  //中转的字符串
             for(int n = 0;n<10;n++)
            	 p[n] = Pattern.compile(ss[n]); 
            	   //创建模式匹配关系
             
    		 while(true){
    			 try{
    				 line = bfder.readLine();
    				 if(line == null)
    			  		 break;
    			 //下面将使用基于处理复杂字符串的正则表达式原理的regex包下的两个重要类
    			     for(int n = 0;n<10;n++){
    			    	 m[n] = p[n].matcher(line);  //创建对应匹配关系
    			         while(m[n].find())
    			        	 num[n]++;  //各个字符串的匹配,而且记录到num数组
    			     }
    				 
    			 }catch(Exception ex){}
    		 }  //while   		 	
    			 fdr.close();
    		     bfder.close();  //关闭文件输入流
    		     for(int i = 0;i<10;i++)
    		    	 sum +=num[i];
    		     for(int i = 0;i<10;i++)
    		    	 ratio[i] = ((float)num[i])/sum;//防止地板除法形成精度损失,获得每一个人的存在感百分比
    		     for(int i = 0;i<10;i++)
    		    	 ratio[i]=(float)Math.round(ratio[i]*1000)/1000;  //将精度控制
                 sort(10,ss,ratio);  //排序
    		     this.gpv = new graphvis(10,ss,ratio);
    		 }catch(Exception ex){}
          
}  //else情形
    	}  //jbt11处理
    	else if(e.getSource()==jbt12){
    		 if(Customer.isdownload == false){
    			    UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
 			        UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));	
    		    	JOptionPane.showMessageDialog(null,"客户端暂时还未下载水浒传,请点击功能1完成下载");
    		    }else
    		    	 new upload("功能2绘图",this.gpv).send2();  
    		    
    	}//jbt12处理
    	else if(e.getSource()==jbt13){
    		this.father.setContentPane(this.jplorigin);
    		this.revalidate();
    	}
    	
    		
    
    	}	
}

8.功能2柱状图显示类

package MYDESIGN;
import MYDESIGN.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
class gpanel extends JPanel implements ActionListener{  
     String[] names;
	 int num;
	 float[] ratios;
	 JFrame father;
	 private JButton jbt = new JButton("返回");
	gpanel(int number,String[] ss,float[] ritio,JFrame f){  //number是将显示的数量给划分坐标提供条件
		this.father = f;
		this.num = number;
		this.ratios = ritio;
		this.names = ss;
		this.jbt.setPreferredSize(new Dimension(200,50));
		this.jbt.setFont(new Font("楷体",Font.PLAIN,40));
		this.jbt.addActionListener(this);
		this.add(jbt);
	}
	public void paint(Graphics g){
		Graphics2D g2 = (Graphics2D)g;
		g2.setStroke(new BasicStroke(2.0f));
		g2.setColor(Color.green);
		g2.drawLine(150,900,1350,900);
		g2.drawLine(1340,910,1350,900);
		g2.drawLine(1340,890,1350,900);
		g2.drawLine(150,900,150,80);
		g2.drawLine(140,90,150,80);
		g2.drawLine(160,90,150,80);   //绘制基本坐标轴
		g2.setStroke(new BasicStroke(0.5f));
		g2.setColor(Color.gray);
		g2.drawLine(150,750,1350,750);
		g2.drawLine(150,600,1350,600);
		g2.drawLine(150,450,1350,450);
		g2.drawLine(150,300,1350,300);
		g2.drawLine(150,150,1350,150);  //获得比率坐标轴的切线方向,便于定位
		
		
		for(int i = 0;i<num;i++){  //绘制统计图
			g2.setColor(Color.red);
			g2.fillRect(200+110*i, 900-(int)(this.ratios[i]*1500), 45,(int)(this.ratios[i]*1500));
			g2.setColor(Color.black);
			g2.setFont(new Font("楷体",Font.PLAIN,20));
			g2.drawString(names[i], 202+110*i, 930);
			g2.setFont(new Font("楷体",Font.PLAIN,20));
			g2.drawString((ratios[i]*100)+"%",205+110*i,886-(int)(this.ratios[i]*1500));       
		}
		g2.setColor(Color.gray);
		for(int i=0;i<5;i++){
			g2.drawString(10*(i+1)+"%",115, 755-150*i); 
		}  //绘制基准
	}
	public void actionPerformed(ActionEvent e){
		father.dispose();
	}
	
}   //柱状图的显示面板
public class graphvis extends JFrame implements Serializable{     //能够进行网络传输
	    private gpanel gp;
        graphvis(int number,String[] name,float[] ratios){
        	this.gp = new gpanel(number,name,ratios,this);
        	this.setTitle("人物存在感分析");
        	this.add(this.gp);
        	this.setSize(1400,1000);
        	this.setLocation(310,50);
        	this.setVisible(true);
        	this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        }
 

}

9.功能3所要切换的面板类

package MYDESIGN;
import javax.swing.*;
import javax.swing.plaf.FontUIResource;
import java.io.*;
import java.util.regex.Pattern;
import java.awt.*;
import java.awt.event.*;
import MYDESIGN.*;
import java.util.regex.*;
public class FUN3 extends Mypanel implements ActionListener{
    private JFrame JFather;
    private JPanel jfather;
    private JTextField jtf = new JTextField(20);
    private JButton jbt1 = new JButton("肯定");
    private JButton jbt2 = new JButton("上传结果");
    private JButton jbt3 = new JButton("返回");
    private JPanel jpl = new JPanel();
    private float[] num = new float[10];  //分红10组记录出现的次数
    private densityvis dsv;
    private boolean canupload = false;
	FUN3(Mypanel jp,JFrame jf){
	  super("D:\\CourseDesign2\\FUN3.jpg");//加个图片
	  this.JFather = jf;
	  this.jfather = jp;
	  this.setLayout(new BorderLayout());
	  this.jbt1.setPreferredSize(new Dimension(200,80));
	  this.jbt1.setFont(new Font("楷体",Font.PLAIN,45));
	  this.jbt2.setPreferredSize(new Dimension(300,80));
	  this.jbt2.setFont(new Font("楷体",Font.PLAIN,45));
	  this.jbt3.setPreferredSize(new Dimension(200,80));
	  this.jbt3.setFont(new Font("楷体",Font.PLAIN,45));
	  this.jbt1.addActionListener(this);
	  this.jbt2.addActionListener(this);
	  this.jbt3.addActionListener(this);
	  this.jpl.add(jbt1);
	  this.jpl.add(jbt2);
	  this.jpl.add(jbt3);
	  this.add(jtf,BorderLayout.NORTH);
	  this.add(jpl,BorderLayout.SOUTH);
	  jtf.setFont(new Font("楷体",Font.PLAIN,35));
	  jtf.setPreferredSize(new Dimension(300,70));
  }
	
	
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==jbt1){
		if(Customer.isdownload==false){
			UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
		    UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
			JOptionPane.showMessageDialog(null,"客户端暂时还未下载文件,请点击功能1完成下载");
		}
			else{
			this.canupload = true;
			String jtfname=this.jtf.getText();
			String[] ss={"宋江","晁盖","柴进","呼延灼","卢俊义","李逵","吴用","武松","鲁智深","林冲"};
			boolean exist = false;
			for(String s:ss){
				if(jtfname.equals(s))
					exist = true;
			}
			if(exist==false){
				UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
			    UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
			    JOptionPane.showMessageDialog(null,"很抱歉"+jtfname+"不在本次分析范围内");
			    this.jtf.setText("");
		}else{
			try{
				FileReader fd = new FileReader("D:\\CourseDesign2\\水浒.txt");
				BufferedReader bfr = new BufferedReader(fd);
				String line;   //读取的每一行
				Pattern pname = Pattern.compile(jtfname);
				Matcher mch;  //创建正则表达式下的字符串匹配机制
				
				for(int i=0;i<10;i++)
					num[i]=0.0f;  
				     //初始化num[]数组
		
					for(int i=0;i<10;i++){ //求出每一个部分这个角色出现的次数		   
						for(int j =1;j<=(FUN1.linenum/10);j++){  //读入一组计算次数
						   line = bfr.readLine();
					       if(line==null)
						       break;
					       else{
                            mch = pname.matcher(line);
                            while(mch.find())
                            	num[i]+=1.0f;
					           }//else
					    }//for
				   }//for		
				fd.close();
				bfr.close();
			}catch(Exception ex){}
			
			dsv = new densityvis(this.num,jtfname);
		}//当名称属于这十我的的时候调用的else
			
			
		}	//只有下载完才能够分析,与Customer的isdownload一致
		} //来自jtf的事件处理
		if(e.getSource()==jbt2){
			 if(Customer.isdownload == false){
				 UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
 			     UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));	
 		    	JOptionPane.showMessageDialog(null,"客户端暂时还未下载水浒传,请点击功能1完成下载");
 		    }else {
 		    	if(this.canupload)
 		    	 new upload("功能3"+jtf.getText()+"出现密度图",this.dsv).send3();
 		    	else{
 		    		UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));
 	 			    UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 20)));	
 	 		    	JOptionPane.showMessageDialog(null,"您暂时尚未分析过某个角色");
 		    		}
 		    	}
 		    
 	}//jbt2处理
		
		if(e.getSource()==jbt3){
			this.jtf.setText("");
			JFather.setContentPane(jfather);
			JFather.revalidate();
		}
	}
}

10.功能3密度图所要切换的类

package MYDESIGN;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;

class dpanel extends JPanel implements ActionListener{   //密度图分析
	private JButton jbt1 = new JButton("返回");
	private float[] num;
	private float[] ratios=new float[10];
 	private float sum=0.0f;   //画图的依据
	private JFrame father;
	private String name;
	private JPanel jpl = new JPanel();
	dpanel(JFrame jf,float numbers[],String character){
		this.setLayout(new BorderLayout());
		this.father=jf;
		this.num = numbers;
		this.name = character;
		jbt1.setFont(new Font("楷体",Font.PLAIN,35));
		jbt1.setPreferredSize(new Dimension(900,60));
		this.jpl.add(jbt1);
		this.add(jpl,BorderLayout.NORTH);
		for(int i=0;i<10;i++)
			sum+=num[i];
		for(int i =0;i<10;i++)
			ratios[i] =255.0f*(num[i]/sum);  //获得颜色程度的依据		
		this.jbt1.addActionListener(this);
	}
	public void paint(Graphics g){
		Graphics2D g2 =(Graphics2D)g;
		g2.setStroke(new BasicStroke(2.0f));
		g2.setColor(Color.black);
		g2.drawLine(100,550,700,550);
		g2.drawLine(690,540,700,550);
		g2.drawLine(690,560,700,550);
		g2.setFont(new Font("楷体",Font.PLAIN,40));
		g2.drawString("开头", 80, 600);
	    g2.drawString("结束", 680, 600);
		for(int i =0 ;i<10;i++){
			g2.setColor(new Color(0,140-(int)ratios[i]/2,0));
			g2.fillRect(150+50*i,150,50,400);
		}
		g2.setColor(new Color(0,80,0));
		g2.fillRect(780,120,25,25);
		g2.setFont(new Font("楷体",Font.PLAIN,20));
		g2.setColor(Color.BLACK);
		g2.drawString("出现密度大",740,180);
		g2.setColor(new Color(0,230,0));
		g2.fillRect(780,270,25,25);
		g2.setFont(new Font("楷体",Font.PLAIN,20));
		g2.setColor(Color.BLACK);
		g2.drawString("出现密度小",740,330);
		
	}
	public void actionPerformed(ActionEvent e){
		if(e.getSource()==jbt1){
			this.father.dispose();
		}
	}
}


public class densityvis extends JFrame implements Serializable{     //能够进行网络传输
    private dpanel dp;
    densityvis(float[] number,String name){
    	this.dp = new dpanel(this,number,name);
    	this.setTitle(name+"出现密度分布");
    	this.add(this.dp);
    	this.setSize(900,680);
    	this.setLocation(520,170);
    	this.setVisible(true);
    	this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }


}

11.功能4所要切换的面板

package MYDESIGN;
import MYDESIGN.*;
import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.regex.*;
public class FUN4 extends JFrame implements Serializable,ActionListener{
    private JButton jbt1 = new JButton("返回");
    private JButton jbt2 = new JButton("上传分组结果");
    private JButton jbt3 = new JButton("人物关系分组结果");
    private JButton jbt4 = new JButton("几率矩阵");
    private JButton jbt5 = new JButton("宋江");
    private JButton jbt6 = new JButton("晁盖");
    private JButton jbt7 = new JButton("吴用");
    private JButton jbt8 = new JButton("李逵");
    private JButton jbt9 = new JButton("柴进");
    private JButton jbt10 = new JButton("呼延灼");
    private JButton jbt11 = new JButton("卢俊义");
    private JButton jbt12 = new JButton("鲁智深");
    private JButton jbt13 = new JButton("林冲");
    private JButton jbt14 = new JButton("武松");
    private JPanel  jplsouth = new JPanel();
    private JPanel  jplnorth = new JPanel();
    private JPanel  jplcenter = new JPanel();
    private JPanel  jpl1=new JPanel();
    private JPanel  jpl2 = new JPanel();
    private JPanel  jpl3 = new JPanel();
    private JPanel  jpl4 = new JPanel();
    private JPanel  mjp = new JPanel();           //主界面
    private String[] ss = {"宋江","晁盖","吴用","李逵","柴进","呼延灼","卢俊义","鲁智深","林冲","武松"};
    private Pattern[] p = new Pattern[10];
	private Matcher[] mch = new Matcher[10];
    private int[] num = new int[10];           //ss[i]出现的区间总数
    private int[][] fdship = new int[10][10];  //在i出现状况下j出现就记录亲密度矩阵
    private float[][] cdlikelyhood = new float[10][10];   //条件几率矩阵 
    FUN4(){
    	mjp.setLayout(new BorderLayout());
    	this.add(mjp);
    	this.jbt1.setPreferredSize(new Dimension(200,55));
    	this.jbt1.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt2.setPreferredSize(new Dimension(300,55));
    	this.jbt2.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt3.setPreferredSize(new Dimension(800,50));
    	this.jbt3.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt3.setContentAreaFilled(false);
    	this.jbt4.setPreferredSize(new Dimension(300,55));
    	this.jbt4.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt5.setPreferredSize(new Dimension(300,55));
    	this.jbt5.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt6.setPreferredSize(new Dimension(300,55));
    	this.jbt6.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt7.setPreferredSize(new Dimension(300,55));
    	this.jbt7.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt8.setPreferredSize(new Dimension(300,55));
    	this.jbt8.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt9.setPreferredSize(new Dimension(300,55));
    	this.jbt9.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt10.setPreferredSize(new Dimension(300,55));
    	this.jbt10.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt11.setPreferredSize(new Dimension(300,55));
    	this.jbt11.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt12.setPreferredSize(new Dimension(300,55));
    	this.jbt12.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt13.setPreferredSize(new Dimension(300,55));
    	this.jbt13.setFont(new Font("楷体",Font.PLAIN,40));
    	this.jbt14.setPreferredSize(new Dimension(300,55));
    	this.jbt14.setFont(new Font("楷体",Font.PLAIN,40));
    	jbt1.addActionListener(this);
    	jbt2.addActionListener(this);
    	jbt4.addActionListener(this);
    	this.jplnorth.setLayout(new BorderLayout());
    	this.jplsouth.add(jbt2);
    	this.jplsouth.add(jbt4);
    	this.jplsouth.add(jbt1);
    	this.jplnorth.add(jbt3,BorderLayout.CENTER);
    	mjp.add(jplsouth,BorderLayout.SOUTH);
    	mjp.add(jplnorth,BorderLayout.NORTH);
    	this.setSize(1000,800);
    	this.setLocation(380,150);
    	this.setVisible(true);
    	this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		mjp.add(jplcenter,BorderLayout.CENTER);
    	this.jplcenter.setLayout(new GridLayout(4,1));
		this.jpl1.add(jbt5);
		this.jpl1.add(jbt6);
		this.jpl1.add(jbt7);
		this.jpl1.add(jbt9);
		this.jplcenter.add(jpl1);
		this.jpl2.add(jbt8);
		this.jpl2.add(jbt10);
		this.jpl2.add(jbt11);
		this.jplcenter.add(jpl2);
		this.jpl3.add(jbt12);
		this.jpl3.add(jbt13);
		this.jplcenter.add(jpl3);
		this.jpl4.add(jbt14);
		this.jplcenter.add(jpl4);
		for(int i = 0;i<10;i++){
            num[i]=0;
			p[i]=Pattern.compile(ss[i]);   //初始化模式串
			for(int j = 0;j<10;j++)
				fdship[i][j]=0;
		} //相关变量的初始化操做
    }
    
    public void getclassification(){	
    	try{
    		FileReader fr = new FileReader("D:\\CourseDesign2\\水浒.txt");
    		BufferedReader br = new BufferedReader(fr);
    		boolean[] isshowup = new boolean[10];
    		boolean flag =false;  //while循环辅助标志,表示已经读完文件
    		String line;
    		StringBuffer lines = new StringBuffer();  //记录区间的容器
    		while(true){
    			for(int i =0;i<10;i++)
    				isshowup[i]=false;    //每一个断定区间在开始前初始化是否出现
    			for(int j = 0;j<20;j++){  //20行做为一个区间
    			   line = br.readLine();
    			   lines.append(line);
    			   if(line==null){
    				  flag =true;
    				  break;}
    			   }
    			for(int i=0;i<10;i++){
    				mch[i]=p[i].matcher(lines);
    				while(mch[i].find())
    					 isshowup[i]=true;}//判断每行ss[i]是否出现
   			for(int k =0;k<10;k++)
				if(isshowup[k])
					num[k]++;   //出现了就把出现区间总数+1	
   			for(int i =0;i<10;i++){
   				if(isshowup[i])
   				for(int j=0;j<10;j++){
   					if(isshowup[j]&&(i!=j))
   						fdship[i][j]++;    //计算在ss[i]出现的条件下ss[j]出现的几率
   				}
   			}
            if(flag)
         	   break;}//while true 循环  获得相应的num[]总区间数和相关亲密度矩阵
    		for(int i=0;i<10;i++)
    			for(int j=0;j<10;j++){
    				cdlikelyhood[i][j]=((float)fdship[i][j])/num[i];  //ss[i]出现的条件下ss[j]出现几率
    				cdlikelyhood[i][j]=(float)Math.round(cdlikelyhood[i][j]*1000)/1000;}  //控制精度
    		for(int i = 0;i<10;i++){
    			for(int j =0;j<10;j++)
    			    System.out.print(cdlikelyhood[i][j]+" ");
    			System.out.print("\n");}
    		fr.close();
    		br.close();
    	}catch(Exception ex){}
    }
    
    
    public void actionPerformed(ActionEvent e){
    	  if(e.getSource()==jbt1){
                this.dispose();   		  
    	  }else if(e.getSource()==jbt2){
    		    new upload("功能4关系分组",this).send4();;    
    	  }
    	  else if(e.getSource()==jbt4){
    		    this.getclassification();
                
    	  }
    }
}

12.最后是upload函数类

package MYDESIGN;
import java.awt.Font;
import java.io.*;
import java.net.*;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.plaf.FontUIResource;
public class upload {  //upload类是一个用于传输信息给服务器端的类,和功能2,3,4搭配使用
    private ObjectOutputStream oops;  //将接收到的类输出到文件 
    private BufferedReader bfr;       //从文件读对象
    private graphvis gpv;             //接收功能2的柱状图
    private densityvis dvs;
    private FUN4 fun4;
    private String path;        //告诉服务器端以何种文件名存储
    upload(String ph,graphvis gp){
    	this.path = ph;
    	this.gpv = gp;
    }
    upload(String ph,densityvis ds){
    	this.path = ph;
    	this.dvs = ds;
    }
    upload(String ph,FUN4 Jfun){
        this.path = ph;
        this.fun4 = Jfun;
    }
    public void send2(){
    	try{
    		FileOutputStream fos = new FileOutputStream("D:\\CourseDesign2\\功能2.txt");
    		oops = new ObjectOutputStream(fos);
    		bfr = new BufferedReader(new FileReader("D:\\CourseDesign2\\功能2.txt"));
    		oops.writeObject(this.gpv);
    		String fileline;
    		String orderline;
    		Customer.psServer.println("!@#接收客户端文件");  //向服务器端发送上传文件指令
    		Customer.psServer.println(this.path);          //向服务器端的receivefile方法发送存储地址
    		while(true){
    			fileline = bfr.readLine();
    		    if(fileline == null){
    		    	Customer.psServer.println("!@#传输完成");
    		    	break;}
    		    else{
    		    	Customer.psServer.println(fileline);
    		    	if(Customer.brServer.readLine()=="!@#继续传输")
    		    		continue;   		    	
    		    }
    		        
    		}
    		fos.close();;
    		oops.close();
    		bfr.close();
    		UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 14)));
			UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 14)));
			JOptionPane.showMessageDialog(null,"文件上传已经完成");
    	}catch(Exception ex){}
    }
    public void send3(){
    	try{
    		FileOutputStream fos = new FileOutputStream("D:\\CourseDesign2\\功能3.txt");
    		oops = new ObjectOutputStream(fos);
    		bfr = new BufferedReader(new FileReader("D:\\CourseDesign2\\功能3.txt"));
    		oops.writeObject(this.dvs);
    		String fileline;
    		String orderline;
    		Customer.psServer.println("!@#接收客户端文件");  //向服务器端发送上传文件指令
    		Customer.psServer.println(this.path);          //向服务器端的receivefile方法发送存储地址
    		while(true){
    			fileline = bfr.readLine();
    		    if(fileline == null){
    		    	Customer.psServer.println("!@#传输完成");
    		    	break;}
    		    else{
    		    	Customer.psServer.println(fileline);
    		    	if(Customer.brServer.readLine()=="!@#继续传输")
    		    		continue;   		    	
    		    }
    		        
    		}
    		fos.close();;
    		oops.close();
    		bfr.close();
    		UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 14)));
			UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 14)));
			JOptionPane.showMessageDialog(null,"文件上传已经完成");
    	}catch(Exception ex){}
    }
    public void send4(){
    	try{
    		FileOutputStream fos = new FileOutputStream("D:\\CourseDesign2\\功能4.txt");
    		oops = new ObjectOutputStream(fos);
    		bfr = new BufferedReader(new FileReader("D:\\CourseDesign2\\功能4.txt"));
    		oops.writeObject(this.fun4);
    		String fileline;
    		String orderline;
    		Customer.psServer.println("!@#接收客户端文件");  //向服务器端发送上传文件指令
    		Customer.psServer.println(this.path);          //向服务器端的receivefile方法发送存储地址
    		while(true){
    			fileline = bfr.readLine();
    		    if(fileline == null){
    		    	Customer.psServer.println("!@#传输完成");
    		    	break;}
    		    else{
    		    	Customer.psServer.println(fileline);
    		    	if(Customer.brServer.readLine()=="!@#继续传输")
    		    		continue;   		    	
    		    }
    		        
    		}
    		fos.close();;
    		oops.close();
    		bfr.close();
    		UIManager.put("OptionPane.buttonFont", new FontUIResource(new Font("楷体", Font.BOLD, 14)));
			UIManager.put("OptionPane.messageFont", new FontUIResource(new Font("楷体", Font.BOLD, 14)));
			JOptionPane.showMessageDialog(null,"文件上传已经完成");
    	}catch(Exception ex){}
    }
}

结语

这周恰巧遇到java课设,汇编实践课,高级程序设计实践,外加科学计算Gauss列主元消去法C语言实现 一块儿布置任务,要不断在面向对象,面向过程和面向CPU之间切换。总之有点晕乎乎,不过总算把java课设搞完了,这是后话了.......

相关文章
相关标签/搜索