Like implying Mouselisteners on a Gridlayout?

Asked

Viewed 14 times

0

I created a GUI for a Board of a game with an 8x8 Gridlayout. In this Grid I need to have a mouse Listener in each of the containers. How do I get that? I’ve tried many ways and I’m not getting it.

Code:

    public static void createAndShowGUI() {
        GridLayout gl_Board = new GridLayout(0, 1, 5, 5);
        board = new Board();
        JPanel Board = new JPanel(gl_Board);
        Board.add(board);
        board.setLayout(new GridLayout(8, 8, 2, 2));
        Board.setBounds(10, 25, 708, 423);
        frame.getContentPane().add(Board);


1 answer

0

Hello

Create a button and add a Switch to it

For example

JButton button = new JButton();
        button.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                System.out.println("cliquei no botao");

            }
        });
  • Don’t forget to add the knob to the panel

Browser other questions tagged

You are not signed in. Login or sign up in order to post.