复审代码
源代码如下:
1 package client; 2 3 import javax.naming.*; 4 import javax.swing.*; 5 6 import java.awt.event.*; 7 8 import javax.swing.ImageIcon; 9 10 import java.net.URL; 11 12 import javax.swing.WindowConstants; 13 14 import ejbserver.EJBServerRemote; 15 16 import java.awt.Color; 17 import java.awt.Font; 18 import java.awt.Point; 19 import java.awt.event.ActionEvent; 20 import java.awt.event.ActionListener; 21 import java.util.*; 22 23 public class Client extends JFrame { 24 JLabel label1 = new JLabel("登录测试应用"); 25 JLabel label2 = new JLabel("用户名:"); 26 JLabel label3 = new JLabel("密 码:"); 27 28 java.sql.Connection con=null; 29 java.sql.ResultSet rs=null; 30 java.sql.PreparedStatement ps=null; 31 32 33 JLabel label6 = new JLabel(new ImageIcon("image/登录界面.jpg")); 34 35 JTextField txtname=new JTextField();; 36 JPasswordField txtPwd = new JPasswordField(); 37 38 JButton but1 = new JButton("登录"); 39 40 JButton but2 = new JButton("退出"); 41 42 JProgressBar jpb = new JProgressBar();// 进度条 43 44 /** 45 * 构造方法 46 */ 47 public Client(){} 48 public Client(int i,int num) { 49 50 initClient(); 51 this.setLocation(new Point(436,176));//界面初始化指定位置 52 this.setResizable(false);// 禁止改变大小 53 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 54 this.setDefaultCloseOperation(i); 55 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 56 } 57 58 /** 59 * 界面代码 60 */ 61 public void initClient() { 62 this.setTitle("Client "); 63 this.setSize(600, 450); 64 JLayeredPane pa = new JLayeredPane(); // 容器 65 66 // 设置组件字体和颜色 67 label1.setFont(new Font("宋体", 1, 32)); 68 label2.setFont(new Font("宋体", 0, 16)); 69 label3.setFont(new Font("宋体", 0, 16)); 70 txtname.setFont(new Font("宋体", 0, 16)); 71 txtPwd.setFont(new Font("宋体", 0, 16)); 72 txtPwd.setEchoChar('*'); 73 txtPwd.setText("2013551728"); 74 label1.setForeground(new Color(250, 89, 136)); 75 txtname.setForeground(new Color(250, 85, 85)); 76 txtname.setEditable(true); 77 txtname.setText("2013551728"); 78 79 // 设置组件位置 80 label1.setBounds(153, 35, 400, 35); 81 label2.setBounds(180, 165, 82, 25); 82 // label5.setBounds(15, 25, 80, 66); 83 txtname.setBounds(245, 165, 150, 25); 84 label3.setBounds(180, 220, 152, 25); 85 txtPwd.setBounds(245, 220, 150, 25); 86 but1.setBounds(245, 275, 80, 30); 87 but2.setBounds(338, 275, 80, 30); 88 89 // 添加组件到容器 90 pa.add(label1); 91 pa.add(label2); 92 pa.add(label3); 93 94 pa.add(txtname); 95 pa.add(txtPwd); 96 pa.add(but1); 97 pa.add(but2); 98 this.add(pa);// 添加容器 99 100 jpb.setBounds(0, 400, 600, 25); 101 jpb.setForeground(new Color(250, 40, 135)); 102 jpb.setVisible(false); 103 pa.add(jpb); 104 label6.setBounds(0, 0, 600, 425); 105 pa.add(label6); 106 but1.addActionListener (new ActionListener() { 107 public void actionPerformed(ActionEvent arg0) { 108 if(txtname.getText().trim().length()==0){ 109 JOptionPane.showMessageDialog(null, "请填入用户名!", "警告", 0); 110 return; 111 } 112 113 if(txtPwd.getText().trim().length()==0) 114 { 115 JOptionPane.showMessageDialog(null, "请填入密码!", "警告", 0); 116 return; 117 118 } 119 if(txtPwd.getText().trim().length()>10){ 120 JOptionPane.showMessageDialog(null, "密码太长!", "警告", 0); 121 return; 122 123 } 124 //DB p=new DB(); 125 //验证区域 126 String id=txtname.getText().trim(); 127 String password=txtPwd.getText().trim(); 128 129 int result = -3; 130 try { 131 result = checkname(id,password); 132 } catch (Exception e) { 133 // TODO Auto-generated catch block 134 e.printStackTrace(); 135 } 136 //System.out.println(id+password+result); 137 if(result==1){ 138 139 //显示进度条 140 jpb.setVisible(true); 141 142 yin();//进度条 143 JOptionPane.showMessageDialog(null, "登录成功"); 144 } 145 else if(result==2){ 146 JOptionPane.showMessageDialog(null,"您被列入黑名单!"); 147 return; 148 } 149 else if(result==0){ 150 JOptionPane.showMessageDialog(null,"密码错误!"); 151 return; 152 } 153 else if(result==-1){ 154 JOptionPane.showMessageDialog(null,"不存在的用户名!"); 155 return; 156 } 157 else{ 158 JOptionPane.showMessageDialog(null,"未知错误!"); 159 return; 160 } 161 } 162 } 163 164 ); 165 166 but2.addActionListener(new ActionListener(){ 167 public void actionPerformed(ActionEvent arg0) { 168 // TODO 自动生成方法存根 169 int a = JOptionPane.showConfirmDialog(null, "是否退出", "警告", 0); 170 if (a == 0) { 171 dispose(); 172 } else { 173 return; 174 } 175 } 176 }); 177 178 } 179 180 /** 181 * 进度条 182 */ 183 public void yin() { 184 this.setEnabled(false);// 锁屏 185 186 new java.lang.Thread(new java.lang.Runnable() { 187 public void run() { 188 while (true) { 189 try { 190 int i = Client.this.jpb.getValue(); 191 192 if (i < Client.this.jpb.getMaximum()) { 193 int k = ++i; 194 Client.this.jpb.setValue(k); 195 Client.this.jpb.setStringPainted(true); 196 197 if (k <= 25) { 198 java.lang.Thread.sleep(100); 199 Client.this.jpb.setString("正在载入系统......" + 4 * k+ "%"); 200 } else if (k <= 75) { 201 java.lang.Thread.sleep(80); 202 Client.this.jpb.setString("加载资料......" + k + "%"); 203 } else { 204 java.lang.Thread.sleep(30); 205 Client.this.jpb.setString("正在缓冲,请稍后......" + k+ "%"); 206 } 207 } else { 208 Client.this.dispose(); 209 } 210 } catch (Exception e) { 211 e.printStackTrace(); 212 } 213 // 成功登入 214 if (Client.this.jpb.getValue() == 100) { 215 Client.this.jpb.setString("完成100%"); 216 217 //new ClientMenu().setVisible(true); 218 Client.this.dispose(); 219 break; 220 } 221 } 222 } 223 }).start(); 224 } 225 public int checkname(String id,String password) throws Exception{ 226 Properties props = new Properties(); 227 props.put("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory"); 228 props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); 229 props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); 230 props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); //host 231 props.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); //EJB Port 232 EJBServerRemote checker=null; 233 Context context = new InitialContext(props); 234 context.lookup("ejbserver.EJBServerRemote"); 235 checker = (EJBServerRemote)context.lookup(EJBServerRemote.class.getName()); 236 int result=checker.check(id, password); 237 return result; 238 239 } 240 public static void main(String[] args) { 241 new Client(0,0).setVisible(true); 242 243 } 244 245 }
复审结果如下:
审查项目 | 检查分项 | 检查结果 |
风格检查 | 命名、格式是否符合对应的规范文档 | 是 |
文件命名清晰,无歧义 | 是 | |
代码缩进、对齐格式正确,可使用IDE工具进行整理 | 是 | |
代码行控制在100字符,文件行数小于2000行,方法行数小于100行 | 是 | |
方法、属性、变量和功能代码块之间使用空行进行分隔 | 是 | |
是否存在重复的代码 | 否 | |
注释检查 | 使用统一的注释风格,注释必须使用易于识别的文本和符号 | 是 |
每个类,每个方法都应有注释,注释量不低于代码行数的20% | 数量不足 | |
注释应随着代码改变而更新,保证无用的代码和注解已删除 | 否 | |
重要变量、复杂算法、循环和逻辑分支处必须有注释 | 是 | |
注释应解释为什么,而不是描述做什么,做什么是由代码自解释的 | 否 | |
注释应说明意外、异常情况,注明原因和解决办法 | 否 | |
类定义检查 | 命名规则是否符合命名规范 | 是 |
类的职责是否过少或过多,类的属性或者方法是否没有被使用 | 否 | |
是否存在如下的调用形式:a.b().c() | 否 | |
是否存在两个类完成类似的工作,使用了不同的方法名,却没有同一个父类 | 否 | |
是否存在某个子类仅使用了父类的部分属性或方法 | 是 | |
当功能变化或逻辑修改时,是否要修改多个类 | 否 | |
是否正确使用类修饰符 | 是 | |
派生类的构造方法应调用基类的构造方法 | 是 | |
方法检查 | 方法名应能明确定义了操作目标以及实现的功能 | 是 |
方法的参数遵循一个明显有序的顺序 | 是 | |
方法应当只做一件事情,并做好 | 是 | |
参数应小于7个,过多的参数应使用参数类或实体封装 | 是 | |
方法检查了输入数据的合法性,return语句是否合理 | 是 | |
方法对可能引发的异常处理有清楚的标识 | 否 | |
重载、覆盖与隐藏是否被正确使用 | 是 | |
运算符、操作符的重载是否符合规范 | 是 | |
对于重复出现并完成同样单一功能的代码,是否进行了封装 | 是 | |
循环/分支检查 | 最普遍的状况应在在if下处理,而不是else中 | 是 |
分值嵌套层次小于3层 | 是 | |
当有明确的多次循环操作,使用for | 是 | |
当有不明确的多次循环操作,使用while | 是 | |
循环嵌套的层次小于3层,是否存在死循环 | 是 不存在 | |
多个if使用switch语句表达是否更清晰 | 是 | |
循环体内不要随意修改循环变量和步长值 | 是 | |
break和continue语句使用是否正确 | 是 | |
循环和分值的边界值是否合适 | 是 | |
定义检查 | 定义常量所有字母应大写,单词之间用下划线连接 | 是 |
代码中的常量应用是否合适,非必要不要使用全局变量 | 是 |