我想将人/公司添加到一种车辆。关键是在个人或公司之间做出选择,然后继续输入有关他们的详细信息。然后继续选择它是哪种类型的车辆,然后选择更多细节。我不知道我必须做什么才能让程序正常运行,我希望有人能帮助我。
private void addVehicle() {
System.out.println("Add Vehicle");
String[] options = {"Private person", "Firm"};
String[] vehicle = {"Car", "Truck", "MC"};
String[] personDetails = {"Firstname: ","Lastname: ","Date of Birth: ",
"Address: ","Phone Number: "};
int chooseOwnerType = JOptionPane.showOptionDialog(this, "Private person/firm",
"Choose an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, "");
int chooseVehicleType = JOptionPane.showOptionDialog(this, "What kind of vehicle is it?",
"Choose an option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, vehicle, "");
int numPairs = personDetails.length;
if(chooseOwnerType == 0) {
JPanel p = new JPanel(new SpringLayout());
for (int i = 0; i < numPairs; i++) {
JLabel l = new JLabel(personDetails[i], JLabel.TRAILING);
p.add(l);
JTextField textField = new JTextField(10);
l.setLabelFor(textField);
p.add(textField);
}
}
if(chooseOwnerType == 1) {
}