I have a JPanel extension called TPanel, which paints the word Tetris on the right hand side of the JFrame. The curr() method returns the current piece that is moving, and is bounded to the left side (x < 400) of the JFrame. Now for some reason when I add them both to the JFrame I can only see the second one I added, so basically it overrides the other one. I have tried the validate method and it doesn’t work.
How do I show them both simultaneously?
Here’s the code:
public Tetris()
{
// frame stuff
super("Tetris");
this.setSize(616,636);
this.setVisible(true);
this.setDefaultCloseOperation(EXIT_O…
// components
occ = new boolean [30][20];
rnd = new Random();
info = new TPanel();
for(int i=0;i<occ.length;i++)
for(int j=0; j< occ[i].length;j++)
occ [i][j] = false;
pieces.add(initPiece());
this.getContentPane().add(info);
this.getContentPane().add(curr());
this.getContentPane().validate();
repaint();
this.addKeyListener(this);
run();
}
BorderLayoutBorderLayoutwith no constraint, it is placed in theCENTER.CENTERposition can only contain one component or container.So as an immediate guess on how to fix the code snippet, try changing:
To:
Or better still: