} public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { TestCardLayout frame = new TestCardLayout(); //createAndShowGUI(); } }); }}
public class TestCardLayout extends JFrame{
private CardLayout layout_ = new CardLayout();
private JPanel panel_;
public TestCardLayout(){
this.setSize(400,400);
panel_ = (JPanel)this.getContentPane();
init();
this.setVisible(true);
}
private void init(){
panel_.setLayout(layout_);
layout_.addLayoutComponent("button1",new JButton("button1"));
layout_.addLayoutComponent("button2",new JButton("button2")); layout_.show(panel_,"button1");
} public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
TestCardLayout frame = new TestCardLayout();
//createAndShowGUI();
}
});
}}