November 17, 2018
03 | import java.awt.event.*; |
09 | public class ClickMe3 extends JFrame { |
11 | private JButton tombol, btnExit; |
17 | super ( "Event Handling" ); |
21 | Container container = getContentPane(); |
23 | container.setLayout( new FlowLayout()); |
25 | ClickListener cl = new ClickListener (); |
29 | tombol = new JButton ( "Click Me!" ); |
31 | tombol.addActionListener(cl); |
33 | container.add(tombol); |
37 | btnExit = new JButton ( "Exit" ); |
39 | btnExit.addActionListener(cl); |
41 | container.add(btnExit); |
53 | public static void main (String arg[]) { |
55 | ClickMe3 test = new ClickMe3(); |
57 | test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
65 | private class ClickListener implements ActionListener { |
67 | public void actionPerformed (ActionEvent e) { |
69 | if (e.getSource() == tombol) { |
71 | JOptionPane.showMessageDialog( null , "You click me again, guys !!!" ); |
73 | } else if (e.getSource() == btnExit){ |
75 | if ( JOptionPane.showConfirmDialog( null , "Apakah Anda yakin akan keluar ?" , "Konfirmasi" , |
77 | JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE) == JOptionPane.OK_OPTION) { |
Semoga Bermanfaat....
0 komentar:
Post a Comment