swing中公告栏的信息怎么滚动???

wwq101693 2009-01-03 10:52:59
我现在要做一个公告栏,例如:公告:公司今天下午2点开会。然后,人家要求“公司今天下午2点开会。”这些字要滚动的!怎么才能让他滚动开啊,大家帮帮忙
...全文
301 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
bzwm 2009-01-12
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 gongfuliang 的回复:]
引用 4 楼 neo0208 的回复:
自己再加多个双缓冲处理 就行了!

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class SwingDemo extends JFrame {

public SwingDemo() {
this.setLayout(new Bor…
[/Quote]

javax.swing.Timer 这个可以。
Dream_JavaWorld 2009-01-12
  • 打赏
  • 举报
回复
mark
nj_dobetter 2009-01-09
  • 打赏
  • 举报
回复
用线程。
chen_2001 2009-01-09
  • 打赏
  • 举报
回复
写个线程
让它的字符串滚动

import java.awt.*;
import javax.swing.*;

/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2005</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/

public class MoveLabel
extends JLabel implements Runnable {

private String text = null;

private Thread thread = null;

private int x = 0;
private int strWidth = 0;

private int w = 0, h = 0;
Font font = new Font("MS Sans Serif", Font.PLAIN, 12);
FontMetrics fm = this.getFontMetrics(font);

public MoveLabel(String text) {
super(text);
this.text = text;
thread = new Thread(this);
thread.start();
}

public String getText() {
return text;
}

public void setText2Label(String text) {
super.setText(text);
this.text = text;
strWidth = fm.stringWidth(text);
x = w;
}

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 - 5);
}

public void run() {

if (x + strWidth < 0) {
x = w;
}
if (x + strWidth >= 0) {
x -= 2;
}
try {
Thread.sleep(100);
}
catch (InterruptedException e) {
e.printStackTrace();
}
this.repaint();
}
}

}
likgui 2009-01-08
  • 打赏
  • 举报
回复
关注中
wwq101693 2009-01-06
  • 打赏
  • 举报
回复
neo0208,大哥,缓冲区你也给写一下吧,多谢了,明天就交活了,帮帮忙,在线等了........
贝壳鱼 2009-01-06
  • 打赏
  • 举报
回复
draw string 在 一张 image 上, 然后 setClip 然后 循环 move.
gongfuliang 2009-01-05
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 neo0208 的回复:]
自己再加多个双缓冲处理 就行了!

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class SwingDemo extends JFrame {

public SwingDemo() {
this.setLayout(new BorderLayout…
[/Quote]

呵呵,配合的还挺好的,不过Timer用错包了,用util包下的
neo0208 2009-01-05
  • 打赏
  • 举报
回复
自己再加多个双缓冲处理 就行了!

import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;

public class SwingDemo extends JFrame {

public SwingDemo() {
this.setLayout(new BorderLayout());
this.add(new MyJPanel("I hate you"), BorderLayout.CENTER);
this.setBounds(200, 100, 600, 500);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}

public static void main(String[] args) {
new SwingDemo();
}

class MyJPanel extends JPanel {
private String message = "";
private int index = 50;

public MyJPanel(String message) {
this.message = message;
refreshTimer.start();
}

Timer refreshTimer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
refreshTimer_actionPerformed();
}
});

public void paint(Graphics g) {
Graphics2D gg = (Graphics2D)g;
gg.drawString(message, index, 50);
}

protected void refreshTimer_actionPerformed() {
index = index + 2;
if (index >= 100) {
index = 50;
}
this.repaint();
}
}
}
wwq101693 2009-01-04
  • 打赏
  • 举报
回复
二楼的兄弟能说的详细点吗,写点伪代码也行,小弟刚接触swing,还不怎么了解!
gongfuliang 2009-01-03
  • 打赏
  • 举报
回复
paint就行了。

重写paintComponent方法 over

drawString(s,x,y),根据你的需要设置x的值就行了,使用Timer刷新
ErfengDu 2009-01-03
  • 打赏
  • 举报
回复
用一个JLABLE加上线程就可以了
代码下载链接: https://pan.quark.cn/s/b27638adc362 在工业自动化监控领域,WinCC 被视为一种常用的可视化软件,其功能在于构建人机界面(HMI)以及SCADA系统。本资料将阐释在WinCC环境下如何构建一个展现管道流体流动的动态效果,此功能主要通过C动作脚本来完成。在此过程,我们需要构建两个矩形,分别标记为 rec1 和 rec2。这两个矩形的高度相等,但 rec1 的宽度要小于 rec2。在具体实施时,rec1 将作为展示流体运动的可见单元,而 rec2 则作为辅助元素,尽管其“显示”属性被设为关闭,但在程序执行期间,其属性参数对流体动画的表现起着决定性作用,因为 rec2 与 rec1 的宽度差将决定流体每次移动的长度。 随后,我们需要将 rec1 和 rec2 整合为一个自定义对象。在自定义对象的属性配置,应包含 rec1.Left、rec1.Width、rec1.Visible 和 rec2.Width 这些核心属性。这些属性将有助于在C脚本精确控制对象的位置和可见状态,以达成流体运动的视觉效果。同时,用户可根据实际需求增加其他属性,以增强自定义对象的功能性。 在自定义对象的C脚本部分,我们设定了一个周期为“250ms”的触发器。该脚本的核心职责是计算并更新流体块的位置。借助 GetPropBOOL、GetPropWord 和 GetLeft 函数,我们可以获取对象的当前状态,涵盖其可见性、位置及宽度等参数。在循环操作,流体块(rec1)将向右移动 rec2 - rec1 的距离,一旦流体块移出显示范围(即 rec1 的右边界达到或超过 rec2 的左边界),它将重新回到起始位置,从而形成流体持续流动的模...

62,622

社区成员

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

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