求java高手解答

wode_ll 2012-07-01 09:12:04
阅读下列程序,回答问题。
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;

public class TestChange extends JApplet {
JButton button;
public void init()
{
button = new JButton("click here ");
getContentPane().add(button);
}
class ButtonListener implements ActionListener //内部类
{ public void actionPerformed(ActionEvent evt){
JButton b= (JButton)evt.getSource();
b.setText("you have clicked");
}
}
}

该程序创建包含一个按钮的applet,当点击按钮时将改变按钮的标题。
为满足要求,对上面代码来说以下哪一个为真?
A) 监听类需注册到button控件,为此,在JApplet类的init方法中编写以下代码。
ButtonListener bListener=new ButtonListener();
button.addActionListener(bListener);
B) 监听类需注册到button控件,为此,在JApplet类的init方法中编写以下代码
ButtonListener bListener=new ButtonListener();
bListener.addActionListener(button);
C) 不需要改动代码,上述程序将按照要求正常运行得出结果
D) 按下面给出的,从init方法调用JApplet类的addActionListener方法
addActionListener(button);
...全文
88 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wode_ll 2012-07-04
  • 打赏
  • 举报
回复
谢谢 对我挺有用的
ak47wjs 2012-07-02
  • 打赏
  • 举报
回复
答案:A

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧