Created
October 12, 2016 22:03
-
-
Save timmolderez/1900f4b2cd69a9d27ec82918f4091172 to your computer and use it in GitHub Desktop.
Simple Swing application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package be.vub; | |
import java.awt.BorderLayout; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import javax.swing.JButton; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
public class Main { | |
/** | |
* Starts the main GUI window | |
*/ | |
public static void main(String[] args) { | |
javax.swing.SwingUtilities.invokeLater(new Runnable() { | |
public void run() { | |
// Setup the application's window | |
JFrame frame = new JFrame("Swing Text Editor"); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
// Setup the content pane | |
JPanel contentPane = new JPanel(); | |
contentPane.setLayout(new BorderLayout()); | |
frame.setContentPane(contentPane); | |
// Add a button to the content pane | |
final JButton button = new JButton("Click here"); | |
contentPane.add(button, BorderLayout.CENTER); | |
button.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent e) { | |
button.setText("Clicked"); | |
} | |
}); | |
// Display the window | |
frame.pack(); | |
frame.setSize(640, 480); | |
frame.setLocationRelativeTo(null); | |
frame.setVisible(true); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment