JPanel的事件监听

jincheng2008 2009-08-14 04:39:24
烦死了,对JPanel中移除所有组件,不能监听。请大家看看:



InfoCol_Application.listPanel.removeAll();

InfoCol_Application.listPanel.removeComponentListener(new ComponentAdapter (){
public void componentHidden(ComponentEvent e){
new InfoCol_Application().updateBackImage();
}

});


InfoCol_Application.listPanel.removeContainerListener(new ContainerAdapter(){

public void componentRemoved(ContainerEvent e) {
new InfoCol_Application().updateBackImage();
}


});


都不行,我疯了
...全文
237 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
monkeyking1987 2009-08-15
  • 打赏
  • 举报
回复
哎呀,你弄错了,那个removeComponentListener不是监听移除组件事件的,而是用它不再接收发自此组件的组件事件的。
要移除组件,比如添加一个“删除组件”按钮,给按钮添加ActionListener监听器,并覆盖方法,在此事件里调用JPANEL的remove方法才可以啊。
jincheng2008 2009-08-14
  • 打赏
  • 举报
回复
那如何对JPanel中移除所有组件事件监听啊,我看了半天的API也没明白
gongfuliang 2009-08-14
  • 打赏
  • 举报
回复
removeComponentListener是指删除Component上注册的监听实例,并不是用来删除组件
musecangying007 2009-08-14
  • 打赏
  • 举报
回复
sf
1、 自定义类说明: (1)类名:MainTest 作用:主类,构建主界面 继承的父类:Jframe 主要实现接口:ActionListener 主要成员变量: private JPanel ContentPane; private JButton Insert = new JButton(); private JButton Select = new JButton(); private JButton Update = new JButton(); 内部类:MainTest_actionPerformed,主页面的事件监听。 jenter_ actionPerformed,按钮的事件监听。 主要成员方法: public MainTest() public static void main(String[] args) (2)类名:Insert 作用:实现添加个人信息 继承的父类:Jframe 主要实现接口:ActionListener 主要成员变量: private JPanel ContentPane; private JLabel jlab1 = new JLabel(); private JLabel jlab2 = new JLabel(); private JLabel jlab3 = new JLabel(); private JLabel jlab4 = new JLabel(); private JLabel jlab5 = new JLabel(); private JLabel jlab6= new JLabel(); private JLabel jlab7 = new JLabel(); private JLabel jlab8 = new JLabel(); private JTextField jtextfield1 = new JTextField(); private JTextField jtextfield2 = new JTextField(); private JTextField jtextfield3 = new JTextField(); private JTextField jtextfield4 = new JTextField(); private JTextField jtextfield5 = new JTextField(); private JComboBox jcombobox1 = new JComboBox(); private JComboBox jcombobox2 = new JComboBox(); private JTextArea jtextarea = new JTextArea(); private JButton sure = new JButton(); 内部类:sure_actionperformed,按钮的事件监听,实现对数据的插入。 主要成员方法:public Insert(); (3)类名:Update 作用:对个人信息进行修改。 继承的父类:Jframe 主要实现接口:ActionListener 主要成员变量: private JPanel ContentPane; private JLabel jlab1 = new JLabel(); private JLabel jlab2 = new JLabel(); private JLabel jlab3 = new JLabel(); private JLabel jlab4 = new JLabel(); private JLabel jlab5 = new JLabel(); private JTextField jtextfield1 = new JTextField(); private JTextField jtextfield2 = new JTextField(); private JTextField jtextfield3 = new JTextField(); private JTextField jtextfield4 = new JTextField(); private JButton sure = new JButton(); private JButton upda = new JButton(); 主要成员方法: public Update() public void actionPerformed(ActionEvent e) (4)类名:Select 作用:查询学生个人信息 继承的父类:Jframe 主要实现接口:ActionListener 主要成员变量: private JTextArea taInfo=new JTextArea(); private JPanel panel=new JPanel(); private JTextField jtextfield1=new JTextField(); private JButton jbutton=new JButton("查询"); private JLabel jlabel=new JLabel("学号"); 主要成员方法: public Select() public void actionPerformed(ActionEvent e)

62,615

社区成员

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

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