Topic: 文本框的监视器问题,谢谢

  Print this page

1.文本框的监视器问题,谢谢 Copy to clipboard
Posted by: benkhe
Posted on: 2005-12-27 16:46


import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class a1 extends Applet implements ActionListener
{
TextField text1,text2,text3;
public void init()
{
text1=new TextField(10);
text1=new TextField(10);
text1=new TextField(10);
add(text1);add(text2);add(text3);
text1.addActionListener(this);//主类的实例作为text1的监视器
}
public void actionPerformed(ActionEvent e)
{
if((e.getSource()==text1)&&(text1.getText().equals("boy")))
{text3.setText("男孩");}

else if((e.getSource()==text1)&&(text1.getText().equals("girl")))
{text3.setText("女孩");}

else if((e.getSource()==text1)&&(text1.getText().equals("sun")))
{text3.setText("太阳");}
}

}


调试正确,却出现如图所示的结果,请问这是为什么?

 
不好意思,不会上图
只好放在附件里
Please don't use BMP, which is huge and only viewable with IE.
I have converted the 729KB BMP to a 3KB GIF with the simple PAINT program.
Embedded JPG, GIF and PNG image would be displayed at the bottom of a post:


2.Re:文本框的监视器问题,谢谢 [Re: benkhe] Copy to clipboard
Posted by: 土妞
Posted on: 2005-12-27 18:42

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class a1 extends Applet implements ActionListener
{
TextField text1,text2,text3;
public void init()
{
text1=new TextField(10);
text1=new TextField(10);
text1=new TextField(10);
add(text1);add(text2);add(text3);
text1.addActionListener(this);//主类的实例作为text1的监视器
}
public void actionPerformed(ActionEvent e)
{
if((e.getSource()==text1)&&(text1.getText().equals("boy")))
{text3.setText("男孩");}
if((e.getSource()==text2)&&(text2.getText().equals("girl")))//应该这样写
{text3.setText("女孩");}
if((e.getSource()==text3)&&(text3.getText().equals("sun")))
{text3.setText("太阳");}

}

}

3.Re:文本框的监视器问题,谢谢 [Re: benkhe] Copy to clipboard
Posted by: benkhe
Posted on: 2005-12-27 20:31

楼上的耍我呢?

不过我刚已经知道了

4.Re:文本框的监视器问题,谢谢 [Re: benkhe] Copy to clipboard
Posted by: why
Posted on: 2005-12-27 21:54

text1 = new TextField(10);
text2 = new TextField(10);
text3 = new TextField(10);

Please don't use BMP, which is huge and only viewable with IE.
I have converted the 729KB BMP to a 3KB GIF with the simple PAINT program.

5.Re:文本框的监视器问题,谢谢 [Re: benkhe] Copy to clipboard
Posted by: benkhe
Posted on: 2005-12-27 22:22

错误我知道了,版主说的话我记住了


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923