Event Handling is handling concept an action that occurred. So a program will run when something happens, for example when the button is clicked, when the combo box is selected and so forth. Java has some type of Event Handling, one of which is the ActionListener class that handles the action of a button. Here is an example program:
Views:
Views:

import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ClickMe extends JFrame implements ActionListener { private JButton tombol; public ClickMe() { super ("Event Handling"); Container container = getContentPane(); container.setLayout(new FlowLayout()); tombol = new JButton ("Click Me!"); tombol.addActionListener(this); container.add(tombol); setSize (200,100); setVisible (true); } public static void main (String arg[]) { ClickMe test = new ClickMe(); test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed (ActionEvent e) { if (e.getSource() == tombol) { JOptionPane.showMessageDialog(null, "You click me, guys !!!"); } } }
0 comments on Examples of Event Handling in Java :
Post a Comment and Don't Spam!
Dont Spam please