此程序没有编译错误,但当用户名跟密码输入正确按登录时,老是出现清空状况,而不能显示登录成功.
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class Xianshi extends Applet implements ActionListener{
Label lb,mima,prompt;
TextField tf1,tf2;
Button btn1;
Image myImage;
public void init() {
lb=new Label("用户");
mima=new Label("密码");
prompt=new Label();
tf1=new TextField(20);
tf2=new TextField(20);
tf2.setEchoChar('*');
btn1=new Button("登录");
myImage=getImage(getDocumentBase(),"11.jpg");
add(lb);
add(mima);
add(prompt);
add(tf1);
add(tf2);
add(btn1);
btn1.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
String str1=tf1.getText();
String str2=tf2.getText();
if(e.getSource()==btn1)
if((str1=="lcj")&&(str2=="510"))
prompt.setText("登录成功!");
else
{ tf1.setText("");
tf2.setText("");
}
}
public void paint(Graphics g)
{
g.drawImage(myImage,50,50,this);
}
}