Topic: 请各位帮忙看看哪里出错了(Cannot invoke length() on the array type char[])

  Print this page

1.请各位帮忙看看哪里出错了(Cannot invoke length() on the array type char[]) Copy to clipboard
Posted by: binghuo007
Posted on: 2006-03-15 09:54

多谢了

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author FC
*/
public class LoginPanel extends JFrame {
JPanel panel=new JPanel();
JLabel label1=new JLabel("用户名");
JLabel label2=new JLabel("密码");
JTextField field1=new JTextField(10);
JPasswordField field2=new JPasswordField(10);
JButton btl1=new JButton("登陆");
JButton btl2=new JButton("取消");
JButton btl3=new JButton("重填");
public LoginPanel() {
this.initb();
}
public void initb(){

this.getContentPane().add(panel);
panel.add(label1);
panel.add(field1);
panel.add(label2);
panel.add(field2);
panel.add(btl1);
panel.add(btl2);
panel.add(btl3);
MyActionListener ma=new MyActionListener();
btl1.addActionListener(ma);
btl3.addActionListener(new MyActionListener());
}
class MyActionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
Object obj=e.getSource();
if(obj==btl1){
if(field1.getText().length()==0){
JOptionPane.showMessageDialog(null ,"用户名不能为空");
}
if(field2.getPassword().length()==0){
JOptionPane.showMessageDialog(null,"密码不能为空");
}

else {
JOptionPane.showMessageDialog(null,"即将转入页面,请稍候");
}
}
else if(obj==btl3){
field1.setText("");
field2.setText("");
}
}
}
public void displayDetails(){
this.show();
this.setSize(400, 400);
this.setDefaultCloseOperation(3);
}
public static void main(String args[]){
LoginPanel p=new LoginPanel();
p.displayDetails();
}

}

2.Re:请各位帮忙看看哪里出错了 [Re: binghuo007] Copy to clipboard
Posted by: hanlichen
Posted on: 2006-03-15 11:37

if (field2.getPassword().length() == 0)

3.Re:请各位帮忙看看哪里出错了 [Re: binghuo007] Copy to clipboard
Posted by: hanlichen
Posted on: 2006-03-15 11:38

Cannot invoke length() on the array type char[]

4.Re:请各位帮忙看看哪里出错了 [Re: binghuo007] Copy to clipboard
Posted by: JavaandC
Posted on: 2006-03-15 12:35

if(field2.getPassword().length()==0) 改成 if(field2.getPassword().length==0)

5.Re:请各位帮忙看看哪里出错了 [Re: binghuo007] Copy to clipboard
Posted by: piaoling
Posted on: 2006-03-15 16:49

呵呵。。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923