Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class EventHandling {
- public static void main(String[] args) {
- JFrame frame = new JFrame("Event Handling");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setSize(300,200);
- frame.setLayout(null);
- JLabel label = new JLabel("Click the button");
- label.setBounds(80, 30, 150, 30);
- frame.add(label);
- JButton button = new JButton("Click Me");
- button.setBounds(90, 80, 120, 30);
- frame.add(button);
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- label.setText("Button Clicked!");
- }
- });
- frame.setVisible(true);
- }
- }
Add Comment
Please, Sign In to add comment