Package Thread_test;import Java.awt.container;import Javax.swing.jframe;import javax.swing.jlabel;import Javax.swing.swingconstants;public class Thread_swing extends JFrame {/** * */private static final long Serialversionuid = 1l;private JLabel JL = new JLabel ("Hi");p rivate static Thread t;private int count = 0;private Container c = Getcontentpan E ();p ublic thread_swing () {//TODO auto-generated Constructor Stubsetbounds (+, +, +); C.setlayout (null); Jl.sethorizontalalignment (Swingconstants.left); Jl.setbounds (ten, ten, +); t=new Thread (New Runnable () {public void Run () {//TODO auto-generated method stub while (count<=200) {jl.setbounds (count, ten, max); try {thread.sleep (500);} catch (Exception e) {//Todo:handle exceptione.printstacktrace ();} Count+=4;if (count==200) {count=10;}}}); T.start (); C.add (JL); setvisible (true); Setdefaultcloseoperation (exit_on_close);} public static void Main (string[] args) {//TODO auto-generated method Stubnew thread_swing ();}}
Note: Use threads to implement JLabel cyclic scrolling.
Utility Runnable Interface Create thread step: Create Runnable Class--"Instantiate object--" write implementation method, namely: Thread t--t = new Thread (new runnable)--run inside Write method
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java Essentials Learning Note thread+jlabel Implementing threads