社区
Java SE
帖子详情
swing中公告栏的信息怎么滚动???
wwq101693
2009-01-03 10:52:59
我现在要做一个公告栏,例如:公告:公司今天下午2点开会。然后,人家要求“公司今天下午2点开会。”这些字要滚动的!怎么才能让他滚动开啊,大家帮帮忙
...全文
280
12
打赏
收藏
swing中公告栏的信息怎么滚动???
我现在要做一个公告栏,例如:公告:公司今天下午2点开会。然后,人家要求“公司今天下午2点开会。”这些字要滚动的!怎么才能让他滚动开啊,大家帮帮忙
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用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加上线程就可以了
大学生java大赛试题
java大赛试题,非常好的试题,帮助你学好JAVA,很好的学习资料。
2021-2022计算机二级等级考试试题及答案No.17669.docx
2021-2022计算机二级等级考试试题及答案No.17669.docx
Java技巧:JLabel
公告栏
文字
滚动
效果
首先要掌握一个概念:一个字符串在计算机屏幕
中
所占的像素,比方说取一个JLabel里面的Text所占的宽和高,方法如下: (主要用到FontMetrics类) import java.awt.FontMetrics; import javax.
swing
.JLabel; JLabel label = new JLabel("test Lab
JAVA
SWING
自定义行列标题的
滚动
面板示例
JScrollPane有以下两个方法 setColumnHeaderView(Component view) setRowHeaderView(Component view) 你可以利用它们, 一个用来显示表行头,一个用来显示列头 同例行标题也有. package scrollpanel; import java.awt.Dimension; import java.awt.GridBag
创建动态上下
滚动
公告栏
的jQuery教程
jQuery是一个快速、小巧且功能丰富的JavaScript库,它简化了HTML文档遍历、事件处理、动画和Ajax交互的编程工作。由于其轻量级和兼容性,在网页交互设计
中
得到了广泛的应用。jQuery通过提供易于使用的API,让开发者能够以较少的代码量完成复杂的功能,从而加速网页开发过程,并提高项目的可维护性。animate()queue()方法是 JavaScript
中
用于以固定的时间间隔执行函数或代码片段的一种技术。这种方法非常适合于周期性的任务处理,例如在网页
中
实现自动
滚动
的内容
公告栏
。
Java SE
62,634
社区成员
307,269
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章