建设论坛网站自学,wordpress 语言包编辑,2021qq网页游戏大全,网站开发进度管理表[求助]关于JLabel添加监听器的问题。请各位帮忙#xff01;#xff01;如图#xff0c;我想在左边的JLabel上添加事件监听器#xff0c;然后再去右边的JPane上进行绘制图形#xff0c;请问这个事件监听器改怎么加#xff0c;好象不能加ActionListener#xff0c;要加什么…[求助]关于JLabel添加监听器的问题。请各位帮忙如图我想在左边的JLabel上添加事件监听器然后再去右边的JPane上进行绘制图形请问这个事件监听器改怎么加好象不能加ActionListener要加什么呢[此贴子已经被作者于2007-5-24 20:09:07编辑过]搜索更多相关的解决方案:JLabel 监听 图形----------------解决方案--------------------------------------------------------你说的是啊,如果你的布局是NULL的话就可以,如果是不同的PANEL,就要在右面建立针对于画笔的方法了,在左面的图象上添加事件,传值,定义右面画笔方法----------------解决方案--------------------------------------------------------对呀但是我不知道添加什么监听器可以说具体点吗----------------解决方案--------------------------------------------------------package paint;import java.awt.event.*;import java.awt.*;import javax.swing.*;/*** author Administrator**/public class Tools extends JPanel implements MouseListener{private JLabel lineLabel ;private JLabel rectLabel ;private JLabel polyLabel ;private JLabel ovalLabel ;private JLabel rrectLabel;private JLabel emLabel;private JLabel emrLabel;private JLabel fullLabel;private JLabel textLabel ;Icon lineBug new ImageIcon( getClass().getResource( image/bug1.JPG ) );Icon rectBug new ImageIcon( getClass().getResource( image/bug2.JPG ) );Icon polyBug new ImageIcon( getClass().getResource( image/bug3.JPG ) );Icon ovalBug new ImageIcon( getClass().getResource( image/bug4.JPG ) );Icon rrectBug new ImageIcon( getClass().getResource( image/bug5.JPG) );Icon textBug new ImageIcon( getClass().getResource( image/bug6.JPG ) );Icon emBug new ImageIcon(getClass().getResource( image/embug.JPG ));//Icon emrBug new ImageIcon(getClass().getResource( image/emrbug.JPG ));//Icon fullBug new ImageIcon(getClass().getResource( image/fullbug.JPG ));private Handle handle;static Color color;public Tools(Handle handle){this.handle handle;handle.setTools(this);//setLayout(null);this.setBackground( Color.WHITE);this.setBounds(0,4,61,500);lineLabel new JLabel(lineBug);add(lineLabel);lineLabel.setVisible(true);rectLabel new JLabel(rectBug);add(rectLabel);rectLabel.setVisible(true);polyLabel new JLabel(polyBug);add(polyLabel);polyLabel.setVisible(true);ovalLabel new JLabel();ovalLabel.setIcon(ovalBug);add(ovalLabel);ovalLabel.addMouseListener(this);ovalLabel.setVisible(true);rrectLabel new JLabel(rrectBug);add(rrectLabel);rrectLabel.setVisible(true);textLabel new JLabel(textBug);add(textLabel);textLabel.setVisible(true);}public void mouseClicked(MouseEvent e){Object o e.getSource();if(o lineLabel){}else if(o rectLabel){}else if(o polyLabel){}else if(o ovalLabel){handle.getDrawJpanel().setLineTag(true);emLabel new JLabel(lineBug);add(emLabel);setLayout(null);emLabel.setVisible(true);}else if(o rrectLabel){}else if(o textLabel){}}public void mousePressed(MouseEvent e){}public void mouseReleased(MouseEvent e){}public void mouseEntered(MouseEvent e){}public void mouseExited(MouseEvent e){}}请问为什么我点了那个椭圆的图标没有反应呢我本来想点击的时候再下面再显示一个图标。----------------解决方案--------------------------------------------------------标签应该不能添加监听器吧你可以把标签改为按钮然后在按钮上添加按钮监听在画图面板上添加鼠标监听我写过一个类似的程序不过我用的是单选按钮呵呵----------------解决方案--------------------------------------------------------哦 但是windows画图伴好象是JLabel吧。我现在觉得论坛人都不错每次提问题都有朋友回答我感动。。谢谢各位了。----------------解决方案--------------------------------------------------------各位帮偶提个建议看看谢谢了。----------------解决方案--------------------------------------------------------DocumentListener 接口啊你可一查下文档监听器----------------解决方案--------------------------------------------------------观察者使用该接口注册以接收文本文档的更改通知。Document 接口的默认实现 (AbstractDocument) 支持异步更改。如果使用此功能(即变化是来自 Swing 事件线程之外的线程)则通过正发生变化的线程通知侦听器。这意味着如果进行异步更新则此接口的实现必须是线程安全的DocumentEvent 通知以 JavaBeans 事件模型为基础。传递给侦听器的传递顺序是没有保证的并且在对 Document 做进一步的更改之前必须通知所有侦听器。这意味着 DocumentListener 的实现不能更改事件源方法摘要void changedUpdate(DocumentEvent e)给出属性或属性集发生了更改的通知。void insertUpdate(DocumentEvent e)给出对文档执行了插入操作的通知。void removeUpdate(DocumentEvent e)给出移除了一部分文档的通知。----------------解决方案--------------------------------------------------------JLabel可以加MouseListener----------------解决方案--------------------------------------------------------