JAVA simple Swing graphical interface application example
JAVA simple Swing graphical interface application example
Package org. rui. hello; import javax. swing. JFrame;/*** simple swing window * @ author lenovo **/public class HelloSwing {public static void main (String [] args) {JFrame frame = new JFrame ("hello Swing"); frame. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); frame. setSize (300,200); frame. setVisible (true );}}
Package org. rui. hello; import java. util. concurrent. timeUnit; import javax. swing. JFrame; import javax. swing. JLabel;/*** Add a JLabel in JFream to make things more interesting * @ author lenovo **/public class HelloLabel {public static void main (String [] args) throws InterruptedException {JFrame frame = new JFrame ("hello swing"); JLabel label = new JLabel ("A label"); frame. add (label); frame. setdefaclocloseoperation (JFrame. EXIT_ON_CLOS E); frame. setSize (300,100); frame. setVisible (true); TimeUnit. SECONDS. sleep (1); label. setText ("Hey! This is Different! ");}}
Package org. rui. hello; import java. util. concurrent. timeUnit; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. swingUtilities; /*** swing has its own dedicated thread to receive UI events and update the screen ** @ author lenovo **/public class SubmitLabelManipulationTask {public static void main (String [] args) throws InterruptedException {JFrame frame = new JFrame ("Hello Swing"); final JLabel label = new JLabel ("A Label"); frame . Add (label); frame. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); frame. setSize (300,100); frame. setVisible (true); TimeUnit. SECONDS. sleep (1); // The dedicated thread SwingUtilities. invokeLater (new Runnable () {@ Overridepublic void run () {label. setText ("hey! This is different ");}});}}
Package org. rui. hello; import java. util. concurrent. timeUnit; import javax. swing. JFrame; import javax. swing. JLabel; import javax. swing. swingUtilities; public class SubmitSwingProgram extends JFrame {JLabel label; public SubmitSwingProgram () {super ("hello swing"); Label = new JLabel ("A label"); add (label ); setSize (300,100); setVisible (true);} // static SubmitSwingProgram ssp; public static void main (String [] arg S) throws InterruptedException {// Instance Object SwingUtilities. invokeLater (new Runnable () {@ Overridepublic void run () {ssp = new SubmitSwingProgram () ;}}); TimeUnit. SECONDS. sleep (1); // set to change the SwingUtilities text. invokeLater (new Runnable () {@ Overridepublic void run () {ssp. label. setText ("hey! This is different! ");}});}}
Package org. rui. hello; import javax. swing. JFrame; import javax. swing. swingUtilities;/*** this may be a tool you want to use. * to use it, your application must be located in a JFrame * static run method. You can set the title of the window to the simple name of the class * @ author lenovo **/public class SwingConsole {public static void run (final JFrame f, final int width, final int height) {SwingUtilities. invokeLater (new Runnable () {@ Overridepublic void run () {f. setTitle (f. getClass (). getSimpleName (); f. setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE); f. setSize (width, height); f. setVisible (true );}});}}