当前位置: 代码迷 >> Java相关 >> 关于Java解决思路
  详细解决方案

关于Java解决思路

热度:8705   发布时间:2013-02-25 21:45:46.0
关于Java
package xu4;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Xu4 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 jtxtName1=new JTextField();
private JPasswordField jtxtPassword1=new JPasswordField();
private JPasswordField jtxtPassword2=new JPasswordField();
private JTextField jtxtName2=new JTextField();
public Xu4(){
jp.setLayout(null);
for(int i=0;i<4;i++){
jlArray[i].setBounds(30,20+i*50,80,26);
jp.add(jlArray[i]);
}
for(int i=0;i<2;i++){
jbArray[i].setBounds(50+i*110,130,80,26);
jp.add(jbArray[i]);
jbArray[i].addActionListener(this);
}
jbArray[0].setBounds(80,220,80,26);
jbArray[1].setBounds(150,220,80,26);
jtxtName1.setBounds(80,20,180,30);
jtxtName2.setBounds(80,170,180,30);
jp.add(jtxtName1);
jp.add(jtxtName2);
jtxtName1.addActionListener(this);
jtxtName2.addActionListener(this);
jtxtPassword1.setBounds(80,70,180,30);
jtxtPassword2.setBounds(80,120,180,30);
jp.add(jtxtPassword1);
jp.add(jtxtPassword2);
jtxtPassword1.setEchoChar('*');
jtxtPassword2.setEchoChar('*');

jtxtPassword1.addActionListener(this);
jtxtPassword2.addActionListener(this);
jlArray[4].setBounds(10,180,300,30);
jp.add(jlArray[4]);
this.add(jp);
this.setTitle("用户注册");
this.setResizable(false);
this.setBounds(160,250,300,350);
this.setVisible(true);


}
public void actionPerformed(ActionEvent e){
if(e.getSource()==jtxtName1){
jtxtPassword1.requestFocus();
}
else if(e.getSource()==jbArray[1]){
jlArray[4].setText(" ");
jtxtName1.setText(" ");
jtxtName2.setText(" ");
jtxtPassword1.setText(" ");
jtxtPassword2.setText(" ");
jtxtName1.requestFocus();
}
else if(e.getSource()==jbArray[0]);
{
jlArray[4].setText("处理注册中");
}
else
{
jlArray[4].setText("对不起,非法的用户名和密码!!!");}
}





/**
* @param args
*/
public static void main(String[] args) {
new Xu4();
// TODO 自动生成方法存根

}

}
这个程序为什么else那里是错的。。我知道那么写不合理,怎么改进,帮帮忙啊

------解决方案--------------------------------------------------------
else if(e.getSource()==jbArray[0]);//!!
 {
 jlArray[4].setText("处理注册中");
 }
------解决方案--------------------------------------------------------
Java code
{jlArray[4].setText("对不起,非法的用户名和密码!!!");}}
  相关解决方案