能不能帮忙看下这个代码啊?我输入正确用户名和密码的时候为什么还说我错误呢?哪里有错啊???万分感谢!!!!
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class One implements ActionListener
{
JFrame f;
JPanel p1,p2,p3,p4,p5;
JLabel l1,l2;
JButton B1,B2;
JTextField tf1,tf2;
JPasswordField pf;
public static void main(String args[])
{
One one=new One();
one.go();
} public void go()
{
f=new JFrame();
f.setSize(300,300);
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
l1=new JLabel("用户ID");
l2=new JLabel("用户口令");
B1=new JButton("登录");
B2=new JButton("清除");
tf1=new JTextField(30);
tf2=new JTextField(30);
pf=new JPasswordField(30); p5.setLayout(new GridLayout(2,2));
p5.add(l1);
p5.add(tf1);
p5.add(l2);
p5.add(pf);
p3.add(B1);
p3.add(B2);
p4.add(tf2);
f.getContentPane().add(p5,BorderLayout.NORTH);
f.getContentPane().add(p3,BorderLayout.CENTER);
f.getContentPane().add(p4,BorderLayout.SOUTH);
f.setVisible(true);
B1.addActionListener(this);
B2.addActionListener(this);
tf2.setEditable(false);
}
public void actionPerformed(ActionEvent e)
{
JButton xb=(JButton)e.getSource();
if(xb==B1)
{
String username=tf1.getText();
if(username!="javaclass")
tf2.setText("用户ID或用户口令不正确!");
else
{
char[]pw=pf.getPassword();
username=new String(pw);
if(username!="200905")
tf2.setText("用户ID或用户口令不正确!");
else
tf2.setText("登录成功!");
}
}
else
{
tf1.setText("");
pf.setText("");
}
}}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
public class One implements ActionListener
{
JFrame f;
JPanel p1,p2,p3,p4,p5;
JLabel l1,l2;
JButton B1,B2;
JTextField tf1,tf2;
JPasswordField pf;
public static void main(String args[])
{
One one=new One();
one.go();
} public void go()
{
f=new JFrame();
f.setSize(300,300);
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
l1=new JLabel("用户ID");
l2=new JLabel("用户口令");
B1=new JButton("登录");
B2=new JButton("清除");
tf1=new JTextField(30);
tf2=new JTextField(30);
pf=new JPasswordField(30); p5.setLayout(new GridLayout(2,2));
p5.add(l1);
p5.add(tf1);
p5.add(l2);
p5.add(pf);
p3.add(B1);
p3.add(B2);
p4.add(tf2);
f.getContentPane().add(p5,BorderLayout.NORTH);
f.getContentPane().add(p3,BorderLayout.CENTER);
f.getContentPane().add(p4,BorderLayout.SOUTH);
f.setVisible(true);
B1.addActionListener(this);
B2.addActionListener(this);
tf2.setEditable(false);
}
public void actionPerformed(ActionEvent e)
{
JButton xb=(JButton)e.getSource();
if(xb==B1)
{
String username=tf1.getText();
if(username!="javaclass")
tf2.setText("用户ID或用户口令不正确!");
else
{
char[]pw=pf.getPassword();
username=new String(pw);
if(username!="200905")
tf2.setText("用户ID或用户口令不正确!");
else
tf2.setText("登录成功!");
}
}
else
{
tf1.setText("");
pf.setText("");
}
}}
解决方案 »
- 一道java算法题
- 怎么产生4位数的年号??菜鸟求助
- 对于熟悉c#的有几年编程工作经验的程序员,java语法也懂得一点,上手j2ee,stuct要多久时间
- java 应用程序中 画图的问题
- 跪求此算法的解密算法,高手请进,急急急急急急急急急急急急急急
- 各位老大,how to convert Unicode code number to a character just like String.fromCharCode in jscript?
- 如何动态选择字体的字号、字型、颜色等?就象打开字体选择框的效果。
- 检查一个线程run方法的执行时间,这样写是否可行?
- JAVA String 编码问题
- 多线程并发向数据库插入数据问题
- 如何 在DocumentListener 中获取 发生改变的 JTextField
- java变量的使用
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.BorderLayout;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
public class One implements ActionListener
{
JFrame f;
JPanel p1,p2,p3,p4,p5;
JLabel l1,l2;
JButton B1,B2;
JTextField tf1,tf2;
JPasswordField pf;
public static void main(String args[])
{
One one=new One();
one.go();
} public void go()
{
f=new JFrame();
f.setSize(300,300);
p1=new JPanel();
p2=new JPanel();
p3=new JPanel();
p4=new JPanel();
p5=new JPanel();
l1=new JLabel("用户ID");
l2=new JLabel("用户口令");
B1=new JButton("登录");
B2=new JButton("清除");
tf1=new JTextField(30);
tf2=new JTextField(30);
pf=new JPasswordField(30); p5.setLayout(new GridLayout(2,2));
p5.add(l1);
p5.add(tf1);
p5.add(l2);
p5.add(pf);
p3.add(B1);
p3.add(B2);
p4.add(tf2);
f.getContentPane().add(p5,BorderLayout.NORTH);
f.getContentPane().add(p3,BorderLayout.CENTER);
f.getContentPane().add(p4,BorderLayout.SOUTH);
f.setVisible(true);
B1.addActionListener(this);
B2.addActionListener(this);
tf2.setEditable(false);
}
public void actionPerformed(ActionEvent e)
{
JButton xb=(JButton)e.getSource();
if(xb==B1)
{
String username=tf1.getText();
System.out.println(username);
if(!username.equals("javaclass"))
tf2.setText("用户ID或用户口令不正确!");
else
{
char[]pw=pf.getPassword();
username=new String(pw);
System.out.println(username);
if(!username.equals("200905"))
tf2.setText("用户ID或用户口令不正确!");
else
tf2.setText("登录成功!");
}
}
else
{
tf1.setText("");
pf.setText("");
}
}}