I have a class BoardGUI
that extends JFrame
. I have added buttons in a JPanel
. When I try to add the panel into the frame with a mouselistoner on the frame, the buttons (undo and replay) become invisible. When I mouse over the buttons, they become visible.
Here is my code:
public class BoardGUI extends JFrame {
JButton a=new JButton("Undo");
JButton r=new JButton("replay");
JPanel jp=new JPanel();
public BoardGUI() {
// TODO Auto-generated constructor stub
setTitle("Checkers Game");
setSize(645, 700);
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);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
addMouseListener(new MouseListener() {
@Override
public void mouseReleased(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub
repaint();
}
});
}
public void paint(Graphics g)
{
for(int i=0;i<8;i++)
{
for(int j=0;j<8;j++)
{
g.fillRect(i*100, j*100, 100, 100);
}
}
}
}
Can anybody help me to fix this please?