1,如何实现对JLabel鼠标单击事件的监听.我把JLalel放在了JScrollPane中把JScrollPane放在了JPanel中主类继承了JFrame实现了ActionListener接口!
2,在JLabel加载图片的时候自动在原图片上画出16*16的菱形网格!当鼠标单击其中一个网格后在网格上作出标记!各位前辈知道的麻烦告诉一下!!小弟在此先谢谢了!!

解决方案 »

  1.   

    给JLabel 添加鼠标监听
    获得鼠标点击的位置,来判断点击的是那个网格。
      

  2.   

    我就把布局做好了  没做事件处理  你补一下就好了import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;public class TestLabel extends JFrame{
    private JLabel label;
    private JScrollPane scrollPane;
    private JPanel panel;
    private ImageIcon icon;

    public TestLabel(){
    super("Label");

    icon = new ImageIcon("C:/TEMP/47.gif");
    label = new JLabel(icon);
    scrollPane = new JScrollPane();
    panel = new JPanel();

    panel.setLayout(new BorderLayout());
    panel.add(label, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(50,50));

    scrollPane.setLayout(new ScrollPaneLayout());
    scrollPane.getViewport().add(panel);

    setLayout(new BorderLayout());
    add(scrollPane, BorderLayout.CENTER);

    setSize(500, 200);
    setVisible(true);
    }

    public static void main(String args[]){
    new TestLabel();
    }
    }
      

  3.   

    公司不让用QQ,你试下Canvas类,应该可以的