免责声明,这是我坚持的作业练习。请指向正确的方向。使用AWT面板的静态嵌套类下拉列表
我遇到了我的嵌套类的问题。我基本上必须创建一个嵌套的静态类,通过java.AWT Panel生成一个下拉列表。
下面是代码:(轻微的更新我的代码......仍然困惑寿“)
package ui.panels;
import interfaces.Resettable;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import shapes.Shape;
import model.Model;
public class MainPanel extends Panel implements Resettable{
ActionPanel actionPanel;
ControlsPanel controlsPanel;
private ColorPanel colorPanel;
private void init() {
colorPanel = new ColorPanel();
}
public MainPanel(Model model) {
actionPanel = new ActionPanel(model);
controlsPanel = new ControlsPanel(model);
setLayout(new GridLayout(2,1));
add(controlsPanel);
add(actionPanel);
}
public void resetComponents() {
controlsPanel.resetComponents();
actionPanel.resetComponents();
}
public static class ColorPanel {
public final static String BLACK = "Black";
public final static String BLUE = "Blue";
public final static String GREEN = "Green";
public final static String RED = "Red";
public final static String YELLOW = "Yellow";
public final static String Magenta = "Magenta";
private static String[] color_selections = {"Black","Blue","Green","Red","Yellow","Magenta"};
String msg = "";
// now create list panel
public ColorPanel(){
Choice myChoice = new Choice();
for (String msg : color_selections) {
myChoice.add(msg);
}
myChoice.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
//do something here when item is selected
}
});
this.add(myChoice); //here is my problem. I don't know what this should say
}
}
}
“有问题”。要求描述问题是否太多? – meriton 2011-02-07 19:08:00