| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 714 人关注过本帖
标题:帮我看看错在哪!!!!!!!!
只看楼主 加入收藏
LoveGood
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-6-2
收藏
 问题点数:0 回复次数:2 
帮我看看错在哪!!!!!!!!
总是判断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();
     }
}
2007-12-05 17:01
nima2004
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-11-26
收藏
得分:0 
if (e.getSource()==btnOk){
                    String id = txtId.getText().trim();
                    String id = txtId.getText().trim();
                    String password = new String(txtPassword.getPassword());
                    String password2 = new String(txtPassword2.getPassword());
                    if (id.length()==0){
                    ……
                    }
     }

[[italic] 本帖最后由 nima2004 于 2007-12-5 20:44 编辑 [/italic]]

我是新手,我谁都怕!
2007-12-05 20:41
LoveGood
Rank: 1
等 级:新手上路
帖 子:37
专家分:0
注 册:2007-6-2
收藏
得分:0 
谢谢~~~~~~~~~~!

路越是难走,就越是有味道~
2007-12-05 21:41
快速回复:帮我看看错在哪!!!!!!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.114873 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved