Box*_*iom 0 java user-interface swing jframe
我对Java非常陌生,现在我正在使用GUI。我现在有一个JFrame-让我们称之为它page1-带有一些内容(文本,图像等)。因此,我要做的是创建几个具有不同内容的“页面”,并能够在程序中的这些页面之间进行切换。
所以我的问题是,做到这一点的最佳方法是什么?假设我要创建一个page2具有不同图像和文本的图片,应该怎么做才能做到这一点?
我希望这是可以理解的。我只需要朝正确的方向前进,这样我就知道要深入研究什么。
您可能要使用CardLayout。这是一个如何使用CardLayout的教程
范例:
//Where instance variables are declared:
JPanel cards;
final static String BUTTONPANEL = "Card with JButtons";
final static String TEXTPANEL = "Card with JTextField";
//Where the components controlled by the CardLayout are initialized:
//Create the "cards".
JPanel card1 = new JPanel();
...
JPanel card2 = new JPanel();
...
//Create the panel that contains the "cards".
cards = new JPanel(new CardLayout());
cards.add(card1, BUTTONPANEL);
cards.add(card2, TEXTPANEL);
Run Code Online (Sandbox Code Playgroud)