惊世猛兽,儿子被查出女儿身,removechild
本文实例讲述了java基于线程实现带有滚动效果的label标签。分享给大家供大家参考。具体如下:
import java.awt.graphics; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; /** * java中用线程实现带有滚动效果的label标签 */ public class test extends jframe { private static final long serialversionuid = -2397593626990759111l; private jpanel pane = null; private movelabel label = null; public test() { super("test"); pane = new jpanel(); label = new movelabel("带有滚动效果的标签"); 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(); } /** * 带有滚动效果的label标签,可继续拓展很多特效,例如颜色变换、速度变换等 */ 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(); } } } } }
希望本文所述对大家的java程序设计有所帮助。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论