Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.aezart.simpleswingexample;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.event.ActionEvent;
- import javax.swing.AbstractAction;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import javax.swing.SwingUtilities;
- public class SimpleSwingExample {
- JFrame mainWindow = new JFrame();
- JButton helloButton = new JButton(new HelloAction());
- class HelloAction extends AbstractAction{
- public HelloAction(){
- super("Click me!");
- }
- @Override
- public void actionPerformed(ActionEvent arg0) {
- JOptionPane.showMessageDialog(mainWindow, "Hello, World.", "ALERT", JOptionPane.INFORMATION_MESSAGE);
- }
- }
- public SimpleSwingExample(){
- mainWindow.setTitle("Simple Swing Example");
- mainWindow.setPreferredSize(new Dimension(320,240));
- mainWindow.setLayout(new FlowLayout());
- mainWindow.add(helloButton);
- mainWindow.pack();
- mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- mainWindow.setLocationRelativeTo(null);
- mainWindow.setVisible(true);
- }
- public static void main(String[] args){
- SwingUtilities.invokeLater(() -> {
- SimpleSwingExample s = new SimpleSwingExample();
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement