我在同一个模块中有3个类:
我正在尝试使用NetBeans平台查找在MenuJPanel上使用CardLayout在Panels之间切换。由于某种原因,只打印System.out文本,但不显示/切换卡片。以下只是一个简短的代码示例(我在原始代码中正确创建并定义了CardLayout。):
public interface MenuAPI {
public void showPanel1();
public void showPanel2();
}
@ServiceProvider(service = MenuAPI.class)
public class MenuJPanel extends javax.swing.JPanel implements MenuAPI {
private void displayPanel(String s) {
CardLayout cardLayout = (CardLayout) this.getLayout();
cardLayout.show(this, s);
}
@Override
public void showPanel1() {
System.out.println("Panel1");
displayPanel("panel1");
}
@Override
public void showPanel2() {
System.out.println("Panel2");
displayPanel("panel2");
}
}
public class Demo extends javax.swing.JPanel{
//This is just a button with an Event Listener
private void btnShowPanel1ActionPerformed(java.awt.event.ActionEvent evt) {
MenuAPI menuAPI = Lookup.getDefault().lookup(MenuAPI.class);
menuAPI.showPanel1();
}
}