Advertisement
zoro-10

MyAnonymousInner.java

Mar 30th, 2024
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import javax.swing.*;
  5.  
  6. public class MyAnonymousInner {
  7.  
  8.   public static void main(String args[]) {
  9.     SwingUtilities.invokeLater(() -> {
  10.       JFrame frame = new JFrame("Anonymous Inner Class");
  11.       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  12.       JPanel panel = new JPanel();
  13.       panel.setPreferredSize(new Dimension(300, 200));
  14.       JButton button = new JButton("Click Here");
  15.       button.addActionListener(
  16.         new ActionListener() {
  17.           @Override
  18.           public void actionPerformed(ActionEvent e) {
  19.             JOptionPane.showMessageDialog(frame, "Button Clicked!");
  20.           }
  21.         }
  22.       );
  23.       panel.add(button);
  24.       frame.add(panel);
  25.       frame.pack();
  26.       frame.setVisible(true);
  27.     });
  28.   }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement