请问:buttonsign定义为一个JButton,那么,buttonsign.addActionListener(this)是什么意思??

Tsingwa 2002-03-22 11:06:32
请问:buttonsign定义为一个JButton,那么,buttonsign.addActionListener(this)是什么意思??
...全文
141 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
gflei 2002-03-22
  • 打赏
  • 举报
回复
奥,我明白你的意思了,在此并不立即触发,只有激发事件,才能触发,他的响应代码应该在actionPerforme(..)中
gflei 2002-03-22
  • 打赏
  • 举报
回复
看看事件监听应该就会明白的

想想你的button怎么通知,原因就在与此
Tsingwa 2002-03-22
  • 打赏
  • 举报
回复
可以讲的再详细一点吗!
用鼠标响应吗??


ImageIcon leftButtonIcon = new ImageIcon("images/right.gif");
ImageIcon middleButtonIcon = new ImageIcon("images/middle.gif");
ImageIcon rightButtonIcon = new ImageIcon("images/left.gif");

b1 = new JButton("Disable middle button", leftButtonIcon);
b1.setVerticalTextPosition(AbstractButton.CENTER);/**设置垂直文本位置*/
b1.setHorizontalTextPosition(AbstractButton.LEFT);/**设置水平文本位置*/
b1.setMnemonic(KeyEvent.VK_D);/**加一个键盘上的快捷键*/
b1.setActionCommand("disable");/**Sets the command name for the action event fired by this button.
By default this action command is set to match the label of the button*/

b2 = new JButton("Middle button", middleButtonIcon);
b2.setVerticalTextPosition(AbstractButton.BOTTOM);
b2.setHorizontalTextPosition(AbstractButton.CENTER);
b2.setMnemonic(KeyEvent.VK_M);

b3 = new JButton("Enable middle button", rightButtonIcon);
//Use the default text position of CENTER, RIGHT.
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enable");
b3.setEnabled(false);/**Sets the enabled state of the object,
if true, enables this object; otherwise, disables it*/

//Listen for actions on buttons 1 and 3.
b1.addActionListener(this)


未完!但就想问b1.addActionListener(this)是立即触发吗??
Tsingwa 2002-03-22
  • 打赏
  • 举报
回复
可以讲的再详细一点吗!
用鼠标响应

ImageIcon leftButtonIcon = new ImageIcon("images/right.gif");
ImageIcon middleButtonIcon = new ImageIcon("images/middle.gif");
ImageIcon rightButtonIcon = new ImageIcon("images/left.gif");

b1 = new JButton("Disable middle button", leftButtonIcon);
b1.setVerticalTextPosition(AbstractButton.CENTER);/**设置垂直文本位置*/
b1.setHorizontalTextPosition(AbstractButton.LEFT);/**设置水平文本位置*/
b1.setMnemonic(KeyEvent.VK_D);/**加一个键盘上的快捷键*/
b1.setActionCommand("disable");/**Sets the command name for the action event fired by this button.
By default this action command is set to match the label of the button*/

b2 = new JButton("Middle button", middleButtonIcon);
b2.setVerticalTextPosition(AbstractButton.BOTTOM);
b2.setHorizontalTextPosition(AbstractButton.CENTER);
b2.setMnemonic(KeyEvent.VK_M);

b3 = new JButton("Enable middle button", rightButtonIcon);
//Use the default text position of CENTER, RIGHT.
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enable");
b3.setEnabled(false);/**Sets the enabled state of the object,
if true, enables this object; otherwise, disables it*/

//Listen for actions on buttons 1 and 3.
b1.addActionListener(this)


wwangl 2002-03-22
  • 打赏
  • 举报
回复
响应这个button的事件

62,617

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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