Difference between revisions of "Simple JFrame"
From MyWiki
(Created page with "How to make frames tutorial : https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html") |
|||
| (2 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | How to make frames tutorial : https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html | + | How to make frames tutorial : https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html<br> |
| + | <br> | ||
| + | <source lang="java"> | ||
| + | package components; | ||
| + | |||
| + | import java.awt.*; | ||
| + | import java.awt.event.*; | ||
| + | import javax.swing.*; | ||
| + | |||
| + | /* FrameDemo.java requires no other files. */ | ||
| + | public class FrameDemo { | ||
| + | /** | ||
| + | * Create the GUI and show it. For thread safety, | ||
| + | * this method should be invoked from the | ||
| + | * event-dispatching thread. | ||
| + | */ | ||
| + | private static void createAndShowGUI() { | ||
| + | //Create and set up the window. | ||
| + | JFrame frame = new JFrame("FrameDemo"); | ||
| + | frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
| + | |||
| + | JLabel emptyLabel = new JLabel(""); | ||
| + | emptyLabel.setPreferredSize(new Dimension(175, 100)); | ||
| + | frame.getContentPane().add(emptyLabel, BorderLayout.CENTER); | ||
| + | |||
| + | //Display the window. | ||
| + | frame.pack(); | ||
| + | frame.setVisible(true); | ||
| + | } | ||
| + | |||
| + | public static void main(String[] args) { | ||
| + | //Schedule a job for the event-dispatching thread: | ||
| + | //creating and showing this application's GUI. | ||
| + | javax.swing.SwingUtilities.invokeLater(new Runnable() { | ||
| + | public void run() { | ||
| + | createAndShowGUI(); | ||
| + | } | ||
| + | }); | ||
| + | } | ||
| + | } | ||
| + | |||
| + | </source> | ||
Latest revision as of 08:51, 18 November 2014
How to make frames tutorial : https://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
package components; import java.awt.*; import java.awt.event.*; import javax.swing.*; /* FrameDemo.java requires no other files. */ public class FrameDemo { /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ private static void createAndShowGUI() { //Create and set up the window. JFrame frame = new JFrame("FrameDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel emptyLabel = new JLabel(""); emptyLabel.setPreferredSize(new Dimension(175, 100)); frame.getContentPane().add(emptyLabel, BorderLayout.CENTER); //Display the window. frame.pack(); frame.setVisible(true); } public static void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }