خرید بک لینک

Vote count: 0

I created a class that extends JPanel called GamePane which on creation it sets the layout to a GridLayout and then adds buttons one at a time:

public class GamePane extends JPanel
{
private JButton[][] buttons;
private final int sizeX, sizeY;
private Partida partida;

public GamePane(int sizeX, int sizeY, Partida p)
{
    super();
    this.sizeX = sizeX;
    this.sizeY = sizeY;
    this.partida = p;
    this.setLayout(new GridLayout(sizeX + 1, sizeY + 1));
    buttons = new JButton[sizeX + 1][sizeY + 1];
    for (int y = 0; y < sizeY + 1; y++)
    {
        for (int x = 0; x < sizeX + 1; x++)
        {
            JButton button = new JButton();
            button.addActionListener(new ListenerGameButton(x, y, this));
            this.add(button);
            button.setBackground(Color.yellow);
            button.setVisible(true);
            buttons[x][y] = button;
        }
}

The panel initialization is done on the parent JDialog:

gamePane = new GamePane(sizeX, sizeY, parentPartida);

And here's how it looks on the netbeans editor: (Being the selected frame a instance of GamePane) enter image description here

Then when testing it out it doesn't show the buttons: enter image description here

So, what am I doing wrong? Thanks in advance!

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: سه شنبه 1 تير 1395 ساعت: 0:01

صفحه بندی