導航:首頁 > 編程語言 > 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走馬燈的工作原理相關的資料

熱點內容
主機集群教程 瀏覽:939
蘋果6英版好不好 瀏覽:959
nodejs抓取網站音頻 瀏覽:772
app上下載的軟體在哪裡 瀏覽:36
起凡保存的照片在哪個文件夾 瀏覽:354
數學建模如何把模型編程 瀏覽:176
ug找不到指定的許可文件 瀏覽:850
數控編程g01表示什麼 瀏覽:700
java實用類 瀏覽:190
去年做哪個網站能致富 瀏覽:727
多少的cad版本能打開pdf格式文件 瀏覽:540
win10文件比率是什麼 瀏覽:652
msdb資料庫置疑 瀏覽:210
移動花卡免流app為什麼要10元 瀏覽:147
xamppphp配置文件 瀏覽:268
刪除ghost文件 瀏覽:642
蘋果7可置換地方 瀏覽:763
win10騰訊文件夾在哪裡 瀏覽:262
在網站前面加什麼可以看會員視頻 瀏覽:908
哪個讀書app支持格式最全 瀏覽:322

友情鏈接