Skip to content

Instantly share code, notes, and snippets.

@benjaminaaron
Created March 10, 2017 21:39
Show Gist options
  • Save benjaminaaron/8e9cdfc1d236cde006ffd0c2c5626a89 to your computer and use it in GitHub Desktop.
Save benjaminaaron/8e9cdfc1d236cde006ffd0c2c5626a89 to your computer and use it in GitHub Desktop.
Simple Swing
import java.awt.event.ActionEvent;
import javax.swing.*;
public class Main {
public static void main(String[] args) {
JFrame frame = new JFrame("Simple Swing");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
JLabel label = new JLabel("Hello Swing World");
panel.add(label);
JButton button = new JButton(new AbstractAction("click me") {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "This is a message :)", "message", JOptionPane.INFORMATION_MESSAGE);
}
});
panel.add(button);
frame.pack();
frame.setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment