我有两个面板,希望它们显示在我的 JFrame 中,但是当我这样尝试时,我只能看到第二个。有人可以帮帮我吗?:(
import javax.swing.JFrame;
public class MainWindow {
CardLayout layout;
JFrame frame;
Player panel1;
Block panel2;
public MainWindow() {
frame = new JFrame("Rechteck");
panel1 = new Player();
panel2 = new Block();
panel1.addKeyListener(new KeyListen(panel1));
frame.add(panel1);
frame.add(panel2);
frame.setSize(500,500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}}