コード例 #1
0
 private Payment getPayment() {
   User user = (User) this.comboBox_user.getSelectedItem();
   return new Payment(
       new Timestamp(
           DateUtil.getDateByDateTimeString(this.textField_paymentdatetime.getText()).getTime()),
       Double.parseDouble(this.textField_paymentamount.getText()),
       user.getId(),
       this.comboBox_paymentType.getSelectedItem().toString());
 }
コード例 #2
0
  /**
   * 重写User的toString()和equals()方法,然后才能向comboBox里添加
   *
   * @param source
   * @return
   */
  private User makeUser(final User source) {
    User user =
        new User() {

          public String toString() {
            return source.getUser_name();
          }

          public boolean equals(Object obj) {
            if (obj instanceof User) {
              User u = (User) obj;
              if (getId() == u.getId()) return true;
            }
            return false;
          }
        };
    user.setId(source.getId());
    return user;
  }