package HashMap;
import java.lang.Math;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import java.awt.Font;
import java.awt.Color;
import javax.swing.ScrollPaneConstants;
public class Window extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField textField; // 关键字输入框
private JTextField textField_1; // 源码1输入框
private JTextField textField_2; // 源码2输入框
private JTextField textField_3; // 结果输出框
private JTextField textField_u;
public String[] Change(String s) { // 消除字符串中所有的标点符号和多余的空格
int point = 0;
String[] r = new String[s.length()];
String buf = new String();
StringBuffer buffer = new StringBuffer();
r = s.split("\\s+");
for (int i = 0; i < r.length; i++) {
buffer.append(r[i]);
buffer.append(" ");
}
buf = buffer.toString();
char[] c = buf.toCharArray();
for (int i = 0; i < c.length; i++) { // 把所有标点符号变为空格
if (c[i] == '`' || c[i] == '~' || c[i] == '!' || c[i] == '@' || c[i] == '#' || c[i] == '$' || c[i] == '%'
|| c[i] == '^' || c[i] == '&' || c[i] == '*' || c[i] == '(' || c[i] == ')' || c[i] == '-'
|| c[i] == '=' || c[i] == '+' || c[i] == '[' || c[i] == ']' || c[i] == '{' || c[i] == '}'
|| c[i] == '\\' || c[i] == '|' || c[i] == ';' || c[i] == ':' || c[i] == '\'' || c[i] == '"'
|| c[i] == ',' || c[i] == '<' || c[i] == '.' || c[i] == '>' || c[i] == '/' || c[i] == '?') {
c[i] = ' ';
}
}
for (int i = 0; i < c.length; i++) {
if (c[i] == ' ') {
continue;
} else {
point = i;
break;
}
}
char[] c1 = new char[c.length - point]; // 把第一个非空格字符前的所有空格去掉
for (int i = 0; i < c1.length; i++) {
c1[i] = c[i + point];
}
buffer = new StringBuffer();
for (int i = 0; i < c1.length; i++) {
buffer.append(c1[i]);
}
buf = buffer.toString();
r = buf.split("\\s+"); // 去掉多余的空格,确保每个字符间只有一个空格
return r;
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Window frame = new Window(); // 创建主窗口
frame.setLocationRelativeTo(null); // 让主窗口在屏幕中间
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace(); // 在命令行打印异常信息在程序中出错的位置及原因
}
}
});
}
/**
* Create the frame.
*/
public Window() {
setTitle("源码相似性检验");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 1315, 692);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton btnNewButton = new JButton("确定");
btnNewButton.setBackground(Color.YELLOW);
btnNewButton.setFont(new Font("宋体", Font.PLAIN, 20));
btnNewButton.setBounds(603, 489, 97, 23);
contentPane.add(btnNewButton);
JTextArea textArea = new JTextArea(); // 关键字输入窗口
JScrollPane pane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
pane.setBounds(10, 40, 618, 115);
contentPane.add(pane);
JTextArea textArea_u = new JTextArea(); // 用户表示符输入窗口
JScrollPane pane_u = new JScrollPane(textArea_u, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
pane_u.setBounds(673, 40, 618, 115);
contentPane.add(pane_u);
JTextArea textArea_1 = new JTextArea(); // 源码1输入窗口
JScrollPane pane1 = new JScrollPane(textArea_1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
pane1.setBounds(10, 189, 618, 290);
contentPane.add(pane1);
JTextArea textArea_2 = new JTextArea(); // 源码2输入窗口
JScrollPane pane2 = new JScrollPane(textArea_2, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
pane2.setBounds(673, 189, 618, 290);
contentPane.add(pane2);
JTextArea textArea_3 = new JTextArea(); // 结果输出窗口
textArea_3.setEditable(false);
JScrollPane pane3 = new JScrollPane(textArea_3, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
pane3.setBounds(10, 522, 1281, 104);
contentPane.add(pane3);
textField = new JTextField();
textField.setBackground(Color.PINK);
textField.setEditable(false);
textField.setFont(new Font("宋体", Font.PLAIN, 22));
textField.setText("关键字输入");
textField.setBounds(10, 2, 123, 28);
contentPane.add(textField);
textField.setColumns(10);
textField_u = new JTextField();
textField_u.setFont(new Font("宋体", Font.PLAIN, 22));
textField_u.setText("用户标识符输入");
textField_u.setEditable(false);
textField_u.setBackground(Color.PINK);
textField_u.setBounds(1127, 2, 164, 28);
contentPane.add(textField_u);
textField_u.setColumns(10);
textField_1 = new JTextField();
textField_1.setBackground(Color.ORANGE);
textField_1.setFont(new Font("宋体", Font.PLAIN, 22));
textField_1.setText("源码1输入");
textField_1.setEditable(false);
textField_1.setBounds(10, 158, 123, 28);
contentPane.add(textField_1);
textField_1.setColumns(10);
textField_2 = new JTextField();
textField_2.setEditable(false);
textField_2.setFont(new Font("宋体", Font.PLAIN, 22));
textField_2.setBackground(Color.ORANGE);
textField_2.setText("源码2输入");
textField_2.setBounds(1175, 158, 116, 30);
contentPane.add(textField_2);
textField_2.setColumns(10);
textField_3 = new JTextField();
textField_3.setEditable(false);
textField_3.setBackground(Color.YELLOW);
textField_3.setFont(new Font("宋体", Font.PLAIN, 22));
textField_3.setText("源码关键字频度及相似性");
textField_3.setBounds(10, 489, 256, 31);
contentPane.add(textField_3);
textField_3.setColumns(10);
btnNewButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
// TODO Auto-generated method stub
double distance = 0, distance_u = 0; // 源码1和源码2的“相对距离” 关键字和用户标识符的
double[] data1, data2, data1_u, data2_u; // 存源码1和源码2基于关键字的value值和基于用户标识符的value值
String in = new String(), in_u = new String(), buf = new String(), input1 = new String(),
input2 = new String();// 关键字输入in、用户标识符输入in_u、临时用的缓存、源码1输入input1,源码2输入input2
String[] library = null, library_u = null, library1 = null, library2 = null; // 存关键字,用户标识符,源码1,源码2的string数组
StringBuffer buffer = new StringBuffer(); // string的中介
HashList list = new HashList(), list_u = new HashList(), list1 = new HashList(),
list2 = new HashList(), list1_u = new HashList(), list2_u = new HashList(); // 关键字、用户标识符、源码1和源码2分别关于关键字和用户标识符的hash表
int num = 0, num_u = 0; // 关键字和用户标识符的个数
try {
in = textArea.getText(); // 关键字的输入
library = Change(in);
for (int i = 0; i < library.length; i++) { // 创建关键字的hash表
buffer = new StringBuffer();
buffer.append(library[i]);
buf = buffer.toString();
if (
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Hash.zip (12个子文件)
Hash
src
HashMap
Node.java 384B
Window.java 15KB
HashList.java 3KB
Warning.java 1KB
bin
HashMap
Warning$2.class 662B
Window$2.class 6KB
Window$1.class 793B
Warning.class 2KB
Node.class 561B
Window.class 5KB
HashList.class 3KB
Warning$1.class 729B
共 12 条
- 1
资源评论
HaibaraAiii
- 粉丝: 25
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功