-2

How does one determine if an EventObject is a MouseEvent an ActionEvent or something else?

Is there a simple way to check the type of an EventObject?

Not a bug
  • 4,286
  • 2
  • 40
  • 80
user1585643
  • 211
  • 1
  • 2
  • 9
  • 1
    How did you reach a situation where you need to check the type of event? If you provided some background to your question, it will probably become apparent where you should have cast the event. – Rainbolt Mar 05 '14 at 18:03
  • possible duplicate of [How to determine an object's class (in Java)?](http://stackoverflow.com/questions/541749/how-to-determine-an-objects-class-in-java) – Rainbolt Mar 05 '14 at 18:09

2 Answers2

1

You can use the instanceof keyword.

public boolean isActionEvent(EventObject o){
   return o instanceof ActionEvent;
}

More info here: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op2.html

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107
1

you can use the instanceof operator.

objectname instanceof EventObjectName

 

Not a bug
  • 4,286
  • 2
  • 40
  • 80
rogue-one
  • 11,259
  • 7
  • 53
  • 75