在线急求登录窗口密码验证问题
Java codepackage cn.hdu.edu;import java.awt.BorderLayout;import java.awt.EventQueue;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.ButtonGroup;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JRadioButton;import javax.swing.JTextField;import javax.swing.JPasswordField;import javax.swing.JButton;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.Color;import java.sql.*;public class Login extends JFrame { private JPanel contentPane; private JTextField textField; private JPasswordField passwordField; /** * Create the frame. */ public Login() { setTitle("\u97F3\u50CF\u7BA1\u7406\u4FE1\u606F\u7CFB\u7EDF"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 480, 320); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); JPanel panel = new JPanel(); panel.setBackground(Color.CYAN); contentPane.add(panel, BorderLayout.CENTER); panel.setLayout(null); JLabel label = new JLabel("\u767B\u5F55"); label.setBounds(200, 5, 44, 15); panel.add(label); ButtonGroup bgp = new ButtonGroup(); final JRadioButton rdbtnNewRadioButton = new JRadioButton("\u5458\u5DE5"); rdbtnNewRadioButton.setBackground(Color.CYAN); rdbtnNewRadioButton.setBounds(145, 54, 58, 23); panel.add(rdbtnNewRadioButton); JRadioButton radioButton = new JRadioButton("\u5BA2\u6237"); radioButton.setBackground(Color.CYAN); radioButton.setBounds(241, 54, 58, 23); panel.add(radioButton); bgp.add(radioButton); bgp.add(rdbtnNewRadioButton); JLabel label_1 = new JLabel("\u7528\u6237\u540D"); label_1.setBounds(136, 106, 54, 15); panel.add(label_1); textField = new JTextField(); textField.setBounds(189, 103, 170, 21); panel.add(textField); textField.setColumns(10); JLabel label_2 = new JLabel("\u5BC6\u7801"); label_2.setBounds(136, 152, 39, 15); panel.add(label_2); passwordField = new JPasswordField(); passwordField.setBounds(189, 149, 170, 21); panel.add(passwordField); JButton btnNewButton = new JButton("\u767B\u5F55"); btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if(rdbtnNewRadioButton.isSelected()){ if (textField.toString().equals("")){ JOptionPane.showMessageDialog(null, "请输入用户名", "温馨提示", JOptionPane.INFORMATION_MESSAGE); } else if (passwordField.toString().equals("")){ JOptionPane.showMessageDialog(null, "请输入密码", "温馨提示", JOptionPane.INFORMATION_MESSAGE); } } else{ dispose(); new KehuFrame().setVisible(true); } } }); btnNewButton.setBounds(110, 201, 93, 23); panel.add(btnNewButton); JButton button = new JButton("\u53D6\u6D88"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { dispose(); } }); button.setBounds(241, 201, 93, 23); panel.add(button); } /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { Login frame = new Login(); frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); }}