class DemoLabel extends JLabel {
String imgpath =" ";
int width = 0,hight = 0;
public DemoLabel(int w, int h, String file) {
width = w;
hight = h;
imgpath = file;
}
public void paint(Graphics g) {
ImageIcon icon = new ImageIcon(imgpath);
Image img = icon.getImage();
g.drawImage(img,0,0, width,hight, null);
}
}
------------------------------
JLabel lblT1 = new DemoLabel(150,128,"pic/1.png");
lblT1.addMouseListener(new MyMouseListener("pic/1.gif"));
------------------------------
class MyMouseListener extends MouseAdapter {
String imgPath;
public MyMouseListener(String a) {
imgPath = a;
}
public void mousePressed(MouseEvent evt) {
//这个位置如何获得lblT1呢,我想写 lblT1 = new DemoLabel(150,128,imgPath);想重新修改图片路径;
}
}
哪位朋友指点下。。
String imgpath =" ";
int width = 0,hight = 0;
public DemoLabel(int w, int h, String file) {
width = w;
hight = h;
imgpath = file;
}
public void paint(Graphics g) {
ImageIcon icon = new ImageIcon(imgpath);
Image img = icon.getImage();
g.drawImage(img,0,0, width,hight, null);
}
}
------------------------------
JLabel lblT1 = new DemoLabel(150,128,"pic/1.png");
lblT1.addMouseListener(new MyMouseListener("pic/1.gif"));
------------------------------
class MyMouseListener extends MouseAdapter {
String imgPath;
public MyMouseListener(String a) {
imgPath = a;
}
public void mousePressed(MouseEvent evt) {
//这个位置如何获得lblT1呢,我想写 lblT1 = new DemoLabel(150,128,imgPath);想重新修改图片路径;
}
}
哪位朋友指点下。。
解决方案 »
- 一个窗体浮在另一个窗体之上
- 算法,如何把一个字符串中所有元素的组合列出来
- SWT中如何区分不同button的事件?
- Jbutton控件组显示层次的问题
- 如果把一个JAVA的应用程序项目打成的JAR包,能让他运行起来呢!?,
- 自定义接口继承什么?
- 如何学习 部署linux的尝试 大家可以互相学习啊
- 为什么在Tomcat 5.0.28下我用自己写的JNI程序不能读取HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources下面的值名?
- java多线程问题
- java图形界面弄最小公倍数,代码写出来了,没语法错误,但为什么得到的结果永远都是0
- 也许这里不是水区,但请允许我向大家说声谢谢.
- File file = new File(“123.txt”) 用什么办法让文件是隐藏文件
不过看楼主你 要实现这样的效果,不应该这样的。这样太麻烦了。直接使用内部类,或者匿名内部类更简单。