2016-07-17 2 views
0

У меня возникла проблема: я не могу сделать любую из созданных кнопок видимой в моем кадре.Имея кошмар, делающий видимый JButton

Я пытаюсь создать рамку с 2 макетами, верхняя часть - это пустой макет, а нижний макет будет иметь три кнопки.

import java.awt.BorderLayout; 
import java.awt.Color; 

import javax.swing.*; 


public class Game_Initiliasation extends JFrame { 

    int Time; 
    int Difficulty; 

    JPanel TopPanel; 
    JPanel BottomPanel; 

    Game_Initiliasation(){ 
     this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
     this.setSize(300, 300); 
     this.setVisible(true); 

     TopPanel = new JPanel(); 
     BottomPanel = new JPanel(); 

     TopPanel.setLayout(new BorderLayout()); 
     add(TopPanel, BorderLayout.CENTER); 
     add(BottomPanel, BorderLayout.SOUTH); 

     JButton Easy = new JButton("Easy"); 
     JButton Medium = new JButton("Medium"); 
     JButton Difficult = new JButton("Difficult"); 

     /*Easy.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
        actionPerformed(evt); 
      } 
     });*/ 

     Easy.setVisible(true); 

     BottomPanel.add(Easy); 
     BottomPanel.add(Medium); 
     BottomPanel.add(Difficult); 
    } 
} 
+1

Я не могу воспроизвести! Я вижу все три кнопки! – Sweeper

ответ

0

this.add(BottomPanel); // Добавьте эту строку, вы сможете увидеть кнопки

import java.awt.BorderLayout; 
import java.awt.Color; 

import javax.swing.*; 


public class Game_Initiliasation extends JFrame { 

int Time; 
int Difficulty; 

JPanel TopPanel; 
JPanel BottomPanel; 

Game_Initiliasation(){ 
    this.setDefaultCloseOperation(EXIT_ON_CLOSE); 
    this.setSize(300, 300); 
    this.setVisible(true); 

    TopPanel = new JPanel(); 
    BottomPanel = new JPanel(); 

    TopPanel.setLayout(new BorderLayout()); 
    add(TopPanel, BorderLayout.CENTER); 
    add(BottomPanel, BorderLayout.SOUTH); 

    JButton Easy = new JButton("Easy"); 
    JButton Medium = new JButton("Medium"); 
    JButton Difficult = new JButton("Difficult"); 

    /*Easy.addActionListener(new java.awt.event.ActionListener() { 
     public void actionPerformed(java.awt.event.ActionEvent evt) { 
       actionPerformed(evt); 
     } 
    });*/ 

    Easy.setVisible(true); 

    BottomPanel.add(Easy); 
    BottomPanel.add(Medium); 
    BottomPanel.add(Difficult); 
    this.add(BottomPanel); // Add this line, you will be able to see the buttons 

} 
} 
Смежные вопросы