Contoh Program click event handler :D Cekidoot ! Semoga Bermanfaat ^^
Pada contoh berikut ini ditambahkan window konfirmasi saat tombol exit ditekan.
Berikut ini tampilannya:
 
Contoh program:
 
| 03 | importjava.awt.event.*; | 
| 07 | publicclassClickMe3 extendsJFrame { | 
| 09 |     privateJButton tombol, btnExit; | 
| 13 |         super("Event Handling"); | 
| 15 |         Container container = getContentPane(); | 
| 17 |         container.setLayout(newFlowLayout()); | 
| 19 |         ClickListener cl = newClickListener (); | 
| 21 |         tombol = newJButton ("Click Me!"); | 
| 23 |         tombol.addActionListener(cl); | 
| 25 |         container.add(tombol); | 
| 27 |         btnExit = newJButton ("Exit"); | 
| 29 |         btnExit.addActionListener(cl); | 
| 31 |         container.add(btnExit); | 
| 39 |     publicstaticvoidmain (String arg[]) { | 
| 41 |         ClickMe3 test = newClickMe3(); | 
| 43 |         test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | 
| 49 |     privateclassClickListener implementsActionListener { | 
| 51 |         publicvoidactionPerformed (ActionEvent e) { | 
| 53 |             if(e.getSource() == tombol) { | 
| 55 |                 JOptionPane.showMessageDialog(null, "You click me again, guys !!!"); | 
| 57 |             } elseif(e.getSource() == btnExit){ | 
| 59 |                 if( JOptionPane.showConfirmDialog(null, "Apakah Anda yakin akan keluar ?","Konfirmasi", | 
| 61 |                         JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) { | 
Sumber :http://contohprogram.info/java/contoh-program-event-handling-di-java-3.html