Пример #1
0
  /** Allows the user to edit all the parameters of an ABug by typing into the console */
  public void edit() {
    System.out.println("Name: ");
    try {
      name = bufferedReader.readLine();
    } catch (IOException e) {
      e.printStackTrace();
    }

    System.out.println("Energy: ");
    energy = InputHelper.readInteger(bufferedReader);

    System.out.println("Symbol: ");
    try {
      try {
        symbol = bufferedReader.readLine().charAt(0);
      } catch (IOException e) {
        e.printStackTrace();
      }
    } catch (IndexOutOfBoundsException ex) {
    }

    position = new Point();

    System.out.println("X Position: ");
    position.x = InputHelper.readInteger(bufferedReader);

    System.out.println("Y Position: ");
    position.y = InputHelper.readInteger(bufferedReader);

    System.out.println("Sensing Distance: ");
    maxSensingDistance = InputHelper.readInteger(bufferedReader);
  }
Пример #2
0
  protected void calculate() {

    InputHelper helper = new InputHelper();
    String s1 = helper.getInput("Enter a numeric value: ");
    String s2 = helper.getInput("Enter a numeric value: ");
    String op = helper.getInput("Choose an operation (+ - * /):");

    double result = 0;

    try {
      switch (op) {
        case "+":
          result = MathHelper.addValues(s1, s2);
          break;
        case "-":
          result = MathHelper.subtractValues(s1, s2);
          break;
        case "*":
          result = MathHelper.multiplyValues(s1, s2);
          break;
        case "/":
          result = MathHelper.divideValues(s1, s2);
          break;
        default:
          System.out.println("Unrecognized operation!");
          return;
      }

      System.out.println("The answer is " + result);

    } catch (Exception e) {
      System.out.println("Number formatting exception " + e.getMessage());
    }
  }
Пример #3
0
  private void createProperty() {
    sqlProp = new SqlProperty();

    InputHelper helper = new InputHelper();

    sqlProp.setDbType(helper.getInput("database (ex.) mysql"));
    sqlProp.setServer(helper.getInput("server name"));
    sqlProp.setDbName(helper.getInput("database name"));
    sqlProp.setUser(helper.getInput("user name"));
    sqlProp.setPassword(helper.getInput("password"));
  }
Пример #4
0
  /** Creates new form Test */
  public Test() {
    initComponents();

    jComboBox1
        .getEditor()
        .getEditorComponent()
        .addKeyListener(
            new KeyAdapter() {
              @Override
              public void keyReleased(KeyEvent evt) {
                String str = jComboBox1.getEditor().getItem().toString();
                if (evt.getKeyCode() >= 65 && evt.getKeyCode() <= 90
                    || evt.getKeyCode() >= 96 && evt.getKeyCode() <= 105
                    || evt.getKeyCode() == 8) {
                  try {
                    jComboBox1.setModel(ItemTable.getList(str));
                    if (jComboBox1.getItemCount() > 0) {
                      jComboBox1.showPopup();
                      if (evt.getKeyCode() != 8) {
                        ((JTextComponent) jComboBox1.getEditor().getEditorComponent())
                            .select(
                                str.length(), jComboBox1.getEditor().getItem().toString().length());
                      } else {
                        jComboBox1.getEditor().setItem(str);
                      }
                    } else {
                      jComboBox1.getEditor().setItem(str);
                    }
                  } catch (SQLException ex) {
                    Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
                  }
                }
              }
            });

    table.setModel(InvoiceItemTable.getInvoiceDetailsToTable(InputHelper.getIntegerInput("999")));
  }