コード例 #1
0
 /**
  * Constructor.
  *
  * @param value the value to edit.
  * @throws TagFormatException if the tag value cannot be retrieved with the expected type.
  */
 public RationalTagValueComponent(TagValue value) throws TagFormatException {
   super(new FlowLayout(FlowLayout.LEFT, 0, 0));
   m_value = value;
   Rational rational = m_value.getAsRational();
   m_numer = new JTextField("" + rational.numerator, 5);
   m_divider = new JLabel("/");
   m_denom = new JTextField("" + rational.denominator, 5);
   add(m_numer);
   add(m_divider);
   add(m_denom);
 }
コード例 #2
0
 /**
  * Returns the editted value.
  *
  * @return the editted value.
  * @throws TagFormatException if the tag value cannot be retrieved with the expected type.
  */
 public TagValue getTagValue() throws TagFormatException {
   try {
     long numer = Long.parseLong(m_numer.getText());
     long denom = Long.parseLong(m_denom.getText());
     Rational rational = new Rational(numer, denom);
     return new TagValue(m_value.getTag(), rational);
   } catch (NumberFormatException e) {
     e.printStackTrace();
     throw new TagFormatException(
         m_numer.getText() + "/" + m_denom.getText() + " is not a valid rational");
   }
 }