当前位置:编程学习 > JAVA >>

java用户登录界面,下面代码哪错了呢?

package wyf.jc;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

 
public class child extends JFrame implements ActionListener
{
 private JPanel jp=new JPanel();
 private JLabel[] jlArray={
   new JLabel("用户名"),new JLabel("密码"),
   new JLabel("确认密码"),new JLabel("电子邮箱"),
   new JLabel("")
 };
 private JButton jbArray[]={new JButton("注册"),new JButton("清空")};
 private JTextField jtxtName=new JTextField();
 private JPasswordField jtxtPassword=new JPasswordField();
 private JPasswordField jtxtPassword2=new JPasswordField();
 private JTextField jtxtSure=new JTextField();
 public child(){
  jp.setLayout(null);
  for(int i=0;i<=3;i++)
  {
   jp.add(jlArray[i]);
   jlArray[i].setBounds(30,20+i*50,80,26);
   jbArray[i].setBounds(50+i*100,130,80,26);
  }
  jp.add(jbArray[0]);
  jp.add(jbArray[1]);
  jbArray[0].addActionListener(this);
  jbArray[1].addActionListener(this);
  jbArray[0].setBounds(80,220,80,26);
  jbArray[1].setBounds(150,220,80,26);
  jtxtName.setBounds(80,20,180,30);
  jp.add(jtxtName);
  jtxtName.addActionListener(this);
  jtxtPassword.setBounds(80,70,180,30);
  jp.add(jtxtPassword);
  jtxtPassword.setEchoChar('*');
  jtxtPassword2.setBounds(80,120,180,30);
  jp.add(jtxtPassword2);
  jtxtPassword2.addActionListener(this);
  jtxtPassword2.setEchoChar('*');
  jtxtSure.setBounds(80,170,180,30);
  jp.add(jtxtSure);
  jtxtSure.addActionListener(this);
  jlArray[4].setBounds(10,180,300,30);
  jp.add(jlArray[2]);
  this.add(jp);
  this.setTitle("用户注册");
  this.setResizable(false);
  this.setBounds(160,250,300,250);
  this.setVisible(true);
 }
 public void actionPerformed(ActionEvent e)
 {
  if(e.getSource()==jtxtName)
  {
   jtxtPassword.requestFocus();
  }
  else if(e.getSource()==jbArray[1])
  {
   jlArray[3].setText("");
   jtxtName.setText("");
   jtxtPassword.setText("");
   jtxtName.requestFocus();
  }
  else if{
   jlArray[4].setText("正在注册中");
  }else{
   jlArray[4].setText("对不起,非法的用户名和密码!!!");
  }
  
 }
 public static void main(String[] args)
 {
  new child();
 }
} --------------------编程问答-------------------- else if(e.getSource()==jbArray[1])
  {
   jlArray[3].setText("");
   jtxtName.setText("");
   jtxtPassword.setText("");
   jtxtName.requestFocus();
  }
  else if{
   jlArray[4].setText("正在注册中");
  }else{
   jlArray[4].setText("对不起,非法的用户名和密码!!!");
  }
LZ这里的else if后面少了个判断条件。还有27行的设置的范围越界了。 --------------------编程问答--------------------
引用 1 楼 xiaoyunyun23 的回复:
else if(e.getSource()==jbArray[1])
  {
   jlArray[3].setText("");
   jtxtName.setText("");
   jtxtPassword.setText("");
   jtxtName.requestFocus();
  }
  else if{
   jlArray[4].se……

楼上神人也,我看见不发报错信息的就头疼,就不愿意看,你不发报错信息的话就等会把所有程序看一遍,其工作也几乎等于自己写一个。 --------------------编程问答--------------------
引用 2 楼 AA5279AA 的回复:
引用 1 楼 xiaoyunyun23 的回复:
else if(e.getSource()==jbArray[1])
  {
   jlArray[3].setText("");
   jtxtName.setText("");
   jtxtPassword.setText("");
   jtxtName.requestFocus();
  }
  else if{
   ……


把代码拷到eclipse里,else的那个问题就能发现了。然后运行下程序,越界的问题也能查出来,会难吗? --------------------编程问答-------------------- 说错了,不需要运行。。。粗略看下就可以了。 --------------------编程问答--------------------
引用 3 楼 fw347969680 的回复:
引用 2 楼 AA5279AA 的回复:引用 1 楼 xiaoyunyun23 的回复:
else if(e.getSource()==jbArray[1])
  {
   jlArray[3].setText("");
   jtxtName.setText("");
   jtxtPassword.setText("");
   jtxtName.requ……

不难,但是并不是每台机器都装有Eclipse的。
--------------------编程问答-------------------- 1.首先,for循环里的 jbArray[i].setBounds(50+i*100,130,80,26);这句是否可以去掉?
2.jp.add(jlArray[2]);是否应该把2改为4?
3.jlArray[3].setText("");是否应该把3改为4?而且清空不彻底,有两个没清空。
4.else if{  这里语法错误,少个条件。
5.if(e.getSource()==jtxtName)
  {
      jtxtPassword.requestFocus();
  } 不知道这句楼主是想干嘛。
6.楼主的发帖时间很奇怪啊。。。 --------------------编程问答-------------------- 谢谢哦,共分享
补充:Java ,  Eclipse
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,