JAVA simple Swing graphical interface application example

Source: Internet
Author: User

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 );}});}}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.