gpt4 book ai didi

java - JComboBox 不允许我用数组启动它

转载 作者:行者123 更新时间:2023-12-02 08:22:06 26 4
gpt4 key购买 nike

import java.awt.event.*;
import javax.swing.*;
public class PlannerMain {
JFrame frame;
JButton makeMap;
JPanel panel;
JLabel outcome;
JComboBox listOfWindTurbines;
int[] windTurbineSpace = new int[10];
JTextField lengthOfRoom, widthOfRoom, widthObjectNeeds, lengthObjectNeeds;
int lengthOfRoomInt, widthOfRoomInt, widthObjectNeedsInt, lengthObjectNeedsInt, largerObjectMeasurement, numberOfItems, numberOfItemsShort;
public static void main(String[] args){
PlannerMain p = new PlannerMain();

}

public PlannerMain(){

windTurbineSpace[0] = 1;
frame = new JFrame("Minecraft Land Planner");
outcome = new JLabel();
panel = new JPanel();
makeMap = new JButton("Make Map");
lengthOfRoom = new JTextField("Length of Room");
widthOfRoom = new JTextField("Width of Room");
widthObjectNeeds = new JTextField("Width Object Needs");
lengthObjectNeeds = new JTextField("Length Object Needs");
listOfWindTurbines = new JComboBox(windTurbineSpace);
makeMap.addActionListener(new makeMapListener());
frame.setSize(580,550);
frame.add(panel);
panel.add(makeMap);
panel.add(lengthOfRoom);
panel.add(widthOfRoom);
panel.add(lengthObjectNeeds);
panel.add(widthObjectNeeds);
panel.add(listOfWindTurbines);
panel.add(outcome);
frame.setVisible(true);


}

class makeMapListener implements ActionListener{

public void actionPerformed(ActionEvent e) {

lengthOfRoomInt = Integer.parseInt(lengthOfRoom.getText());
widthOfRoomInt = Integer.parseInt(widthOfRoom.getText());
lengthObjectNeedsInt = Integer.parseInt(lengthObjectNeeds.getText());
widthObjectNeedsInt = Integer.parseInt(widthObjectNeeds.getText());
if(lengthObjectNeedsInt<=widthObjectNeedsInt){

largerObjectMeasurement = widthObjectNeedsInt;

}
if(widthObjectNeedsInt<=lengthObjectNeedsInt){
largerObjectMeasurement = lengthObjectNeedsInt;

}
numberOfItems = (lengthOfRoomInt/lengthObjectNeedsInt)*(widthOfRoomInt/widthObjectNeedsInt);
outcome.setText(String.valueOf(numberOfItems));
lengthOfRoom.setSize(30, 20);
widthOfRoom.setSize(30, 20);
widthObjectNeeds.setSize(30, 10);
lengthObjectNeeds.setSize(100, 20);

}

}
}

它在第 28 行给了我这个错误。

最佳答案

使用包装类,

Integer[] windTurbineSpace = new Integer[10];

关于java - JComboBox 不允许我用数组启动它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5286786/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com