【发布时间】:2012-12-21 15:22:29
【问题描述】:
我有两个面板并希望它们显示在我的 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);
}}
【问题讨论】: