Friday, May 9, 2014

Button Listener (PART 1)

For this time i will share about available listener for javax.swing.JButton /  java.awt.Button..
In button, u have two option, either :

  • ActionListener, Or
  • MouseListener



Action Listener

  • only have actionPerformed(java.awt.ActionEvent e) function, will perform the action when the button is pressed and released


Mouse Listener
It have five function,

  1. mouseExited(java.awt.MouseEvent e) : will invoke when the mouse is exited the button
  2. mouseEntered(java.awt.MouseEvent e) : will invoke when the mouse is entered the button
  3. mouseReleased(java.awt.MouseEvent e) : will invoke when the mouse is released  the button
  4. mousePressed(java.awt.MouseEvent e) : will invoke when the mouse is pressed the button
  5. mouseClicked(java.awt.MouseEvent e) : will invoke when the mouse is pressed and released the button
Okay, enough for the introduction, here the sample code for the button listener :

MainPanel.java




MainFrame.java


Sample Running :












you can test it by your self..
i hope you like this souce code...
and please give some comment....
                                                                                                                                                      Created By : Z-man, 2014

No comments:

Post a Comment