public GridPanel(final Grid grid) {
        this.grid = grid;
        this.size = new Dimension(grid.width * BLOCK_SIZE, grid.height * BLOCK_SIZE);
        this.addMouseMotionListener(new MouseMotionAdapter() {
            @Override
            public void mouseMoved(MouseEvent e) {
                posX = e.getX() / BLOCK_SIZE;
                posY = e.getY() / BLOCK_SIZE;
            }
        });
        this.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
                if (piece == null) {
                    return;
                }
                if (SwingUtilities.isRightMouseButton(e)) {
                    if (piece != null) piece.rotate(true);
                } else if (SwingUtilities.isMiddleMouseButton(e)) {
                    grid.panic();
                } else if (SwingUtilities.isLeftMouseButton(e) && grid.remove(posX, posY, piece)) {
                    piece = new Piece();
                }
            }
        });
    }