I am adding both a JLabel
and my own Panels
class to a JFrame
. The Panels
class I made inherits from JPanel
, by the way.
My code only shows one of the two components, the JLabel
or the JPanel
inherited class. When I add a setLayout()
line, the JLabel
shows and when I don't the JPanel
inherited class shows. What's up with that?
public class TetisFrame extends JFrame{
private final static int FRAME_WIDTH = 400;
private final static int FRAME_HEIGHT = 720;
private static Panels panels;
public TetisFrame(){
setTitle("Tetis");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(FRAME_WIDTH + 200, FRAME_HEIGHT + 50);
setResizable(false);
setLocationRelativeTo(null);
JLabel points = new JLabel("Score: ");
points.setBounds(450, 360, 100, 30);
add(points);
panels=new Panels();
add(panels);
addKeyListener(panels);
setLayout(null);
setVisible(true);
}
public static void main(String[] args) {
new TetisFrame();
}
}