一个类test,里面有一张图片
另外一个类mouseMotion,里面是关于鼠标的事件,点击图片要它响应鼠标该怎么写呢?
///////////////////////////////////////////////类test
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.image.*;
import java.awt.color.*;
import java.util.*;
import java.io.*;
public class test extends JFrame {
private Panel panel1 = new Panel();
private JScrollPane jScrollPane1 = new JScrollPane();
private JLabel jLabel1 = new JLabel();
private GridLayout gridLayout2 = new GridLayout();
private Image image;
private ImageIcon imageicon;
private BufferedImage bimage; public test() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
panel1.setBounds(new Rectangle(127, 43, 555, 600));
panel1.setLayout(gridLayout2);
this.getContentPane().add(panel1, null);
panel1.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jLabel1, null);
this.setSize(700,700);
this.setVisible(true);
mouseMotion mm=new mouseMotion(panel1);
} public static void main(String [] args){
test t=new test();
}
}///////////////////////////////////////////////类mouseMotion
class mouseMotion extends MouseAdapter{
Panel pan;
public mouseMotion(Panel p){
this.pan=p;
p.addMouseListener(this);
} public void mouseClicked(MouseEvent e){
int x=e.getX();
int y=e.getY();
System.out.println(x);
System.out.println(y); }
}
为什么点了图片上什么反应都没有呢???
另外一个类mouseMotion,里面是关于鼠标的事件,点击图片要它响应鼠标该怎么写呢?
///////////////////////////////////////////////类test
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.image.*;
import java.awt.color.*;
import java.util.*;
import java.io.*;
public class test extends JFrame {
private Panel panel1 = new Panel();
private JScrollPane jScrollPane1 = new JScrollPane();
private JLabel jLabel1 = new JLabel();
private GridLayout gridLayout2 = new GridLayout();
private Image image;
private ImageIcon imageicon;
private BufferedImage bimage; public test() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception {
panel1.setBounds(new Rectangle(127, 43, 555, 600));
panel1.setLayout(gridLayout2);
this.getContentPane().add(panel1, null);
panel1.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jLabel1, null);
this.setSize(700,700);
this.setVisible(true);
mouseMotion mm=new mouseMotion(panel1);
} public static void main(String [] args){
test t=new test();
}
}///////////////////////////////////////////////类mouseMotion
class mouseMotion extends MouseAdapter{
Panel pan;
public mouseMotion(Panel p){
this.pan=p;
p.addMouseListener(this);
} public void mouseClicked(MouseEvent e){
int x=e.getX();
int y=e.getY();
System.out.println(x);
System.out.println(y); }
}
为什么点了图片上什么反应都没有呢???
解决方案 »
- JAVA运行 内存不够 程序过于缓慢 有没有办法改善
- IE兼容问题
- 实现接口与继承抽象类有什么区别??
- 关于字符排序的问题??
- 请问 则是什么错误啊?????????????
- 请教高手,关于配置文件读取
- 测试你未来的另一半,超准的
- 有人在Red hat linux7.3下面用过jxl(Java Excel API)吗?我在Windows下面没问题,Linux下面就不行了。
- 谁做过 用java 生成点阵字库的程序?
- 求助 有什么技术可以实现应答技术的回退
- 为什么线程不结束
- 小弟总结的array,vertor,arraylist,hashable,hashmap等几个易混淆的概念,请大家来指正,补充
import javax.swing.*;
import java.awt.event.*;
import java.awt.BorderLayout;
import java.awt.image.*;
import java.awt.color.*;
import java.util.*;
import java.io.*;public class test extends JFrame {
private Panel panel1 = new Panel(); private JScrollPane jScrollPane1 = new JScrollPane(); private JLabel jLabel1 = new JLabel("Label"); private GridLayout gridLayout2 = new GridLayout(); /*
* private Image image; private ImageIcon imageicon; private BufferedImage
* bimage;
*/ public test() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
} private void jbInit() throws Exception {
panel1.setBounds(new Rectangle(127, 43, 555, 600));
panel1.setLayout(gridLayout2);
this.getContentPane().add(panel1, null);
panel1.add(jScrollPane1, null);
jScrollPane1.getViewport().add(jLabel1, null); this.setSize(700, 700);
this.setVisible(true);
// mouseMotion mm = new mouseMotion(panel1);
jLabel1.addMouseListener(new MouseListener(){ public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
int x = e.getX();
int y = e.getY();
System.out.println(x);
System.out.println(y);
} public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub
} public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
} public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
} public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
}});
} public static void main(String[] args) {
test t = new test();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}