你能告诉我在这个程序中我犯了什么错误吗? 。为什么两个相同的字符串在条件....下不匹配?
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
/*<Applet code="kk" height=400 width=400></applet>*/
public class kk extends Applet implements ActionListener
{
Button b;
TextField t;
String str1,str2;
public void init()
{
b=new Button("submit");
t=new TextField(20);
add(t);
add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
try
{
str2="mohit";
str1=t.getText();
if(str1==str2)
{
System.out.println("matched");
}
else
{
System.out.println("not matched");
}
}
catch(Exception e)
{
System.out.println("Exception caught ");
}
}
}
不知道为什么str1和str2不匹配。
可能重复的[我如何比较Java中的字符串?](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java) – Makoto 2013-09-08 05:08:33