Skip to content

Instantly share code, notes, and snippets.

@kappa7194
Last active December 14, 2015 16:58
Show Gist options
  • Save kappa7194/5118400 to your computer and use it in GitHub Desktop.
Save kappa7194/5118400 to your computer and use it in GitHub Desktop.
My first Java GUI application.
package it.penpen.java.myproject;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;
public class MyClass implements Runnable {
public static void main(String[] args) {
FlowLayout layout = new FlowLayout();
JLabel label = new JLabel("Hello, world.");
JButton button = new JButton("Click me.");
JFrame frame = new JFrame("Hello, world.");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(layout);
frame.add(label);
frame.add(button);
frame.pack();
frame.setVisible(true);
}
@Override
public void run() {
MyClass my = new MyClass();
SwingUtilities.invokeLater(my);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment