📄 mainframe.java~141~
字号:
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jPanel23.add(subList_ScrollPanse, BorderLayout.CENTER);
jPanel18.add(jPanel23, BorderLayout.CENTER);
jPanel26.add(jPanel25, BorderLayout.NORTH);
jPanel18.add(jPanel26, BorderLayout.EAST);
jPanel24.add(new JPanel());
jPanel21.add(jPanel24, BorderLayout.CENTER);
jPanel21.add(new JPanel(), BorderLayout.NORTH);
jPanel21.add(subName, BorderLayout.SOUTH);
jPanel22.add(count, BorderLayout.SOUTH);
jPanel19.add(jPanel21);
jPanel19.add(jPanel22);
jPanel10.setBorder(titledBorder2);
jPanel10.add(jPanel18, BorderLayout.CENTER);
jPanel10.add(jPanel19, BorderLayout.NORTH);
jPanel9.add(jPanel10);
jPanel9.add(jPanel11);
jPanel2.add(close); //添加关闭按钮
jPanel2.add(help); //添加帮助按钮
jPanel3.add(importAdd);
jPanel3.add(exportCmd);
jPanel4.setBorder(titledBorder1);
jPanel4.add(jPanel8, BorderLayout.NORTH);
jPanel4.add(jPanel9, BorderLayout.CENTER);
jPanel6.setBorder(titledBorder4);
jPanel7.setBorder(titledBorder5);
jPanel5.add(jPanel6);
jPanel5.add(jPanel7);
jPanel1.add(jPanel3, BorderLayout.NORTH);
jPanel1.add(jPanel4, BorderLayout.CENTER);
jPanel1.add(jPanel5, BorderLayout.SOUTH);
fileSetPane.add(jPanel1, "配置"); //添加面板到标签页面板上
contentPane = (JPanel) getContentPane(); //获得内容窗格
contentPane.setLayout(borderLayout1); //设置主面板的布局
contentPane.add(fileSetPane); //添加标签页面板,默认位置是主面板的中间位置
contentPane.add(jPanel2, BorderLayout.SOUTH); //添加关闭帮助按钮的面板到内容面板的南边
setTitle("文件检索系统"); //设置标题
new FrameSizes().setFrameSize(this);//设置界面显示大小
//以下部分为按钮的事件处理
levCount.addFocusListener(new CheckCountOfLev(levCount)); //为levCount添加焦点的监听器()
close.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);//关闭按钮的事件:退出程序()
}
});
exportCmd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String path = new SaveAndLoad("save").getFilePath();//获取保存文件的绝对路径
new Save(path,subList,fileList,other()).SaveFile();
}
});//导出文件配置
importAdd.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String path = new SaveAndLoad("load").getFilePath();//获取导入文件的绝对路径
//读取文件中的各个配置选项
String[] content = new Load(path).getAllContent();
int content_len = content.length;//数组的长度
//1:定位数组中每项内容,就是定位-l,-d,-fm,-f,-v,-s各项在数组中的位置
int ii = 1, jj = ii;
//2:可以将数组中的第一项及倒数两项直接附值到相对应的控件上,如-l附值到levCount文本框中
levCount.setText(content[0].substring(3));//数组的第一项是 "-l加空格加数值";所以将值取出来时,应该从第三个字母开始
String str1 = content[content_len-2].substring(3);//结果显示配置
String str2 = content[content_len-1].substring(3);//结果排序方式
String str3 ;
String[] str4 ;//sub文件的
String[] str5 ;//file文件的
for(int i = 1; i < content_len; i++){
if(content[i].startsWith("-d ")){
jj++;
}
else{
break;
}
}
if(jj > 1){
str4 = new String[jj-1];//sub文件的
System.arraycopy(content,1,str4,0,jj-1);//将开头包含"-d "的项复制到str4中
subDefault.removeAllElements();//导入时,先将原有的内容清除
for(int i = 0; i < str4.length; i++){
str4[i] = str4[i].substring(3).trim();//再将"-d "去掉,剩余部分再存进str4数组中
///////////////////subDefault.clear();
subDefault.addElement(str4[i]);//再将str4中的值设置到JList中
}
}
int kk = content_len -2 - jj;
if(kk > 0){
str5 = new String[kk];//设置长度大小为:在"-fm "到"-v "之间"距离"
System.arraycopy(content,jj+1,str5,0,kk);
fileDefault.removeAllElements();//导入时,先将原有的内容清除
for(int i = 0 ; i < kk; i++){
str5[i] = str5[i].substring(4).trim();
fileDefault.addElement(str5[i]);
}
}
//接下来可找到-fm的位置(因为它是必定出现的)
str3 = content[jj].substring(4).trim();
//System.out.println(str3);
if(str3.equals("in")){
option1.setSelected(true);
}
else if(str3.equals("ex")){
option2.setSelected(true);
}
switch(Integer.parseInt(str1)){
case 7:
check3.setSelected(true);break;//设置check3为被选中的状态
case 6:
check3.setSelected(false);break;//设置不为被选中的状态
}
if(str2.equals("fn")){
option3.setSelected(true);
}
else if (str2.equals("sz")) {
option5.setSelected(true);
}
else {
option4.setSelected(true);
}
}
});//导入配置文件
subAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String subName = subDir.getText().trim();
String subLength = subLev.getText().trim();
String all = subName + ":" + subLength;
String reg = "\\s+[^\\S+]";//匹配一个或多个空格
if(subName.equals(null)||subName.matches(reg)){
JOptionPane.showMessageDialog(new JFrame(),"文件名不能为空!");
}
else{
if(subName.length()>128){
JOptionPane.showMessageDialog(new JFrame(),"文件名太长,文件名长度范围是[1,128]字节!");
}
else{
subLev.addFocusListener(new CheckCountOfLev(subLev)); //为levCount添加焦点的监听器()
new AddFile(subDefault, subList, all.toUpperCase()).addFileItem();
}
}
}
});//添加一项
subDel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int len = subList.getModel().getSize();
if(len == 0){//先判断List列表不为空
JOptionPane.showMessageDialog(new JFrame(),"列表框已经为!");
}
else
{
int index = subList.getSelectedIndex();//被选中的项的位置
if ( -1 == index) { //判断是否有内容被选中
JOptionPane.showMessageDialog(new JFrame(),
"你必须在列表框中选中需要删除的设置项!");
} else {
subDefault.removeElementAt(index);
}
}
}
});//删除列表中的一项ok
subDelAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
subDefault.removeAllElements();
}
});//删除列表中的全部内容ok
fileAdd.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String fileName = fileSet.getText().trim();
String reg = "\\s+[^\\S+]";//匹配一个或多个空格
if(fileName.equals(null)||fileName.matches(reg)){
JOptionPane.showMessageDialog(new JFrame(),"文件名不能为空!");
}
else{
if(fileName.length()>128){
JOptionPane.showMessageDialog(new JFrame(),"文件名太长,文件名长度范围是[1,128]字节!");
}
else{
new AddFile(fileDefault, fileList, fileName.toUpperCase()).
addFileItem();
}
}
}
});//添加一项
fileDel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int len = fileList.getModel().getSize();
if(len == 0){//先判断List列表不为空
JOptionPane.showMessageDialog(new JFrame(),"列表框已经为空!");
}
else{
int index = fileList.getSelectedIndex();//被选中的项的位置
if ( -1 == index) {//判断是否有内容被选中
JOptionPane.showMessageDialog(new JFrame(),
"你必须在列表框中选中需要删除的设置项!");
}
else{//有内容被选中
fileDefault.removeElementAt(index);
}
}
}
});//删除列表中的一项ok
fileDelAll.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fileDefault.removeAllElements();
}
});////删除列表中的全部内容ok
}
public String[] other(){//将部分内容,放入数组中...
String[] others = new String[4];
//根目录检索层次
others[0] = levCount.getText();
//包含/排除
if(option1.isSelected()){
others[1] = "in";//文件包含
}
else if(option2.isSelected()){
others[1] = "ex";//文件排除
}
else{}//end of the if
//结果显示配置
if(check3.isSelected()){
others[2] = "7";
}
else{
others[2] = "6";//默认值为6
}//end of the if
//结果排序方式
if(option3.isSelected()){
others[3] = "fn";//按文件名
}
else if(option5.isSelected()){
others[3] = "sz";//按文件规模
}
else{
others[3] = "pn";//按文件相对路径
}
return others;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -