小编use*_*545的帖子

用于JPanel的addMouseListener

今天我有一个问题..我的程序制作一个8x8网格,当我点击一个时显示coord JButton.

但我拒绝使用JButton,我需要去JPanel...但我addMouseListener 的工作没有,所以我不知道怎么可能解决我4小时后正在搜索的问题.....

    package coordboutons;

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;

    public class CoordBoutons extends JFrame {

        CoordBoutons() {
            super("GridLayout");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            Container contenant = getContentPane();
            contenant.setLayout(new GridLayout(8, 8));

            for (int i = 0; i < 8; i++) 
                for (int j = 0; j < 8; j++)
                    contenant.add(new CaseEchiquier(i, j));

            pack();
            setVisible(true);
        }

        **class CaseEchiquier extends JPanel** {
            private int lin, col;
            CaseEchiquier(int i, int j) {
                lin = i;
                col = j;
                setPreferredSize(new …
Run Code Online (Sandbox Code Playgroud)

java swing awt jpanel mouselistener

8
推荐指数
2
解决办法
6万
查看次数

标签 统计

awt ×1

java ×1

jpanel ×1

mouselistener ×1

swing ×1