帮我看看错在哪!!!!!!!!
总是判断txt是不是为空哪位仁兄帮我解决下
在线等待
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import *;
import java.util.*;
import *;
public class Enrol extends JFrame
{
JLabel lblMessage = new JLabel("");
JLabel lblBt = new JLabel("必填信息");
JLabel lblXt = new JLabel("选填信息");
JLabel lblId = new JLabel("用户名:");
JLabel lblPassword = new JLabel("密码:");
JLabel lblPassword2 = new JLabel("确认字码:");
JLabel lblName = new JLabel("姓名:");
JLabel lblTelephone = new JLabel("电话:");
JLabel lblAdderss = new JLabel("地址:");
JLabel lblAge = new JLabel("性别:");
JLabel lblBorn = new JLabel("出生:");
JLabel lblYear = new JLabel("年");
JLabel lblMonth = new JLabel("月");
JLabel lblDay = new JLabel("日");
String packYaer[] = {"","1980","1980","1980","1981","1982","1983","1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2007"};
String packMonth[] = {"","1","2","3","4","5","6","7","8","9","10","11","12"};
String packDay[] = {"","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"};
JComboBox cbYear = new JComboBox(packYaer);
JComboBox cbMonth = new JComboBox(packMonth);
JComboBox cbDay = new JComboBox(packDay);
ButtonGroup btng = new ButtonGroup();
JRadioButton radbtnMan = new JRadioButton("男");
JRadioButton radbtnWoman = new JRadioButton("女");
JTextField txtId = new JTextField(15);
JPasswordField txtPassword = new JPasswordField(15);
JPasswordField txtPassword2 = new JPasswordField(15);
JTextField txtName = new JTextField(10);
JTextField txtTelephone = new JTextField(15);
JTextField txtAddress = new JTextField(25);
JButton btnOk = new JButton("确定");
JButton btnCen = new JButton("取消");
JButton btnBack = new JButton("返回");
JButton btnExit = new JButton("退出");
JPanel pan = new JPanel();
JPanel panBg = new JPanel();
JPanel panBorn = new JPanel();
JPanel panBt = new JPanel();
JFrame f = new JFrame("用户注册");
GridBagConstraints gbc = new GridBagConstraints();
GridBagLayout gbl = new GridBagLayout();
public Enrol()
{
pan.setLayout(gbl);
gbc.anchor = GridBagConstraints.WEST; //西(左)对齐
gbc.gridx = 0;
gbc.gridy = 0;
pan.add(lblBt,gbc);
gbc.gridx = 0;
gbc.gridy = 1;
pan.add(lblId,gbc);
gbc.gridx = 1;
pan.add(txtId,gbc);
gbc.gridx = 2;
gbc.gridx = 0;
gbc.gridy = 2;
pan.add(lblPassword,gbc);
gbc.gridx = 1;
pan.add(txtPassword,gbc);
gbc.gridx = 2;
gbc.gridx = 0;
gbc.gridy = 3;
pan.add(lblPassword2,gbc);
gbc.gridx = 1;
pan.add(txtPassword2,gbc);
gbc.gridx = 2;
gbc.gridx = 0;
gbc.gridy = 4;
pan.add(lblXt,gbc);
gbc.gridx = 0;
gbc.gridy = 5;
pan.add(lblName,gbc);
gbc.gridx = 1;
pan.add(txtName,gbc);
gbc.gridx = 0;
gbc.gridy = 6;
pan.add(lblTelephone,gbc);
gbc.gridx = 1;
pan.add(txtTelephone,gbc);
gbc.gridx = 0;
gbc.gridy = 7;
pan.add(lblAdderss,gbc);
gbc.gridx = 1;
pan.add(txtAddress,gbc);
gbc.gridx = 0;
gbc.gridy = 8;
pan.add(lblBorn,gbc);
panBorn.add(cbYear);
panBorn.add(lblYear);
panBorn.add(cbMonth);
panBorn.add(lblMonth);
panBorn.add(cbDay);
panBorn.add(lblDay);
gbc.gridx = 1;
pan.add(panBorn,gbc);
gbc.gridx = 0;
gbc.gridy = 9;
pan.add(lblAge,gbc);
btng.add(radbtnMan);
btng.add(radbtnWoman);
panBg.add(radbtnMan,gbc);
panBg.add(radbtnWoman,gbc);
gbc.gridx = 1;
gbc.gridy = 9;
pan.add(panBg,gbc);
panBt.add(btnOk,gbc);
panBt.add(btnCen,gbc);
panBt.add(btnBack,gbc);
panBt.add(btnExit,gbc);
gbc.anchor = GridBagConstraints.CENTER; //居中
gbc.gridy = 10;
pan.add(panBt,gbc);
btnOk.addActionListener(new Listener());
btnCen.addActionListener(new Listener());
btnBack.addActionListener(new Listener());
btnExit.addActionListener(new Listener());
gbc.gridy = 11;
gbc.anchor = GridBagConstraints.CENTER; //居中
pan.add(lblMessage,gbc);
//窗体居中
Toolkit kit=Toolkit.getDefaultToolkit();
Dimension screenSize=kit.getScreenSize();
int screenHeight=screenSize.height;
int screenWidth=screenSize.width;
f.setLocation(screenWidth/3, screenHeight/3);
f.getContentPane().add(pan);
f.setSize(400,400);
f.setVisible(true);
f.setDefaultCloseOperation(EXIT_ON_CLOSE);
// btnOk.setEnabled(false);
// btnCen.setEnabled(false);
// btnExit.setEnabled(true);
}
class Listener implements ActionListener
{
String id = txtId.getText().trim();
String password = new String(txtPassword.getPassword());
String password2 = new String(txtPassword2.getPassword());
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btnOk)
{
//提交注册信息
if(id.length()==0)
{
JOptionPane.showMessageDialog(null,"用户名不能为空!","错误",JOptionPane.ERROR_MESSAGE);
return;
}
if(password.length()==0)
{
JOptionPane.showMessageDialog(null,"密码不能为空!","错误",JOptionPane.ERROR_MESSAGE);
return;
}
if(password.length()==0)
{
JOptionPane.showMessageDialog(null,"确认密码不能为空!","错误",JOptionPane.ERROR_MESSAGE);
return;
}
}
if(e.getSource()==btnCen)
{
txtId.setText("");
txtPassword.setText("");
txtPassword2.setText("");
txtName.setText("");
txtTelephone.setText("");
txtAddress.setText("");
lblMessage.setText("");
}
if(e.getSource()==btnBack)
{
//返回登录框
f.setVisible(false);
// new Logon();
}
if(e.getSource()==btnExit)
System.exit(0);
}
}
public static void main(String args[])
{
Enrol obj = new Enrol();
}
}