我有一堆 JComboBox 已放入 JPanel 中,但 JComboBox 在被点击之前是不可见的。有没有人知道我可能做错了什么,初始化代码如下所示:
public class DelegateUI extends JFrame implements Observer, ActionListener{
public static int vertexPoints[][]= {
{586, 584}, {586, 754}, {83, 754}, {83, 582}, // 1 - 4
{414, 246}, {340, 514}, {479, 514}, // 5 - 8
{618, 108}, {700, 203}, {493, 336}, {492, 126}, // 9 - 11
{935, 123}, {937, 470}, {729, 473}, {730, 125}, // 12 - 15
{772, 557}, {656, 672}, {608, 410},
{1042, 120}, {1104, 179}, {1071, 508}, {967, 169} // 19 - 22
};
private Model model;
private JPanel topPanel;
private JComboBox searchType;
private JComboBox startVertex;
private JComboBox goalVertex;
Object [] searchTypes = { "Breadth First", "Uniform Cost", "Greedy Best First", "A*"};
Object [] vertexNumbers = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15",
"16", "17", "18", "19", "20", "21", "22"};
public DelegateUI(Model m){
this.model = m;
m.addObserver(this);
setSize(1200, 1000);
topPanel = new JPanel();
topPanel.setBackground(Color.BLACK);
searchType = new JComboBox(searchTypes);
startVertex = new JComboBox(vertexNumbers);
goalVertex = new JComboBox(vertexNumbers);
searchType.setSelectedIndex(0);
searchType.addActionListener(this);
startVertex.setSelectedIndex(3);
startVertex.addActionListener(this);
startVertex.setActionCommand("start");
goalVertex.setSelectedIndex(19);
goalVertex.addActionListener(this);
goalVertex.setActionCommand("goal");
topPanel.add(searchType);
topPanel.add(startVertex);
topPanel.add(goalVertex);
this.setLayout(new BorderLayout());
this.add(topPanel, BorderLayout.NORTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}