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

📄 stressui.java

📁 软件测试与junit实践一书的源代码
💻 JAVA
字号:
/* * StressUI.java *" * 创建日期: 2002年10月08日, 上午9:10" * 创建人员:Fastpoint * 修改日期: * 修改人员: */package com;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.*;import javax.swing.*;import javax.swing.text.JTextComponent;public class StressUI extends JComponent{    public static final int HOMEPAGE = 1;    public static final int SHOW_PROPERTIES = 2;    public static final int TESTING = 3;    public static final int RESULT = 4;    JTextField filePath;    JTextField threadNumber;    JTextField distance;    JTextArea textArea;    JButton endbutton;    JScrollPane scrollpane;    public StressUI(int pageno){        filePath = null;        threadNumber = null;        distance = null;        textArea = null;        endbutton = null;        scrollpane = null;        setPreferredSize(new Dimension(320, 240));        if(pageno == 1){            setLayout(new BorderLayout());            Icon big1 = new ImageIcon(String.valueOf(String.valueOf((new StringBuffer(".")).append(File.separator).append("pic").append(File.separator).append("catalog.jpg"))));            JLabel tigerLabel = new JLabel(big1);            add(tigerLabel, "North");            JPanel mainPanelc = new JPanel();            JTextField textfield = new JTextField();            textfield.setColumns(25);            filePath = textfield;            JTextField textfield1 = new JTextField();            textfield1.setColumns(10);            threadNumber = textfield1;            JTextField textfield2 = new JTextField();            textfield2.setColumns(10);            distance = textfield2;            JButton catalogButton = new JButton("选择配置文件");            catalogButton.setSize(200, 25);            catalogButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e){                    JFileChooser jfc = new JFileChooser();                    jfc.setDialogTitle("选择URL配置文件");                    jfc.setCurrentDirectory(new File(".\\"));                    int state = jfc.showOpenDialog(null);                    if(state == 0){                        File file = jfc.getSelectedFile();                        filePath.setText(file.getPath());                    }                }            });                        mainPanelc.setBorder(BorderFactory.createTitledBorder(""));            mainPanelc.add(new JLabel("选择URL配置文件"));            mainPanelc.add(Box.createHorizontalStrut(180));            mainPanelc.add(textfield);            mainPanelc.add(Box.createHorizontalStrut(5));            mainPanelc.add(catalogButton);            mainPanelc.add(Box.createHorizontalStrut(170));            mainPanelc.add(new JLabel("并发访问数"));            mainPanelc.add(Box.createHorizontalStrut(5));            mainPanelc.add(textfield1);            mainPanelc.add(Box.createHorizontalStrut(90));            mainPanelc.add(new JLabel("访问请求间隔时间(毫秒)"));            mainPanelc.add(Box.createHorizontalStrut(15));            mainPanelc.add(textfield2);            add(mainPanelc, "Center");            JButton nextButton = new JButton("下一步");            nextButton.setSize(150, 25);            nextButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e){                    StressTest st = StressTest.st;                    try{                        st.setProperties(threadNumber.getText(), distance.getText(), filePath.getText());                    }catch(NumberFormatException nfe){                        nfe.printStackTrace();                        JOptionPane message = new JOptionPane();                        message.setMessageType(2);                        JOptionPane.showMessageDialog(StressTest.st.ui, "并发数和访问时间间隔都必须是大于0的数字。");                    }                    st.showProperties();                }            });            JPanel mainPanel = new JPanel();            mainPanel.setBorder(BorderFactory.createTitledBorder(""));            mainPanel.add(Box.createHorizontalStrut(250));            mainPanel.add(nextButton);            mainPanel.add(Box.createHorizontalStrut(5));            add(mainPanel, "South");        }else if(pageno == 2){            setLayout(new BorderLayout());            Icon big1 = new ImageIcon(String.valueOf(String.valueOf((new StringBuffer(".")).append(File.separator).append("pic").append(File.separator).append("catalog.jpg"))));            JLabel tigerLabel = new JLabel(big1);            add(tigerLabel, "North");            JPanel mainPanelc = new JPanel();            mainPanelc.setBorder(BorderFactory.createTitledBorder(""));            mainPanelc.add(new JLabel("配置文件正确"));            mainPanelc.add(Box.createHorizontalStrut(5));            mainPanelc.add(Box.createHorizontalStrut(250));            mainPanelc.add(new JLabel("并发访问数:".concat(String.valueOf(String.valueOf(StressTest.st.threadNumber)))));            mainPanelc.add(Box.createHorizontalStrut(5));            mainPanelc.add(new JLabel("访问请求间隔时间(毫秒):".concat(String.valueOf(String.valueOf(StressTest.st.distance)))));            mainPanelc.add(Box.createHorizontalStrut(5));            add(mainPanelc, "Center");            JButton previousButton = new JButton("上一步");            previousButton.setSize(150, 25);            previousButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e){                    StressTest.st.selectServer(1);                }            });            JButton nextButton = new JButton("开始测试");            nextButton.setSize(200, 25);            nextButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e){                    StressTest.st.testing();                }            });            JPanel mainPanel = new JPanel();            mainPanel.setBorder(BorderFactory.createTitledBorder(""));            mainPanel.add(Box.createHorizontalStrut(50));            mainPanel.add(previousButton);            mainPanel.add(Box.createHorizontalStrut(5));            mainPanel.add(nextButton);            mainPanel.add(Box.createHorizontalStrut(5));            add(mainPanel, "South");        }else if(pageno == 3){            setPreferredSize(new Dimension(640, 480));            setLayout(new BorderLayout());            textArea = new JTextArea();            scrollpane = new JScrollPane(textArea);            add(scrollpane, "Center");            JButton nextButton = new JButton("查看测试结果");            endbutton = nextButton;            nextButton.setSize(300, 25);            nextButton.setEnabled(false);            nextButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e){                    StressTest.st.result();                }            });            JPanel mainPanel = new JPanel();            mainPanel.setBorder(BorderFactory.createTitledBorder(""));            mainPanel.add(Box.createHorizontalStrut(5));            mainPanel.add(nextButton);            mainPanel.add(Box.createHorizontalStrut(5));            add(mainPanel, "South");        }else if(pageno == 4){            setPreferredSize(new Dimension(640, 480));            setLayout(new BorderLayout());            textArea = new JTextArea();            add(new JScrollPane(textArea), "Center");            JButton saveButton = new JButton("保存");            saveButton.setSize(100, 25);            saveButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e){                    JFileChooser jfc = new JFileChooser();                    jfc.setDialogTitle("选择保存文件");                    jfc.setCurrentDirectory(new File(".\\"));                    int state = jfc.showSaveDialog(null);                    if(state == 0){                        File file = jfc.getSelectedFile();                        String mes = null;                        JOptionPane message = new JOptionPane();                        try{                            BufferedWriter bw = new BufferedWriter(new FileWriter(file));                            bw.write(StressTest.st.sb.toString());                            bw.close();                            message.setMessageType(1);                            mes = String.valueOf(String.valueOf((new StringBuffer("测试结果已经保存到")).append(file.getPath()).append("文件中。")));                        }catch(IOException ioe){                            message.setMessageType(0);                            mes = String.valueOf(String.valueOf((new StringBuffer("保存测试信息失败。\n请检查")).append(file.getPath()).append("文件。")));                        }                        JOptionPane.showMessageDialog(StressTest.st.ui, mes);                    }                }            });            JButton nextButton = new JButton("退出");            nextButton.setSize(100, 25);            nextButton.addActionListener(new ActionListener() {                public void actionPerformed(ActionEvent e){                    System.exit(0);                }            });            JPanel mainPanel = new JPanel();            mainPanel.setBorder(BorderFactory.createTitledBorder(""));            mainPanel.add(Box.createHorizontalStrut(200));            mainPanel.add(saveButton);            mainPanel.add(Box.createHorizontalStrut(100));            mainPanel.add(nextButton);            add(mainPanel, "South");        }    }    public void out(String dec){        if(textArea != null){            textArea.append(String.valueOf(String.valueOf(dec)).concat("\n"));            if(scrollpane != null)                scrollpane.getVerticalScrollBar().setValue(scrollpane.getVerticalScrollBar().getMaximum());        }    }    public void endButton(boolean enable){        endbutton.setEnabled(enable);    }   }

⌨️ 快捷键说明

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