NetBeans中CardLayout自动生成匿名对象,无法引用啊。
这是NetBeans生成的代码: jPanel1.setLayout(new java.awt.CardLayout());
我现在要从一张卡片换到另一张卡片 怎么才能引用这个匿名的CardLayout对象?
------解决方案--------------------------------------------------------
- Java code
JPanel panel = new JPanel(); panel.setLayout(new CardLayout()); LayoutManager manager = panel.getLayout(); if (manager instanceof CardLayout) { CardLayout layout = (CardLayout) manager; layout.show(panel, name); System.out.println("HELlo"); }