예제 #1
0
 private JComboBox createComboBox() {
   final JComboBox comboBox = new JComboBox();
   for (Currency item : CurrencySet.getInstance()) comboBox.addItem(item);
   currency = CurrencySet.getInstance().iterator().next();
   comboBox.addActionListener(
       new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
           currency = (Currency) comboBox.getSelectedItem();
         }
       });
   return comboBox;
 }
  public void execute() {
    while (true) {
      try {
        System.out.println("Introduce la divisa");
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line = reader.readLine();
        Currency[] currencies = CurrencySet.getInstance().search(line);
        if (currencies.length == 1) {
          currency = currencies[0];
          break;
        }
        if (currencies.length == 0) {
          System.out.println("No se ha encontrado divisas");
        }
        if (currencies.length > 1) {}

      } catch (IOException ex) {
        System.out.println("Por favor introduzca un valor correcto");
      }
    }
  }