【发布时间】:2014-05-02 20:29:17
【问题描述】:
我一直在寻找,没有什么对我来说足够简单。但是对于我正在做的事情,我想在我的主要方法中制作一个 JFrame,并为每个 JPanel 使用不同的类文件。 (这是为了保持信息分离和清洁)。 如果我用这种方法切换 JPanel 的最佳方法是什么?
public class Main extends JFrame {
public Main(){
JFrame intro = new JFrame("FormProgram");
intro.setSize(800,600);
intro.setVisible(true);
intro.setResizable(false);
setDefaultCloseOperation(EXIT_ON_CLOSE);
intro.setLocationRelativeTo(null);
}
public static void main(String[] args) {
new Main();
}
那我的基础二班是这样的。
public class Page1 extends JFrame implements ActionListener{
public JLabel test;
public void Page1(){
Container cp = intro.getContentPane();
cp.setLayout(null);
this.test = new JLabel("welcome");
this.test.setBounds(5,5,300,300);
cp.add(test);
}
【问题讨论】: