标签:
自重装系统后,电脑中两个版本的eclipse都驾崩了,起个VS也要花费半年的时间(观赏收费),所以就运用已有的工具STS编了代码,不能用JavaFX很是遗憾,只能在网上找了代码,自己修改后完成了测试。
1. 基本等价类的划分
有效等价类 | 无效等价类 |
长度:1到6 | 长度:0,7 |
字符:a-z,A-Z,0-9 | 字符:英文/数字以外字符,控制字符,标点符号 |
2. 测试用例
编号 | test1 | test2 | test3 | 输出 |
1 | 12345 | asdfg | ert234 | true,true,true |
2 | 1234567 | 123 | ert | false,true,true |
3 | 123@ | 123 | ert | false,true,true |
4 | 空 | 123 | ert | false,true,true |
5 |
123, | 123 | ert | false,true,true |
按理说应该同时测试各个test(i)为假的情况,但以经验而谈,情况是一样的,就不做脱裤子放屁的事了。
3. 代码如下
package editbox; import java.awt.BorderLayout; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingUtilities; public class test { public static void main(String[] args) { MFrame frame = new MFrame(); } } class MFrame extends JFrame{ public MFrame(){ JLabel jl = new JLabel("Editbox",SwingUtilities.CENTER); Font font = new Font("宋体",Font.BOLD,24); jl.setFont(font); jl.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20)); this.add(jl,BorderLayout.NORTH); font = new Font("宋体",Font.PLAIN,12); JLabel jl_name = new JLabel("test1:",SwingUtilities.RIGHT); jl_name.setFont(font); JLabel jl_pass1 = new JLabel("test2:",SwingUtilities.RIGHT); jl_pass1.setFont(font); JLabel jl_pass2 = new JLabel("test3:",SwingUtilities.RIGHT); jl_pass2.setFont(font); JPanel jp_center_left = new JPanel(); jp_center_left.setLayout(new GridLayout(5,1)); jp_center_left.add(jl_name); jp_center_left.add(jl_pass1); jp_center_left.add(jl_pass2); JTextField jt_name = new JTextField(); JTextField jt_pass1 = new JTextField(); JTextField jt_pass2 = new JTextField(); JPanel jp_center_right = new JPanel(); jp_center_right.setLayout(new GridLayout(5,1)); jp_center_right.add(jt_name); jp_center_right.add(jt_pass1); jp_center_right.add(jt_pass2); JPanel jp_center = new JPanel(); jp_center.setLayout(new GridLayout(1,2)); jp_center.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 60)); jp_center.add(jp_center_left); jp_center.add(jp_center_right); JButton jb1 = new JButton("OK"); jb1.addMouseListener(new MouseAdapter(){ boolean result = true; public void mouseClicked(MouseEvent e){ String []str = new String[3]; for(int i = 0; i<3; i++){ str[i]= new String(); } str[0] = jt_name.getText(); str[1] = jt_pass1.getText(); str[2] = jt_pass2.getText(); for(int i =0;i<3;i++){ result = true; if(str[i].length() >0 && str[i].length()<7){ for(int j =str[i].length()-1;j>=0;j--){ if(!Character.isDigit((str[i].charAt(j)))&&!Character.isLetter(str[i].charAt(j))) { result = false; break; } } } else { result = false; } System.out.println(str[i]); System.out.println(result); } } }); JPanel jp_south = new JPanel(); jp_south.add(jb1); jp_south.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); this.add(jp_center); this.add(jp_south,BorderLayout.SOUTH); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); this.setSize(370, 280); this.setResizable(false); this.setLocationRelativeTo(null); } }
4. 结果截图
标签:
原文地址:http://www.cnblogs.com/dulun/p/4375929.html