Contoh Program Event Handling di Java
STUDI FORUM :: PEMROGRAMAN :: JAVA
Halaman 1 dari 1
Contoh Program Event Handling di Java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ClickMe2 extends JFrame {
Selamat mencoba, semoga bermanfaat
import java.awt.event.*;
import javax.swing.*;
public class ClickMe2 extends JFrame {
08 |
09 | private JButton tombol, btnExit; |
10 |
11 | public ClickMe2() { |
12 |
13 | super ("Event Handling"); |
14 |
15 | Container container = getContentPane(); |
16 |
17 | container.setLayout(new FlowLayout()); |
18 |
19 | ClickListener cl = new ClickListener (); |
20 |
21 | tombol = new JButton ("Click Me!"); |
22 |
23 | tombol.addActionListener(cl); |
24 |
25 | container.add(tombol); |
26 |
27 | btnExit = new JButton ("Exit"); |
28 |
29 | btnExit.addActionListener(cl); |
30 |
31 | container.add(btnExit); |
32 |
33 | setSize (200,100); |
34 |
35 | setVisible (true); |
36 |
37 | } |
38 |
39 | public static void main (String arg[]) { |
40 |
41 | ClickMe2 test = new ClickMe2(); |
42 |
43 | test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
44 |
45 | } |
46 |
47 | //inner class |
48 |
49 | private class ClickListener implements ActionListener { |
50 |
51 | public void actionPerformed (ActionEvent e) { |
52 |
53 | if (e.getSource() == tombol) { |
54 |
55 | JOptionPane.showMessageDialog(null, "You click me again, guys !!!"); |
56 |
57 | } else if (e.getSource() == btnExit){ |
58 |
59 | JOptionPane.showMessageDialog(null, "See you, guys !"); |
60 |
61 | System.exit(0); |
62 |
63 | } |
64 |
65 | } |
66 |
67 | } |
68 |
69 | } |
Selamat mencoba, semoga bermanfaat
Adhitya warman- Jumlah posting : 10
Join date : 16.04.12
Lokasi : BENGKULU
Similar topics
» Contoh Program Variabel dan Tipe Data
» Membuat Tulisan Program Aplikasi "GOOD LUCK SELAMAT BEKERJA"
» Buatlah program menghitung sisi miring (rumus Phitagoras) Input : a, b Output : c = Sqr(a^2 + b^2)
» Membuat Tulisan Program Aplikasi "GOOD LUCK SELAMAT BEKERJA"
» Buatlah program menghitung sisi miring (rumus Phitagoras) Input : a, b Output : c = Sqr(a^2 + b^2)
STUDI FORUM :: PEMROGRAMAN :: JAVA
Halaman 1 dari 1
Permissions in this forum:
Anda tidak dapat menjawab topik
|
|