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