2
我想加載一個擴展JPanel的類,並且有另一個類的組件,這個組件也將JPanel擴展到另一個類中。 加載包含另一個JPanel的JPanel
而這正是我需要實現: 例
First.java
public class First extends JPanel{
JPanel cont = new JPanel();
public First(){
cont.setBackground(Color.YELLOW);
}
}
例Second.java
public class Second extends JPanel{
JPanel cont = new JPanel();
First first_panel = new First();
public Second(){
cont.setBackground(Color.RED);
cont.add(first_panel);
}
}
例Container.java
public class Container extends JFrame{
JFrame frame = new JFrame();
JPanel cont = new JPanel();
Second second_panel = new Second();
public Container(){
cont.setBackground(Color.GREEN);
cont.add(second_panel);
frame.add(cont);
frame.setVisible(true);
}
}
我能夠加載一個接一個班,但是當我試圖加載包含另一個panel.class面板圖形用戶界面不顯示它。邏輯有什麼問題?有什麼問題?
爲了更好地幫助越早,張貼[MCVE](http://stackoverflow.com/help/mcve)(最小完備可驗證實施例)或[SSCCE](HTTP:// WWW .sscce.org /)(簡短,獨立,正確的例子)。 –