小窗口事件出事了
import java.awt.*;import java.awt.event.*;
public class B_H_J extends Frame implements ActionListener
{
private TextField B_char,B_text;//一个文本行
private Button button_char;//一个按钮
public B_H_J()
{
super("迷途青年资料!");
this.setBounds(300,300,300,200);
this.setBackground(java.awt.Color.red);
this.setLayout(new java.awt.FlowLayout(FlowLayout.LEFT));
this.add(new Label("请输入姓名:"));
B_char=new TextField(" ",10);
this.add(B_char);
this.add(new Label("显示被调查者信息:"));
B_text=new TextField(" ",100);
this.add(B_text);
button_char=new Button("确定");
this.add(button_char);
button_char.addActionListener(this);
this.addWindowListener(new WinClose());
this.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==button_char)
{
String str=B_char.getText(),r="一员虎将";//这段代码好像没有执行,觉得应该可以!但是....
if(B_char.getText()=="张飞")
B_text.setText("一员虎将");
if(str=="李广")
B_text.setText("百步穿杨!");
}
}
public static void main(String args[])
{
new B_H_J();
}
}
class WinClose implements WindowListener
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
public void windowOpened(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void windowClosed(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
}
程序可以运行,呵呵呵,但结果不对!!这是咋回事?想不明白!!请大家给指点一下!!!