I have a class named BoardGUI
extended from JFrame
, in a constructor I have made a JPanel
with two buttons in it. I have added this panel into my frame. Whenever I run this program, buttons get invisible. As I bring my mouse cursor over the buttons they get visible. Code is as follows:
public class BoardGUI extends JFrame {
Play pieces;
JButton a=new JButton("Undo");
JButton r=new JButton("replay");
JPanel jp=new JPanel();
public BoardGUI() {
pieces = new Play();
setTitle("Checkers Game");
setSize(645, 700);
setVisible(true);
jp.setLayout(new FlowLayout());
jp.setPreferredSize(new Dimension(645,35));
a.setVisible(true);
r.setVisible(true);
jp.add(a);
jp.add(r);
add(jp,BorderLayout.SOUTH);
I am also using repaint method in my program. Can anybody point out my mistake and suggest any solution for this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…