Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.*;
- public class MyAnonymousInner {
- public static void main(String args[]) {
- SwingUtilities.invokeLater(() -> {
- JFrame frame = new JFrame("Anonymous Inner Class");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- JPanel panel = new JPanel();
- panel.setPreferredSize(new Dimension(300, 200));
- JButton button = new JButton("Click Here");
- button.addActionListener(
- new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- JOptionPane.showMessageDialog(frame, "Button Clicked!");
- }
- }
- );
- panel.add(button);
- frame.add(panel);
- frame.pack();
- frame.setVisible(true);
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement