时间:2011-04-18 12:29:13

标签: java input joptionpane

目前我必须手动将项目添加到我的阵列,但我想让用户自己也可以通过JOptionPanes这样做,最好的方法是什么?这是我目前的代码。

public class Main {
  public static void main(String[] args){

  //Create new Person objects

 Address p[] = new Address[3];
 p[0] = new Address("27","Abbey View","Hexham","NE46 1EQ");
 p[1] = new Address("15", "Chirdon Crescent", "Hexham", "NE46 1LE");
 p[2] = new Address("6", "Causey Brae", "Hexham", "NE46 1DB");
 Details c[] = new Details[3];
 c[0] = new Details ("3", "175,000", "Terraced");
 c[1] = new Details  ("6", "300,000", "Bungalow");
 c[2] = new Details ("4", "250,000", "Detached");

  //Send some messages to the  objects
  c[0].setBeds("3 ");
  c[1].setBeds("6");
  c[2].setBeds("4");
  c[0].setPrice("175,000");
  c[1].setPrice("300,000");
  c[2].setPrice("250,000");
  c[0].setType("Terraced");
  c[1].setType("Bungalow");
  c[2].setType("Detached");


  //Set up the association
  p[0].ownsDetails(c[0]);
  p[1].ownsDetails(c[1]);
  p[2].ownsDetails(c[2]);

  //print details
  p[1].printDetails();
  p[2].printDetails();
  p[3].printDetails();


}
  System.exit(0);
}
}

1 个答案:

答案 0 :(得分:2)

您可以在JOptionPane上使用showXXXX方法,并像在控制台上一样提示用户。

但是,我建议只创建一个简单的JFrame,该控件允许用户输入多个项目而不是一个接一个地显示一个对话框。