滚动字体不显示

reshine8306 2017-11-27 07:34:18
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();
}
}
...全文
170 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
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方法替换一下就可以了。。其中跟你的不同自己比较下吧

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧