📄 checkout.java
字号:
package yy;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//---------------------------------------检验文档类
public class Checkout extends JFrame{
JTextField jfield;//-----------------文件名地址栏
JTextField jfield2;//-----------------另存为文件名地址栏
JTextArea jarea;//--------------------文本内容显示框
JButton b;//--------------------------确定按钮
JButton b3;//-------------------------重检验按钮
JButton b4;//-------------------------选择字典按钮
JButton b5;//-------------------------打开按钮
JButton b6;//-------------------------注释按钮
JLabel label;//-----------------------文件名
JComboBox jbox;//---------------------保存下拉列表
JList show;//-------------------------显示出错单词位置
Font font = new Font("宋体",Font.PLAIN,13);
JPanel content=(JPanel)this.getContentPane();//面版
String address;//----------------------用来保存文件名
String str1;//-------------------------字典名
String str2;//-------------------------校验的文件名
String str3;//-------------------------另存文件名
String str4;//-------------------------结果保存文件名
String str5;//-------------------------存放错误单词
//----------------------------------------构造方法
public Checkout(){
label=new JLabel("文件名:");//----构造界面
label.setFont(font);
jfield=new JTextField(10);
jarea=new JTextArea(13,36);
JPanel pp=new JPanel();
pp.setLayout(new BorderLayout());
JLabel ll=new JLabel("出错单词:");
ll.setFont(font);
show=new JList();
show.setVisibleRowCount(10);
show.setFixedCellHeight(22);
show.setFixedCellWidth(150);
show.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
pp.add(ll,BorderLayout.NORTH);
pp.add(new JScrollPane(show),BorderLayout.CENTER);
String[] items={"保存","另存为","保存结果"};
b=new JButton("确定");
b.setFont(font);
b3=new JButton("重校验");
b3.setFont(font);
b4=new JButton("选择字典");
b4.setFont(font);
b5=new JButton("打开");
b5.setFont(font);
b6=new JButton("关于..");
b6.setFont(font);
b.setPreferredSize(new Dimension(60,22));
b3.setPreferredSize(new Dimension(80,22));
b4.setPreferredSize(new Dimension(90,22));
b5.setPreferredSize(new Dimension(60,22));
b6.setPreferredSize(new Dimension(100,22));
jbox=new JComboBox(items);
jbox.setFont(font);
jbox.setPreferredSize(new Dimension(80,22));
b.addActionListener(new ActionListener(){//确定按钮的监听器
public void actionPerformed(ActionEvent event){
jarea.selectAll();
jarea.cut();
b_action(event);
}
});
b4.addActionListener(new ActionListener(){//选择字典按钮的监听器
public void actionPerformed(ActionEvent eve){
b4_action(eve);
}
});
b5.addActionListener(new ActionListener(){//浏览按钮的监听器
public void actionPerformed(ActionEvent event){
jarea.selectAll();
jarea.cut();
b5_action(event);
}
});
b3.addActionListener(new ActionListener(){//重校验按钮的监听器
public void actionPerformed(ActionEvent e){
FileCopy c=new FileCopy();//--------文件复制类对象
String jj=jarea.getText();
c.FileCopy(jj,address);//------------文件类构造方法
jarea.selectAll();
jarea.cut();
b_action(e);
}
});
jbox.addActionListener(new ActionListener(){//下拉列表的监听器
public void actionPerformed(ActionEvent ee){
jbox_action(ee);
}
});
b6.addActionListener(new ActionListener(){//下拉列表的监听器
public void actionPerformed(ActionEvent b){
b6_action(b);
}
});
content.setLayout(new FlowLayout());
content.add(b4);
content.add(label);
content.add(jfield);
content.add(b);
content.add(b5);
content.add(b3);
content.add(jbox);
content.add(new JScrollPane(jarea));
content.add(pp);
content.add(b6);
setSize(new Dimension(600,350));
setTitle("单词校验");
show();
}
//----------------------------------------------确定按钮的监听类方法
private void b_action(ActionEvent e){
address=jfield.getText();
Compare com=new Compare();
try{com.Compare(address,str1);
com.Readin();}
catch(IOException er){;}
str5=com.str2;
jarea.setText(com.str1);
show.setListData(com.string);
}
//----------------------------------------------选择字典按钮监听器类方法
private void b4_action(ActionEvent e){
FileDialog fd=new FileDialog(this,"选择字典文件");
fd.setFont(font);
fd.setSize(300,100);
fd.show();
str1=fd.getDirectory()+fd.getFile();
}
//----------------------------------------------打开按钮监听器类方法
private void b5_action(ActionEvent e){
FileDialog fd2=new FileDialog(this,"打开");
fd2.setFont(font);
fd2.setSize(300,100);
fd2.show();
str2=fd2.getDirectory()+fd2.getFile();
jfield.setText(str2);
}
//----------------------------------------------下拉列表的监听器类方法
private void jbox_action(ActionEvent e){
int index=jbox.getSelectedIndex();
FileCopy c=new FileCopy();
String jj=jarea.getText();
if(index==0)//--------------------------选择保存
c.FileCopy(jj,address);
else if(index==1)//---------------------选择另存为
{FileDialog fd3=new FileDialog(this,"另存为",1);
fd3.setFont(font);
fd3.setSize(300,100);
fd3.show();
str3=fd3.getDirectory()+fd3.getFile();
c.FileCopy(jj,str3);
}
else if(index==2)//---------------------选择保存结果
{FileDialog fd4=new FileDialog(this,"保存结果",1);
fd4.setFont(font);
fd4.setSize(300,100);
fd4.show();
str4=fd4.getDirectory()+fd4.getFile();
c.FileCopy(str5,str4);
}
}
private void b6_action(ActionEvent b){
JOptionPane.showMessageDialog(content,"软件制作者: 曾斌 庄白雯\n该软件可用于校验文本文件的拼写错误.\n功能:1、选择文件\n 2、选择字典\n 3、检错\n 4、对文本修改\n 5、保存\n 6、重校验\n");
}
//--------------------------------------主方法
public static void main(String args[]){
Checkout demo=new Checkout();
demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -