当前位置: 代码迷 >> Java相关 >> CardLayout的父对象
  详细解决方案

CardLayout的父对象

热度:292   发布时间:2006-12-11 11:07:55.0
CardLayout的父对象

/*
* @(#) CardLayoutDemo.java
*/

import java.awt.*;

import javax.swing.*;

public class CardLayoutDemo extends JFrame {

private Button button1, button2, button3;

public CardLayoutDemo() {
button1 = new Button("Button1");
button2 = new Button("Button2");
button3 = new Button("Button3");
CardLayout cardLayout = new CardLayout(5, 10);
setLayout(cardLayout);
add(button1, "card1");
add(button2, "card2");
add(button3, "card3");
setSize(400, 300);
cardLayout.show(this, "card1");
setVisible(true);
}

public static void main(String[] args) {
CardLayoutDemo application = new CardLayoutDemo();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}

程序在执行时出现异常:
Exception in thread "main" java.lang.IllegalArgumentException: wrong parent for
CardLayout
at java.awt.CardLayout.checkLayout(CardLayout.java:383)
at java.awt.CardLayout.show(CardLayout.java:505)
at CardLayoutDemo.<init>(CardLayoutDemo.java:23)
at CardLayoutDemo.main(CardLayoutDemo.java:28)

这个程序中cardLayout对象的父对象应该是谁啊?

搜索更多相关的解决方案: CardLayout  对象  

----------------解决方案--------------------------------------------------------
不是setlayout么
----------------解决方案--------------------------------------------------------
仔细看看API吧
----------------解决方案--------------------------------------------------------