导航:首页 > 编程语言 > java走马灯的工作原理

java走马灯的工作原理

发布时间:2025-04-05 22:45:31

❶ 使用java做一个走马灯,源代码

网上帮你找的 跑马灯 你可以使用 Timer 也可以使用线程 间隔多少毫秒移动一段距离 实现起来其实也不难
package clock;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Calendar;
import java.util.Date;
import java.text.*;

public class removingLight extends JFrame {

public removingLight() {

Font font1 = new Font("幼圆", Font.BOLD, 16);

Calendar cal = Calendar.getInstance();
SimpleDateFormat formatter = new SimpleDateFormat(
"EEEE,MMMMdd日,yyyy年 HH:mm:ss");
String mDateTime = formatter.format(cal.getTime());
MovingMessagePanel messagePanel = new MovingMessagePanel(mDateTime);
messagePanel.setFont(font1);
messagePanel.setBackground(Color.BLACK);
messagePanel.setForeground(Color.PINK);
add(messagePanel);
}

public static void main(String[] args) {
removingLight frame = new removingLight();
JLabel label = new JLabel("开始调试时间:5月5日 结束调试时间:5月6日");
label.setBackground(Color.black);
frame.setTitle("软件1班 XXX 3107006757");
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(320, 120);
frame.add(label, BorderLayout.SOUTH);
frame.setVisible(true);

}

static class MovingMessagePanel extends JPanel {
private String message = " ";
private int xCoordinate = 0;
private int yCoordinate = 40;

public MovingMessagePanel(String message) {
this.message = message;

Timer timer = new Timer(100, new TimerListener());
timer.start();
}

public void paintComponent(Graphics g) {
super.paintComponent(g);

if (xCoordinate > getWidth()) {
xCoordinate = -100;
}

xCoordinate += 5;
g.drawString(message, xCoordinate, yCoordinate);
}

class TimerListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
repaint();
}
}
}

}

阅读全文

与java走马灯的工作原理相关的资料

热点内容
测量大师导入底图找不到文件 浏览:313
小红伞安装程序要求版本6 浏览:799
全民k歌pcm文件夹 浏览:224
c图片写入数据库 浏览:466
c串口程序 浏览:500
中农金融注册app有哪些 浏览:629
回收站文件清理不在电脑上有痕迹 浏览:886
dx版本更新 浏览:738
主机集群教程 浏览:939
苹果6英版好不好 浏览:959
nodejs抓取网站音频 浏览:772
app上下载的软件在哪里 浏览:36
起凡保存的照片在哪个文件夹 浏览:354
数学建模如何把模型编程 浏览:176
ug找不到指定的许可文件 浏览:850
数控编程g01表示什么 浏览:700
java实用类 浏览:190
去年做哪个网站能致富 浏览:727
多少的cad版本能打开pdf格式文件 浏览:540
win10文件比率是什么 浏览:652

友情链接