我正在处理一项 Java 任务,并且我创建了一个 JFrame 小程序,该小程序具有在单独的类中创建的四个面板,这些面板返回到主类并添加到主面板中。我面临的问题是我的南面板中有一个组合框。根据该组合框中的选择,我希望根据该选择更新一个或多个其他面板。我不知道如何做到这一点,我已经研究过重新粉刷那个面板,甚至重新创建整个主面板。任何帮助和/或建议将不胜感激。
我已经从初学者的主面板类中发布了下面的代码。
我是第一次在这里发帖,所以如果没有足够的细节或者我遗漏了一些东西,请告诉我。
public class Main_GUI_Panel extends JFrame {
public static Panel_North northPanel;
public static Panel_Center centerPanel;
public static Panel_West westPanel;
public static Panel_South southPanel;
private int index = -1;
public Main_GUI_Panel() {
super("Java 2: Final Project");
getContentPane().setBackground(Color.BLACK); //set the applet background color
setLayout(new BorderLayout()); //set the Layout for the applet
//START - call methods to create & set panels
northPanel = new Panel_North();
westPanel = new Panel_West();
centerPanel = new Panel_Center();
southPanel = new Panel_South();
add(northPanel.setNorth(),BorderLayout.NORTH); //set the North portion of the applet
add(westPanel.setWest(index),BorderLayout.WEST); //set the West portion of the applet
add(centerPanel.setCenter(),BorderLayout.CENTER); //set the Center portion of the applet
add(southPanel.setSouth(),BorderLayout.SOUTH); //set the South portion of the applet
//END - call methods to set panels
}