Example #1
0
  public void paint(Graphics g) {
    // chose Font with selected value
    f =
        new Font(
            lFont.getSelectedItem(),
            lStyle.getSelectedIndex(),
            Integer.parseInt(lSize.getSelectedItem()));

    // Clear Background
    g.setColor(Color.white);
    g.fillRect(0, 85, 400, 200);
    g.setColor(Color.black);

    if (f != null) {
      g.setFont(f);
    }

    g.drawString(sString.getText(), 20, 120);

    // Get Unicode char format FFFF in textfield sChar
    String s = sChar.getText();
    char c;
    try {
      c = (char) Integer.parseInt(s, 16);
      if (Character.isDefined(c)) g.drawString("char \\u" + s + " is " + c, 20, 180);
      else g.drawString("char \\u" + s + " not exist", 20, 180);
    } catch (Exception e) { // Can parse this string
      g.drawString("" + e, 20, 180);
    }
  }
Example #2
0
  public void keyPressed(int key, char c) {
    if (textInput) {
      if (key == Input.KEY_BACK) {
        if (worldName.length() > 0) {
          worldName = worldName.substring(0, worldName.length() - 1);
        }
      } else {
        if (worldName.length() < 15) {

          if (Character.isDefined(c))
            if (Character.isLetter(c) || Character.isDigit(c) || Character.isSpaceChar(c)) {
              worldName += c;
            }
        }
      }
    }
  }