Class UDCIPAddressField

All Implemented Interfaces:
FocusListener, KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class UDCIPAddressField extends JPanel implements KeyListener, FocusListener
A Component which allows for the entry of an IP address. It consists of a panel containing 4 JTextFields. Each textfield will only accept numeric values between 0 and 255. Focus will automatically shift to the next field when it can be determined that the user has entered a valid value for that field.
See Also:
  • Constructor Details

    • UDCIPAddressField

      public UDCIPAddressField()
      Initializes component with an IP Address of 0.0.0.0
    • UDCIPAddressField

      public UDCIPAddressField(String ip)
      Initializes component with an IP Address of 0.0.0.0
    • UDCIPAddressField

      public UDCIPAddressField(String ip, int columns)
    • UDCIPAddressField

      public UDCIPAddressField(int columns)
  • Method Details

    • getText

      public String getText()
      Returns the contents of the text fields as an IP Address using dot-notation, Example : 127.0.0.1
    • setText

      public void setText(String s)
      Parses the given String as an IP Address and puts the bytes in the appropriate text fields. Partial IP addresses may be specified, such as "121.33" or "...100"
    • getByteValue

      public int getByteValue(int pos)
      Returns the value of the byte in the given position(1-4).
      Returns:
      If pos is out of range, -1 will be returned.
    • setByteValue

      public void setByteValue(int pos, int value)
      Sets the value of the byte in the given position(1-4). If pos is out of range, nothing is done.
    • setEnabled

      public void setEnabled(boolean b)
      Overrides:
      setEnabled in class JComponent
    • setEditable

      public void setEditable(boolean b)
    • focusGained

      public void focusGained(FocusEvent e)
      Called when one of the text fields gains focus. All text is selected so the user can just overwrite the present value quickly.
      Specified by:
      focusGained in interface FocusListener
    • focusLost

      public void focusLost(FocusEvent e)
      Called when one of the text fields loses focus. If the field is left blank, the contents will be replaced with "0".
      Specified by:
      focusLost in interface FocusListener
    • keyTyped

      public void keyTyped(KeyEvent e)
      Specified by:
      keyTyped in interface KeyListener
    • keyPressed

      public void keyPressed(KeyEvent e)
      Specified by:
      keyPressed in interface KeyListener
    • setColumns

      public void setColumns(int i)
      Set the column width of the editable text fields.
    • keyReleased

      public void keyReleased(KeyEvent e)
      Determines whether focus should leave the current text field.
      Specified by:
      keyReleased in interface KeyListener