lp1滚动字体不显示,代码如下,请大神指点
package com.db;import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;public class SbcghtExportUtils extends JFrame implements Runnable { Thread t = new Thread(this);// 在窗体里创建线程并实例化
JDesktopPane deskpane = new JDesktopPane();// 在窗体里建立虚拟桌面并实例化
JPanel p = new JPanel();// 创建一个面板并实例化
Label lp1 = new Label(
"欢  迎  使  用  员  工  管  理  系  统 !           有 不 明 白 请 看 帮 助 !        本 系 统 禁 止 用 作 商 业 用 途 !"); public SbcghtExportUtils() {// 构造函数
setTitle("员工管理系统");// 设置窗体标题
Container con = getContentPane();
con.setLayout(new BorderLayout());// 创建一个布局
con.add(deskpane, BorderLayout.CENTER);// 实例虚拟桌面的布局 Font f = new Font("新宋体", Font.PLAIN, 12);// 设置一个字体,以后设置字体全部调用这种字体,懒得弄那么花花哨哨的 // Label lp1=new Label("欢  迎  使  用  员  工  管  理  系  统 !");
p.setLayout(new BorderLayout());
p.add(lp1, BorderLayout.EAST);
t.start(); con.add(p, BorderLayout.SOUTH); Toolkit t = Toolkit.getDefaultToolkit();
int width = t.getScreenSize().width - 200;
int height = t.getScreenSize().height - 100;
setSize(width, height);
setLocation(150, 100);
setVisible(true);
setResizable(false); // 设置窗口大小不允许调整
} // 线程的方法
public void run() {
System.out.println("线程启动了!");// 友好提示
Toolkit t = Toolkit.getDefaultToolkit();
int x = t.getScreenSize().width;
System.out.println("x=" + x); // lp1.setFont( new Font("宋体",Font.ITALIC,"14"));
lp1.setForeground(Color.red);
while (true) {
if (x < -600) {
x = t.getScreenSize().width;
// System.out.println("x为:" + x);
}
lp1.setBounds(x, 0, 700, 20);
x -= 10;
// System.out.println(x);
try {
Thread.sleep(100);
} catch (Exception e) {
}
// }
}
} public static void main(String[] args) {// 主函数
new SbcghtExportUtils();
}
}

解决方案 »

  1.   

        // 线程的方法
        public void run() {
            System.out.println("线程启动了!");// 友好提示
            Toolkit t = Toolkit.getDefaultToolkit();
            Point point = lp1.getLocation();
            point.x = this.getWidth();
            System.out.println("x=" + point.x);
            lp1.setLocation(point);
            // lp1.setFont( new Font("宋体",Font.ITALIC,"14"));
            lp1.setForeground(Color.red);
            while (true) {
                if (point.x <= 0) {
                 point.x = this.getWidth();
                    // System.out.println("x为:" + x);
                }
    //            lp1.setBounds(x, 0, 700, 20);
                point.x -= 80;
                lp1.setLocation(point);
                // System.out.println(x);
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                }
                // }
            }把这个run方法替换一下就可以了。。其中跟你的不同自己比较下吧