JButton仅在重启后鼠标结束时出现,为什么?

时间:2015-10-24 08:24:33

标签: java swing user-interface jbutton

所以当我点击原始扫雷中的笑容时,我想重新启动游戏。它真正产生了一个新的游戏,但只有在鼠标悬停在图片上时才会出现按钮。为什么呢?

_

我的JFrame重启方法:

    initConsole(_width,_height,_mineNum);   //Creating the game arrays
    remove(fieldPanel);               //Removing the already added panels
    remove(smilePanel);
    remove(borderDrawer);
    fieldPanel = new JPanel();       //Now creating new panels
    smilePanel = new JPanel();
    startTime = System.currentTimeMillis();
    _buttons = new FieldButton[_height][_width];  //Creating an array for the buttons

    int fieldSizeWidth = (_width)*20;
    int fieldSizeHeight = (_height)*20; // Magic size
    fieldPanel.setSize(fieldSizeWidth,fieldSizeHeight);
    fieldPanel.setLocation(15, 70);
    fieldPanel.setLayout(new GridLayout(9,9));
    int fullWindowWidth = fieldSizeWidth+50;
    int fullWindowHeight = fieldSizeHeight+200;
    setSize(fullWindowWidth,fullWindowHeight);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    RestartButton restartButton = new RestartButton(this);
    smilePanel.setSize(34,34);                  // Ha ezt nem irom ide akkor megse jelenik a kep
    smilePanel.add(restartButton);
    smilePanel.setLayout(new GridLayout(1,1));  // Ha ezt nem irom ide akkor egy magikus keretet hoz letre a gomb korul WTF?
    smilePanel.setLocation((int)fullWindowWidth/2-(34/2),20);


    for(int i = 0; i < _height; i++)
    {
        for(int j = 0; j < _width ; j++)
        {
            _buttons[i][j] = new FieldButton(_hidden[i][j],i,j,this);
            fieldPanel.add(_buttons[i][j]);
        }
    }

    add(fieldPanel);
    add(smilePanel);
    borderDrawer = new BorderDrawer(); 
    add(borderDrawer);

    setVisible(true);

按钮:

我的按钮的构造函数:

    this.addMouseListener(this);
    _hidden = new ImageIcon(this.getClass().getResource("hidden.png"));
    setIcon(_hidden);
    setVisible(true);
    setBorderPainted(false);
    setFocusPainted(false);
    setContentAreaFilled(false);

0 个答案:

没有答案