Java图形化界面输入输出

JavaGUI,
输入输出框,多选按钮,资源管理器,文件上传,重置图形化,滚动条。

package com.westos.gui;

import com.westos.codeaudit.catchcode.entity.VersionManage;
import com.westos.core.DoScan;
import com.westos.utils.JTextFieldHintListener;
import com.westos.utils.StartTimer;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import java.io.File;

import javax.swing.*;

public class Index extends JFrame {

    // 定义组件
    JCheckBox jcb1, jcb2; //复选框
    JPanel jp1, jp2, jp3, jp4;
    JLabel jlb1, jlb2;
    JButton jb1, jb2, btn;
    JTextField jtf1, jtf3, textField;
    //JPasswordField jpf1; //密码


    // 构造函数
    public Index() {

        jp1 = new JPanel();
        jp2 = new JPanel();
        jp3 = new JPanel();
        jp4 = new JPanel();

        jlb1 = new JLabel("文件ID:");
        jlb2 = new JLabel("请选择文件:");

        textField = new JTextField(20);// 文本域
        btn = new JButton("浏览");// 钮1


        jcb1 = new JCheckBox("sql注入扫描");
        jcb2 = new JCheckBox("xss扫描");

        jb1 = new JButton("开始");
        jb2 = new JButton("重置");

        jtf1 = new JTextField(20);
        jtf3 = new JTextField(20);

        jtf3.addFocusListener(new JTextFieldHintListener("1代表sql,2代表xss", jtf3));
        //设置布局为4行1列
        GridLayout layout = new GridLayout(4, 1);
        this.setLayout(layout);

        // 加入各个组件
        jp1.add(jlb1);
        jp1.add(jtf1);

        jp2.add(jlb2);
        jp2.add(textField);
        jp2.add(btn);

        jp3.add(jcb1);
        jp3.add(jcb2);
        jp4.add(jb1);
        jp4.add(jb2);

        // 加入到JFrame
        this.add(jp1);
        this.add(jp2);
        this.add(jp3);
        this.add(jp4);

        this.setSize(500, 300);
        this.setTitle("代码审计");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

        //使得窗口在屏幕中心显示
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        this.setBounds((screenSize.width - 500) / 2, (screenSize.height - 300) / 2, 500, 300);

        btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JFileChooser chooser = new JFileChooser();
                chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
                JLabel jLabel = new JLabel();
                chooser.showDialog(jLabel, "选择");
                File file = chooser.getSelectedFile();
                textField.setText(file.getAbsoluteFile().toString());
            }
        });
        jb2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                jtf1.setText("");
                textField.setText("");
                jcb1.setSelected(false);
                jcb2.setSelected(false);
            }
        });
        jb1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    int id = Integer.parseInt(jtf1.getText());
                    String dir = textField.getText();
                    String way = null;
                    if (jcb1.isSelected() && jcb2.isSelected()) {
                        System.out.println(jcb1.getText() + jcb2.getText());
                        way = "3";
                    } else if (jcb1.isSelected()) {
                        System.out.println(jcb1.getText());
                        way = "1";//sql
                    } else if (jcb2.isSelected()) {
                        System.out.println(jcb2.getText());
                        way = "2";//xss
                    }
                    System.out.println(id + "==" + dir + "==" + way);
                    VersionManage versionManage = new VersionManage();
                    versionManage.setVerid(id);
                    versionManage.setPropath(dir);
                    versionManage.setScanway(way);
                    DoScan doScan = new DoScan(versionManage);
                    new StartTimer(doScan);
                    doScan.doScan();
                } catch (Exception ex) {
                    System.out.println("输入有误");
                }
            }
        });

    }

    public static void main(String[] args) {

        new Index();

    }
}

结果:
Java图形化界面输入输出_第1张图片

Java图形化界面输入输出_第2张图片

package com.westos.gui;

import com.westos.bean.RiskBean;
import com.westos.codeaudit.catchcode.entity.VersionManage;

import javax.swing.*;
import java.awt.*;
import java.util.List;

public class Index2 extends JFrame {
    private List list = null;
    VersionManage versionManage = null;
    // 定义组件
    JPanel jp1;

    // 构造函数
    public Index2(List<RiskBean> list, VersionManage versionManage) {
        this.list = list;
        this.versionManage = versionManage;
        jp1 = new JPanel();
        JTextArea textArea = new JTextArea(40, 85);
        textArea.setLineWrap(true);//设置自动换行
        textArea.setWrapStyleWord(true);//设置以单词为整体
        textArea.setEditable(false);//设置无法编辑
        //将TextArea放入滚动条里面去
        JScrollPane scroll = new JScrollPane(textArea);
        //把定义的JTextArea放到JScrollPane里面去
        //分别设置水平和垂直滚动条自动出现
        scroll.setHorizontalScrollBarPolicy(
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll.setVerticalScrollBarPolicy(
                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

        textArea.append("任务编号: " + versionManage.getVerid() + "\n");
        textArea.append("任务路径: " + versionManage.getPropath() + "\n\n");
        int num = 0;
        if (list.size()>0) {
            for (RiskBean riskBean : list) {
                textArea.append(" 漏洞编号:" + ++num);
                textArea.append("\n");
                textArea.append(" 漏洞名称:" + riskBean.getRiskname().trim());
                textArea.append("\n");
                textArea.append(" 文件路径:" + riskBean.getFilepath().trim());
                textArea.append("\n");
                textArea.append(" 漏洞所在行号:" + riskBean.getRownum().toString());
                textArea.append("\n");
                textArea.append(" 漏洞代码:\n" + riskBean.getRiskcode().trim());
                textArea.append("\n\n");

            }
        }else {
            textArea.append("未检查出漏洞");
        }


        this.setLayout(new GridLayout(1, 1));
        jp1.add(scroll);
        this.add(jp1);
        this.setSize(1000, 700);
        this.setTitle("代码审计");
        this.setVisible(true);

        //让窗口显示在屏幕中央
        Toolkit kit = Toolkit.getDefaultToolkit();
        Dimension screenSize = kit.getScreenSize();
        this.setBounds((screenSize.width - 1000) / 2, (screenSize.height - 700) / 2, 1000, 700);

    }


}

结果:
乱码是windows的原因,linux上没有乱码
Java图形化界面输入输出_第3张图片

你可能感兴趣的:(Java)