对于 Java GUI 作业额外的功劳,我正在尝试将几个面板添加到 JTabbedPane。实际上,它们是 JFrame,但我只是更改为扩展 JPanel 而不是 JFrame,并删除了 main()。无论如何,当我运行 main() 时,JTabbedPane 和两个面板都出现了,但是是分开的。我错过了什么?
import javax.swing.*;
public class TabbedPane extends JFrame
{
JPanel DayGui = new JPanel();
JPanel OfficeAreaCalculator = new JPanel();
JLabel firstLabel = new JLabel("First tabbed pane");
JLabel secondLabel = new JLabel("Second tabbed pane");
JTabbedPane tabbedPane = new JTabbedPane();
// constructor
public TabbedPane()
{
DayGui.add(firstLabel);
OfficeAreaCalculator.add(secondLabel);
tabbedPane.add("First Panel", DayGui);
tabbedPane.add("Second Panel", OfficeAreaCalculator);
add(tabbedPane);
}
public static void main(String[] args)
{
TabbedPane tab = new TabbedPane();
tab.pack();
tab.setVisible(true);
JTabbedPane DayGui = new JTabbedPane();
JTabbedPane OfficeAreaCalculator = new JTabbedPane();
DayGui dg = new DayGui();
OfficeAreaCalculator oac = new OfficeAreaCalculator();
}
}