⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.java

📁 该系统是一个文件配置与检索的系统,该文件主要是关于该系统的一些测试文档等.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package test;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.DefaultListModel;
import javax.swing.JTextField;
import javax.swing.text.*;
import javax.swing.border.TitledBorder;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JOptionPane;

public class MainFrame extends JFrame{
    //各按钮定义
    private JButton importAdd;//导入按钮
    private JButton exportCmd;//导出按钮
    private JButton subAdd;//左边的添加按钮
    private JButton subDel;//左边的删除按钮
    private JButton subDelAll;//左边的清空按钮
    private JButton fileAdd;//右边的添加按钮
    private JButton fileDel;//右边的删除按钮
    private JButton fileDelAll;//右边的清空按钮
    private JButton close;//关闭按钮
    private JButton help;//帮助按钮
    //各列表定义
    private JList fileList;//左边的列表----子文件
    private JList subList;//右边的列表----文件
    //各文本框定义
    private JTextField levCount;//根目录检索的层次
    private JTextField fileSet;//文件名
    private JTextField subDir;//子目录名
    private JTextField subLev;//子目录名的层次数
    //各标签定义
    private JLabel rootCount;//根目录检索层次
    private JLabel subName;//子目录名
    private JLabel count;//层次数
    private JLabel fileName;//文件名
    //各面板定义
    private JTabbedPane fileSetPane;//配置标签面板
    private JPanel jPanel1;
    private JPanel jPanel2;
    private JPanel jPanel3;
    private JPanel jPanel4;
    private JPanel jPanel5;
    private JPanel jPanel6;
    private JPanel jPanel7;
    private JPanel jPanel8;
    private JPanel jPanel9;
    private JPanel jPanel10;
    private JPanel jPanel11;
    private JPanel jPanel12;
    private JPanel jPanel13;
    private JPanel jPanel14;
    private JPanel jPanel15;
    private JPanel jPanel16;
    private JPanel jPanel17;
    private JPanel jPanel18;
    private JPanel jPanel19;
    private JPanel jPanel20;
    private JPanel jPanel21;
    private JPanel jPanel22;
    private JPanel jPanel23;
    private JPanel jPanel24;
    private JPanel jPanel25;
    private JPanel jPanel26;
    private JPanel contentPane;
    //滚动面板定义
    private JScrollPane fileList_ScrollPanse;//放置fileList的滚动面板
    private JScrollPane subList_ScrollPanse;//放置subList的滚动面板
    //复选框定义
    private JCheckBox check1;//显示文件名
    private JCheckBox check2;//显示相对路径名
    private JCheckBox check3;//显示文件规模
    //单选框定义
    private JRadioButton option1;//文件包含
    private JRadioButton option2;//文件排除
    private JRadioButton option3;//按文件名
    private JRadioButton option4;//按相对路径名
    private JRadioButton option5;//按文件规模
    private ButtonGroup buttonGroup1;
    private ButtonGroup buttonGroup2;
    //定义布局类型
    private BorderLayout borderLayout1;
    private BorderLayout borderLayout2;
    private FlowLayout flowLayout1;
    private FlowLayout flowLayout2;
    private GridLayout girdLayout1;
    private GridLayout girdLayout2;
    private GridLayout girdLayout3;
    private GridLayout girdLayout4;
    private GridBagLayout gridBageLayout1;
    private GridBagLayout gridBageLayout2;
    private TitledBorder titledBorder1;//加在panel4上的标题
    private TitledBorder titledBorder2;//加在panel10上的标题
    private TitledBorder titledBorder3;//加在panel11上的标题
    private TitledBorder titledBorder4;//加在panel6上的标题
    private TitledBorder titledBorder5;//加在panel7上的标题
    public DefaultListModel subDefault;
    public DefaultListModel fileDefault;

    public MainFrame() {
        try {
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            initFrame();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void initFrame() throws Exception {
        //对象实例化
        option3 = new JRadioButton("按文件名");
        option4 = new JRadioButton("按相对路径名",true);//默认为选中状态
        option5 = new JRadioButton("按文件规模");
        buttonGroup1 = new ButtonGroup();
        buttonGroup1.add(option4);
        buttonGroup1.add(option3);
        buttonGroup1.add(option5);
        option1 = new JRadioButton("文件包含", true); //默认为选中状态
        option2 = new JRadioButton("文件排除");
        buttonGroup2 = new ButtonGroup();
        buttonGroup2.add(option1);
        buttonGroup2.add(option2);
        flowLayout1 = new FlowLayout();
        flowLayout1.setAlignment(FlowLayout.RIGHT); //设置布局右对齐
        flowLayout2 = new FlowLayout();
        flowLayout2.setAlignment(FlowLayout.LEFT);
        girdLayout1 = new GridLayout(1, 2);
        girdLayout2 = new GridLayout(2, 2);
        girdLayout3 = new GridLayout(2, 2);
        girdLayout4 = new GridLayout(1, 2);
        borderLayout1 = new BorderLayout();
        borderLayout2 = new BorderLayout();
        gridBageLayout1 = new GridBagLayout();
        gridBageLayout2 = new GridBagLayout();
        titledBorder1 = new TitledBorder("文件检索配置");
        titledBorder2 = new TitledBorder("子目录检索配置");
        titledBorder3 = new TitledBorder("包含/排除文件");
        titledBorder4 = new TitledBorder("结果显示配置");
        titledBorder5 = new TitledBorder("结果排序方式");
        fileSetPane = new JTabbedPane();
        jPanel1 = new JPanel(borderLayout2);
        jPanel2 = new JPanel(flowLayout1);
        jPanel3 = new JPanel(flowLayout1); //上
        jPanel4 = new JPanel(new BorderLayout()); //中
        jPanel5 = new JPanel(girdLayout1); //下
        jPanel6 = new JPanel(girdLayout2); //下1:结果显示配置面板
        jPanel7 = new JPanel(girdLayout3); //下2:结果排序方式面板
        jPanel8 = new JPanel(flowLayout2);
        jPanel9 = new JPanel(girdLayout1);
        jPanel10 = new JPanel(new BorderLayout()); //子目录检索配置面板
        jPanel11 = new JPanel(new BorderLayout()); //包含/排除文件面板
        jPanel12 = new JPanel(new BorderLayout());
        jPanel13 = new JPanel(new BorderLayout());
        jPanel14 = new JPanel(flowLayout2);
        jPanel15 = new JPanel(new BorderLayout());
        jPanel16 = new JPanel(gridBageLayout1);
        jPanel17 = new JPanel(new BorderLayout());
        jPanel18 = new JPanel(new BorderLayout());
        jPanel19 = new JPanel(girdLayout4);
        jPanel21 = new JPanel(new BorderLayout());
        jPanel22 = new JPanel(new BorderLayout());
        jPanel23 = new JPanel(new BorderLayout());
        jPanel24 = new JPanel();
        jPanel25 = new JPanel(gridBageLayout2);
        jPanel26 = new JPanel(new BorderLayout());
        jPanel20 = new JPanel(new BorderLayout());
        importAdd = new JButton("引入配置");
        exportCmd = new JButton("引出配置");
        subAdd = new JButton("添加");
        subDel = new JButton("删除");
        subDelAll = new JButton("清空");
        fileAdd = new JButton("添加");
        fileDel = new JButton("删除");
        fileDelAll = new JButton("清空");
        close = new JButton("关闭");
        help = new JButton("帮助");
        levCount = new JTextField();
        subLev = new JTextField();
        rootCount = new JLabel("根目录检索层次");
        subName = new JLabel("子目录名");
        count = new JLabel("层次数");
        fileName = new JLabel("文件名");
        levCount = new JTextField(5);
        levCount.setText("0");
        fileSet = new JTextField();
        subDir = new JTextField();
        subLev = new JTextField(7);
        subLev.setText("0");
        check1 = new JCheckBox("显示文件名", true);
        check1.setEnabled(false);
        check2 = new JCheckBox("显示相对路径名", true);
        check2.setEnabled(false);
        check3 = new JCheckBox("显示文件规模");
        subDefault = new DefaultListModel();
        fileDefault = new DefaultListModel();
        fileList = new JList(fileDefault); //文件列表框
        fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION );
        subList = new JList(subDefault); //子文件列表框
        subList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION );
        jPanel7.add(new JPanel());
        jPanel7.add(option4);
        jPanel7.add(option3);
        jPanel7.add(option5);
        jPanel6.add(new JPanel());
        jPanel6.add(check2);
        jPanel6.add(check1);
        jPanel6.add(check3);
        jPanel8.add(rootCount);
        jPanel8.add(levCount);
        jPanel14.add(option1);
        jPanel14.add(option2);
        jPanel13.add(jPanel14, BorderLayout.NORTH);
        jPanel13.add(fileName, BorderLayout.SOUTH);
        GridBagConstraints c1 = new GridBagConstraints();
        c1.gridx = 0;
        c1.gridy = 0;
        jPanel16.add(fileAdd, c1);
        c1.gridy = 1;
        jPanel16.add(fileDel, c1);
        c1.gridy = 2;
        jPanel16.add(fileDelAll, c1);
        jPanel15.add(fileSet, BorderLayout.NORTH);
        fileList_ScrollPanse = new JScrollPane(fileList,
                                       JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                       JScrollPane.
                                       HORIZONTAL_SCROLLBAR_AS_NEEDED);
        jPanel15.add(fileList_ScrollPanse, BorderLayout.CENTER);
        jPanel17.add(jPanel16, BorderLayout.NORTH);
        jPanel12.add(jPanel15, BorderLayout.CENTER);
        jPanel12.add(jPanel17, BorderLayout.EAST);
        jPanel11.setBorder(titledBorder3);
        jPanel11.add(jPanel12, BorderLayout.CENTER);
        jPanel11.add(jPanel13, BorderLayout.NORTH);
        GridBagConstraints c2 = new GridBagConstraints();
        c2.gridx = 0;
        c2.gridy = 0;
        jPanel25.add(subAdd, c2);
        c2.gridy = 1;
        jPanel25.add(subDel, c2);
        c2.gridy = 2;
        jPanel25.add(subDelAll, c2);
        jPanel20.add(subDir, BorderLayout.CENTER);
        jPanel20.add(subLev, BorderLayout.EAST);
        jPanel23.add(jPanel20, BorderLayout.NORTH);
        subList_ScrollPanse = new JScrollPane(subList,
                                       JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                       JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -