Code review
1.源代码
package Text1; import java.awt.BorderLayout; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.DefaultComboBoxModel; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.ImageIcon; import javax.swing.JPasswordField; public class Day extends JFrame { private JPanel contentPane; private JTextField textField; private JPasswordField passwordField; public static void main(String[] args) { Day frame = new Day(); frame.setVisible(true); } public Day() { setTitle("用户登录"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 450, 300); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); contentPane.setLayout(null); this.setResizable(false); JLabel label = new JLabel("用户名"); label.setBounds(39, 45, 54, 15); contentPane.add(label); JComboBox comboBox = new JComboBox(); comboBox.setModel(new DefaultComboBoxModel(new String[] {"\u7BA1\u7406\u5458 ", "\u6536\u94F6\u5458"})); comboBox.setBounds(126, 121, 173, 21); contentPane.add(comboBox); textField = new JTextField(); textField.setBounds(126, 42, 173, 21); contentPane.add(textField); textField.setColumns(30); JButton button = new JButton("确定"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String userName=textField.getText(); String passWord=String.valueOf( passwordField.getPassword()); String role=(String)comboBox.getSelectedItem(); if(userName==null||userName.length()<=0||passWord==null||passWord.length()<=0||role==null||role.length()<=0){ JOptionPane.showMessageDialog(contentPane,"请输入完整登录信息!"); } else if(userName.equals("SMMS")&&passWord.equals("123456")&&role.equals("管理员")) JOptionPane.showMessageDialog(contentPane,"欢迎登录SMMS超市购物系统!"); else JOptionPane.showMessageDialog(contentPane,"输入信息错误,请重新输入!"); } }); button.setBounds(142, 194, 77, 23); contentPane.add(button); JLabel label_1 = new JLabel("密码"); label_1.setBounds(39, 88, 54, 15); contentPane.add(label_1); JLabel label_2 = new JLabel("角色"); label_2.setBounds(39, 124, 54, 15); contentPane.add(label_2); passwordField = new JPasswordField(); passwordField.setBounds(126, 85, 173, 21); contentPane.add(passwordField); JButton button_1 = new JButton("取消"); button_1.setBounds(245, 194, 93, 23); contentPane.add(button_1); JLabel label_3 = new JLabel(""); label_3.setIcon(new ImageIcon("C:\\Users\\lenovo.Lenovo-PC\\Pictures\\butterfly.jpg")); label_3.setBounds(0, 0, 434, 261); contentPane.add(label_3); } }
2.Code review
Number |
Problem |
1 |
代码没有注释 |
2 |
代码有些杂乱,每段代码之间没有规范,没有让人很清楚该段代码的功能 |
3 |
命名不规范,大小写不注意,命名没有意义 |
4 |
代码格式布局都不合理 |
5 |
整个代码运行后,界面布局不整齐 |