Detect whether FocusEvent of component is lost or gained

I implementing a EventQueue and get notified when AWTEvents are send. I wait till instances of FocusEvent are send to the dispatchEvent methode.

The FocusEvent by itself does not have a methode to ask if the focus of the component is gained or lost. The methode paramString returns a String in which the information is placed, but i dont want to hack or pars the String. A contains call can give me the answer, but the returnes String is no constant, so it could change in the future.

The paramString methode of FocusEvent is like:

 switch(id) {
      case FOCUS_GAINED:
          typeStr = "FOCUS_GAINED";
          break;
      case FOCUS_LOST:
          typeStr = "FOCUS_LOST";
          break;
      default:
          typeStr = "unknown type";
    }
    return typeStr + (temporary ? ",temporary" : ",permanent") +
        ",opposite=" + getOppositeComponent();

Do you know another solution for this issue.

Answers


What's wrong with "evt.getID()"? It returns FOCUS_LOST or FOCUS_GAINED?


Need Your Help

Is the way I free my nodes correct?

c list pointers

So I have a structure like this:

Simple for loop, beginner

java loops for-loop

new to Java as you can tell when you see my question.