一个事件的问题??帮忙看看这个事件是怎么会发生在Fan2的按钮上呢?

haif1978 2002-02-18 10:46:26

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

class MyPanel extends Panel
{
static Button But1, But2, But3;
MyPanel()
{
But1 = new Button("改变背景颜色");
But2 = new Button("Not");
But3 = new Button("Save");
add(But1);add(But2);add(But3);
But1.addActionListener(new ButEvent());
But2.addActionListener(new ButEvent());
But3.addActionListener(new ButEvent());
}
}
public class Example111 extends Applet
{
static MyPanel Pan1,Pan2,Pan3;
Button But4;
public void init()
{
Pan1 = new MyPanel();
Pan2 = new MyPanel();
But4 = new Button("我不在MyPanel面板里面");
add(Pan1);add(Pan2);add(But4);
}
}

class ButEvent implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == Example111.Pan1.But1)
{
Example111.Pan2.setBackground(Color.RED);
}
if(e.getSource() == Example111.Pan1.But2)
{
Example111.Pan2.setBackground(Color.BLACK);
}
if(e.getSource() == Example111.Pan1.But3)
{
Example111.Pan2.setBackground(Color.YELLOW);
}
}
}
...全文
52 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
liujun_cn 2002-02-18
  • 打赏
  • 举报
回复
I am sorry,my system does not support chinese.
haif1978 2002-02-18
  • 打赏
  • 举报
回复
楼上的老兄,你的回答可以用中文么!我的E文实在是不好!
liujun_cn 2002-02-18
  • 打赏
  • 举报
回复
guan zhu.
liujun_cn 2002-02-18
  • 打赏
  • 举报
回复
I think you should use a layout manager to adjust the pan1 and pan2 's position,so you meight get a better result.
haif1978 2002-02-18
  • 打赏
  • 举报
回复
我问的是事件!
我的想法是在做Pan1上的按钮事件,
可是程序执行后事件的来源是Pan2上的按钮!
ggyy 2002-02-18
  • 打赏
  • 举报
回复
if(e.getSource() == Example111.Pan1.But2)
{
Example111.Pan2.setBackground(Color.BLACK);
}
ggyy 2002-02-18
  • 打赏
  • 举报
回复
是不是说你点击:pan1.按钮1
执行如同点击pan2.按钮????

23,404

社区成员

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

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