import java.awt.CardLayout;
import java.awt.Color;import javax.swing.JButton;
import javax.swing.JFrame;public class CardLayoutTest
{
public static void main( String[] args )
{
JFrame f = new JFrame();
CardLayout cl = new CardLayout();
f.setTitle( "haowan" );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setLayout( cl );
JButton[] button = new JButton[5];
for( int i = 0; i < button.length; i++ )
{
button[i] = new JButton( "The" + i + "is" );
f.add( button[i], "page" + i );
}
button[0].setBackground( Color.RED );
button[1].setBackground( Color.BLACK );
button[2].setBackground( Color.BLUE );
button[3].setBackground( Color.CYAN );
button[4].setBackground( Color.DARK_GRAY);
f.pack();
f.setVisible( true );
while( true )
{
try
{
Thread.sleep( 2000 );
}
catch( Exception ee )
{
ee.getStackTrace();
}
cl.next( f );
}
}
}
Exception in thread "main" java.lang.IllegalArgumentException: wrong parent for CardLayout
at java.awt.CardLayout.checkLayout(Unknown Source)
at java.awt.CardLayout.next(Unknown Source)
at Swings.CardLayoutTest.main(CardLayoutTest.java:45)
import java.awt.Color;import javax.swing.JButton;
import javax.swing.JFrame;public class CardLayoutTest
{
public static void main( String[] args )
{
JFrame f = new JFrame();
CardLayout cl = new CardLayout();
f.setTitle( "haowan" );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setLayout( cl );
JButton[] button = new JButton[5];
for( int i = 0; i < button.length; i++ )
{
button[i] = new JButton( "The" + i + "is" );
f.add( button[i], "page" + i );
}
button[0].setBackground( Color.RED );
button[1].setBackground( Color.BLACK );
button[2].setBackground( Color.BLUE );
button[3].setBackground( Color.CYAN );
button[4].setBackground( Color.DARK_GRAY);
f.pack();
f.setVisible( true );
while( true )
{
try
{
Thread.sleep( 2000 );
}
catch( Exception ee )
{
ee.getStackTrace();
}
cl.next( f );
}
}
}
Exception in thread "main" java.lang.IllegalArgumentException: wrong parent for CardLayout
at java.awt.CardLayout.checkLayout(Unknown Source)
at java.awt.CardLayout.next(Unknown Source)
at Swings.CardLayoutTest.main(CardLayoutTest.java:45)
解决方案 »
- EL表达式能否判断 对象 a instanceof Class B?
- 高分求教一个怪异的问题 谢谢回答
- 请教gef内添加一个元素的调用流程
- JAVA socket的异常现象
- 接口变量重名问题
- hib 查询结果读取问题。。。
- 一个很菜的问题,高手帮忙~~~
- 如何在class A里控制class B的Component或Layout的状态变化?
- 继承object类的clone方法,为什么要写为super.clone()?
- 各位打印过PDF文档吗?我打印的时候,经常打出乱码来,比如don't就会变成乱码,还有其它非英文字符也会变成乱码,有解决方法吗?
- 请各位高手来看看!!!!在线等!
- 很简单的一个背景问题。。。
你只捕获Thread.sleep可能发生的异常
import java.awt.Color;import javax.swing.JButton;
import javax.swing.JFrame;public class CardLayoutTest { public static void main(String[] args) {
JFrame f = new JFrame();
CardLayout cl = new CardLayout();
f.getContentPane().setLayout(cl);
f.setTitle("haowan");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton[] button = new JButton[5];
for (int i = 0; i < button.length; i++) {
button[i] = new JButton("The" + i + "is");
f.add(button[i], "page" + i);
} button[0].setBackground(Color.RED);
button[1].setBackground(Color.BLACK);
button[2].setBackground(Color.BLUE);
button[3].setBackground(Color.CYAN);
button[4].setBackground(Color.DARK_GRAY); f.pack();
f.setVisible(true);
while (true) {
try {
Thread.sleep(2000);
} catch (Exception ee) {
ee.getStackTrace();
}
cl.next(f.getContentPane());
}
}
}