java中JLabel添加监听事件_[求助]关于JLabel添加监听器的问题。请各位帮忙!!

[求助]关于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

----------------解决方案--------------------------------------------------------

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441949.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

指数循环节证明

还有关键的一步忘写了phi(m)>r的注意因为ma^r*m‘’所以phi(m)>phi(a^r)>r,所以就相当于phi(m)为循环节,不过如果指数小于phi(m)只能直接算了。。 注意这里的m与a^r是互质的上面忘写了。。 转自https://blog.csdn.net/guoshiyuan484/article/details/787…

java语言中的类可以_java 语言中的类

类一、类类是具有相同性质的一类事物的总称, 它是一个抽象的概念。它封装了一类对象的状态和方法, 是创建对象的模板。类的实现包括两部分: 类声明和类体类的声明类声明的基本格式为:[ 访问权限修饰符]c l a s s类名[extends超类][ implments实现的接口列表]{}说 明:① 访问权限…

【HDU - 1546】 Idiomatic Phrases Game(Dijkstra,可选map处理字符串)

题干: Tom is playing a game called Idiomatic Phrases Game. An idiom consists of several Chinese characters and has a certain meaning. This game will give Tom two idioms. He should build a list of idioms and the list starts and ends with the two…

Java迭代器修改链表_Java恼人的迭代器不会返回链表中的元素

给出以下代码:public void insertIntoQueue(float length,int xElement,int yElement,int whichElement){Dot dot new Dot(xElement,yElement);GeometricElement element null;// some codeint robotX,robotY;boolean flag false;for (Iterator i robotList.ite…

(精)【ACM刷题之路】POJ题目详细多角度分类及推荐题目

POJ上的一些水题(可用来练手和增加自信) (poj3299,poj2159,poj2739,poj1083,poj2262,poj1503,poj3006,poj2255,poj3094) 初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. (5)构造法.(poj…

java输入正确的信息_判断用户输入的信息是否正确

package com.Embed.util;import java.sql.Connection;import java.sql.DriverManager;import java.text.SimpleDateFormat;import java.util.Date;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Common {// 判断用户输入的时间格式是否正确publ…

【UVA - 10815】 Andy's First Dictionary(STL+字符处理)

题干: Andy, 8, has a dream - he wants to produce his very own dictionary. This is not an easy task for him, as the number of words that he knows is, well, not quite enough. Instead of thinking up all the words himself, he has a briliant idea. F…

java里dir是什么意思_关于文件系统:为什么user.dir系统属性在Java中工作?

我读过的几乎每篇文章都告诉我,你不能用Java创建chdir。 这个问题的公认答案说你不能用Java做到这一点。但是,这里有一些我尝试过的东西:geocodebox:~$ java -versionjava version"1.6.0_14"Java(TM) SE Runtime Environment (buil…

【Uva - 10935】 Throwing cards away I (既然是I,看来还有Ⅱ、Ⅲ、Ⅳ?)(站队问题队列问题)

题干: Given is an ordered deck of n cards numbered 1 to n with card 1 at the top and card n at the bottom. The following operation is performed as long as there are at least two cards in the deck: Throw away the top card and move the card that …

腾讯 tars java_腾讯TARS开源团队郑苏波:腾讯微服务开发框架的源码剖析

郑苏波:大家下午好!我是腾讯微服务的郑苏波。先做一个框架的介绍,Tars是一个支持多语言内嵌服务治理功能的框槛,能跟DevOps比较好的协同开发。这个框架四大特点:一是对用户透明实现,让业务可以聚焦自己的逻…

【POJ - 3310】Caterpillar(并查集判树+树的直径求树脊椎(bfs记录路径)+dfs判支链)

题干: An undirected graph is called a caterpillar if it is connected, has no cycles, and there is a path in the graph where every node is either on this path or a neighbor of a node on the path. This path is called the spine of the caterpillar …

*【POJ - 1860】Currency Exchange (单源最长路---Bellman_Ford算法判正环)

题干: Description Several currency exchange points are working in our city. Let us suppose that each point specializes in two particular currencies and performs exchange operations only with these currencies. There can be several points specia…

使用java开发应用程序_使用Java中的插件支持开发应用程序

我一直在研究如何开发可以加载插件的应用程序.到目前为止,我已经看到这可以通过定义一个接口来实现,并让插件实现它.但是,我当前的问题是如何在Jars中打包时加载插件.有没有“最好的”方法呢?我正在考虑的当前逻辑是让每个插件和他们的Jar内部寻找实现接口的类.但我…

【POJ - 1995】Raising Modulo Numbers(裸的快速幂)

题干: People are different. Some secretly read magazines full of interesting girls pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that t…

软件设计师下午题java_2018上半年软件设计师下午真题(三)

● 阅读下列说明和Java代码,将应填入(n)处的字句写在答题纸的对应栏内。【说明】生成器( Builder)模式的意图是将一个复杂对象的构建与它的表示分离,使得同样的构建过程可以创建不同的表示。图6-1所示为其类图。【Java代码】import java.util.*;class Product {priv…

【ZOJ - 2724】【HDU - 1509】Windows Message Queue(优先队列)

题干: Message queue is the basic fundamental of windows system. For each process, the system maintains a message queue. If something happens to this process, such as mouse click, text change, the system will add a message to the queue. Meanwhil…

java细粒度锁_Java细粒度锁实现的3种方式

最近在工作上碰见了一些高并发的场景需要加锁来保证业务逻辑的正确性,并且要求加锁后性能不能受到太大的影响。初步的想法是通过数据的时间戳,id等关键字来加锁,从而保证不同类型数据处理的并发性。而java自身api提供的锁粒度太大&#xff0c…

【POJ - 1062】【nyoj - 510】昂贵的聘礼 (Dijkstra最短路+思维)

题干: 年轻的探险家来到了一个印第安部落里。在那里他和酋长的女儿相爱了,于是便向酋长去求亲。酋长要他用10000个金币作为聘礼才答应把女儿嫁给他。探险家拿不出这么多金币,便请求酋长降低要求。酋长说:"嗯,如果…

php e notice,PHP函数之error_reporting(E_ALL ^ E_NOTICE)详细说明

举例说明:在Windows环境下:原本在php4.3.0中运行正常的程序,在4.3.1中为何多处报错,大体提示为:Notice:Undefined varialbe:变量名称. 例如有如下的代码: 复制代码 代码如下:if (!$tmp_i) { $tmp_i10; }在4…

【POJ - 3169】 Layout(差分约束+spfa)(当板子记?)

题干&#xff1a; Like everyone else, cows like to stand close to their friends when queuing for feed. FJ has N (2 < N < 1,000) cows numbered 1..N standing along a straight line waiting for feed. The cows are standing in the same order as they are nu…