+ 1
I am having a problem to understand that which listener should i use with which component in java (G.U.I)
2 Réponses
+ 2
You can use as many listeners as you want and it depends on what events you want to listen for. It doesn't matter so much what kind of swing class you're listening on events from.
Want to listen for things like clicks, the most obvious actionable event? Use ActionListener.
Want to listen for basic mouse events? Use MouseListener.
Want to listen for mouse movement or drag events? Use MouseMotionListener.
Want to listen for keyboard events? Use KeyListener.
I more often use ActionListener than the others because clicking is the action event for buttons. Clicking a menu item calls actionPerformed. The main event I most often want to listen for is the action event.
0
Please put Java GUI in the tags rather than number 1 ☝