The example in this article describes the Java based thread implementation of label labels with scrolling effects. Share to everyone for your reference. as follows:
Import Java.awt.Graphics;
Import Javax.swing.JFrame;
Import Javax.swing.JLabel;
Import Javax.swing.JPanel; /** * Java uses a thread to implement a label label with scrolling effect */public class Test extends JFrame {private static final long Serialversionuid =-2397
593626990759111L;
Private JPanel pane = null;
Private Movelabel label = NULL;
Public test () {super ("Test");
pane = new JPanel ();
label = new Movelabel ("label with scrolling effect");
Pane.add (label);
This.getcontentpane (). Add (pane);
This.setdefaultcloseoperation (Jframe.exit_on_close);
This.setsize (300, 200);
This.setvisible (TRUE);
public static void Main (String args[]) {new Test (); /** * with scrolling effect label label, can continue to expand a lot of special effects, such as color conversion, speed conversion, etc./private class Movelabel extends JLabel implements Runnable {private
Static final Long serialversionuid = 1891684760189602720L;
Private String text = null;
Private thread thread = NULL;
private int x = 0;
private int w = 0, h = 0;
Public Movelabel (String text) {super (text);
This.text = text; thread = new Thread (this);
Thread.Start ();
Public String GetText () {return text;
public void SetText (String text) {super.settext (text);
This.text = text;
} protected void Paintcomponent (Graphics g) {super.paintcomponent (g);
G.setcolor (This.getbackground ());
G.fillrect (0, 0, w = this.getwidth (), H = this.getheight ());
G.setcolor (This.getforeground ());
G.setfont (This.getfont ());
g.DrawString (text, x, h-2);
public void Run () {while (true) {x = 2;
if (x < W) {x = W;
} this.repaint ();
try {thread.sleep (50);
catch (Interruptedexception e) {e.printstacktrace ();
}
}
}
}
}
I hope this article will help you with your Java programming.