Java Simple Swing Graphical interface application example

Source: Internet
Author: User
Tags lenovo

Java Simple Swing Graphical interface application example


Package Org.rui.hello;import javax.swing.jframe;/** * Simple Swing window * @author Lenovo * */public class Helloswing {public stat IC void Main (string[] args) {JFrame frame=new JFrame ("Hello Swing"); Frame.setdefaultcloseoperation (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.setdefaultcloseoperation (Jframe.exit_on_close); 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.setdefaultcloseoperation ( Jframe.exit_on_close); Frame.setsize (+); frame.setvisible (true); TimeUnit.SECONDS.sleep (1);//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 (+); SetVisible (True );} static Submitswingprogram ssp;public static void Main (string[] args) throws Interruptedexception {// Instance Object Swingutilities.invokelater (new Runnable () {@Overridepublic void run () {SSP = new Submitswingprogram ();}}); TimeUnit.SECONDS.sleep (1);//settings Change text swingutilities.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 yourself, * to use it,  Your app must be in a jframe * static Run method 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.se Ttitle (F.getclass (). Getsimplename ()); F.setdefaultcloseoperation (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.