要求
1、20万字以上长篇小说存到服务器中,格式自定,一般存储为文本文档。
2、该程序支持从服务器载入小说,对小说中的文本进行分析。
3、首先运行服务器。服务器运行之后,可以连接1个客户端。
4、运行客户端。用户能够输入昵称,确定,则连接到服务器。连接成功,即可出现功能界面。
客户端功能界面如下:
1、功能1:载入小说。能够选择服务器端的小说。
2、功能2:任意设置10个人姓名(可以预设置在客户端界面上),将这10个人在小说中的存在感进行排名,用柱状图表示。点击按钮,存在感排名的柱状图可以保存到服务器端。
3、每个人在小说中活跃的位置是不一样的。任意输入10人中的1人,显示他在小说中出现的密度,画出密度图。建议用颜色深浅表示密度。点击按钮,密度图可以保存到服务器端。
4、如果两人在相距较短的一段文字中出现,我们认为两人有关系,距离越短,关系越近;如果多次在较短篇幅出现,则关系更近。对这10个人,根据他们关系的紧密程度进行归类,并用图形形式直观表示。点击按钮,紧密程度归类的图像内容,可以保存到服务器端。
部分代码
package server;
import java.net.*;
import java.io.*;
public class Server{
private ServerSocket ss;
private static Socket socket;
public Server() {
try {
ss=new ServerSocket(9999);
socket=ss.accept();
}catch(Exception ex) {
ex.printStackTrace();
}
}
public static void main(String[] args) throws Exception{
new Server();
}
}
package client;
import java.net.*;
public class Client{
public static Socket socket;
public static void main(String[] args) throws Exception{
try {
socket=new Socket("127.0.0.1",9999);
new MyJFrame();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
package client;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MyJFrame extends JFrame implements ActionListener{
private JPanel jpl=new JPanel();;
private JButton btConnect=new JButton("确定");
private int function;
private String name;
private JTextField tfAcc1;
public MyJFrame() {
super("客户端");
JLabel lblAcc=new JLabel("输入昵称:");
JTextField tfAcc=new JTextField(10);
jpl.add(lblAcc);
jpl.add(tfAcc);
this.add(jpl);
this.add(btConnect,BorderLayout.SOUTH);
btConnect.addActionListener(this);
this.setLocation(1000,450);
this.setSize(350,100);
this.setVisible(true);
function=0;
}
public void JFrame1() {
JLabel jl=new JLabel("请选择小说");
ButtonGroup bgSex=new ButtonGroup();
JRadioButton rbTxt1=new JRadioButton("万历十五年",false);
JRadioButton rbTxt2=new JRadioButton("明朝那些事儿",false);
JRadioButton rbTxt3=new JRadioButton("三国演义",false);
jpl.removeAll();
jpl.repaint();
this.setTitle("已成功连接服务器!");
jpl.add(jl);
bgSex.add(rbTxt1);
bgSex.add(rbTxt2);
bgSex.add(rbTxt3);
jpl.add(rbTxt1);
jpl.add(rbTxt2);
jpl.add(rbTxt3);
this.add(jpl);
this.setLocation(1000,450);
this.setSize(450,100);
this.setVisible(true);
function=1;
}
public void JFrame2() throws Exception{
JLabel jl1=new JLabel("10位人物");
JLabel jl2=new JLabel("朱元璋、朱棣、朱允炆、蓝玉、冯胜、刘基、李文忠、常遇春、方孝孺、杨士奇");
JLabel jl3=new JLabel("点击确定生成人物存在感柱状图");
jpl.removeAll();
jpl.repaint();
this.setTitle("功能2:人物存在感");
jpl.add(jl1);
jpl.add(jl2);
jpl.add(jl3);
this.add(jpl);
this.setLocation(1000,450);
this.setSize(500,150);
this.setVisible(true);
function=2;
}
public void JFrame3() throws Exception{
JLabel jl1=new JLabel("已生成人物存在感柱状图");
JLabel jl2=new JLabel("点击确定进入功能3");
jpl.removeAll();
jpl.repaint();
jpl.add(jl1);
jpl.add(jl2);
this.add(jpl);
this.setLocation(1000,450);
this.setSize(300,100);
this.setVisible(true);
function=3;
}
public void JFrame4() throws Exception{
JLabel jl1=new JLabel("10位");
JLabel jl2=new JLabel("朱元璋、朱棣、朱允炆、蓝玉、冯胜、刘基、李文忠、常遇春、方孝孺、杨士奇");
JLabel lblAcc=new JLabel("输入人物名:");
tfAcc1=new JTextField(10);
JLabel jl3=new JLabel("点击确定生成该人物出现密度图");
jpl.removeAll();
jpl.repaint();
this.setTitle("功能3:人物出现密度");
jpl.add(jl1);
jpl.add(jl2);
jpl.add(lblAcc);
jpl.add(tfAcc1);
jpl.add(jl3);
this.add(jpl);
this.setLocation(1000,450);
this.setSize(500,150);
this.setVisible(true);
function=4 ;
}
public void JFrame5() throws Exception{
JLabel jl1=new JLabel("已生成"+name+"密度图");
JLabel jl2=new JLabel("点击确定进入功能4");
jpl.removeAll();
jpl.repaint();
jpl.add(jl1);
jpl.add(jl2);
this.add(jpl);
this.setLocation(1000,450);
this.setSize(500,150);
this.setVisible(true);
function=5;
}
public void JFrame6() throws Exception{
JLabel jl1=new JLabel("点击确定生产人物关系图");
jpl.removeAll();
jpl.repaint();
this.setTitle("功能4:人物关系");
jpl.add(jl1);
this.add(jpl);
this.setLocation(1000,450);
this.setSize(300,100);
this.setVisible(true);
function=6;
}
public void actionPerformed(ActionEvent e){
if(function==0){
this.JFrame1();
}
else if(function==1) {
try {
Save.saveTxt(Client.socket);
this.JFrame2();
}catch(Exception ex) {}
}
else if(function==2) {
try {
Histogram his = new Histogram();
his.setVisible(true);
this.JFrame3();
}catch(Exception ex) {}
}
else if(function==3) {
try {
Save.savaJpg1();
this.JFrame4();
}catch(Exception ex) {}
}
else if(function==4) {
try {
name=tfAcc1.getText();
Density.name=name;
Density dp=new Density();
dp.setVisible(true);
this.JFrame5();
}catch(Exception ex) {}
}
else if(function==5) {
try {
Save.savaJpg2();
this.JFrame6();
}catch(Exception ex) {}
}
else if(function==6) {
try {
Relation ra=new Relation();
ra.setVisible(true);
Save.savaJpg3();
function=7;
}catch(Exception ex) {}
}
else if(function==7) {
try {
Save.savaJpg3();
}catch(Exception ex) {}
}
}
}