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

熱點內容
cad的列印到文件怎麼設置 瀏覽:902
智行app鉑金會員怎麼還有期限 瀏覽:581
win10用子文件夾改名 瀏覽:234
ae鋼筆工具在哪裡 瀏覽:460
gn105數據線插哪裡 瀏覽:916
破鎖屏密碼方法 瀏覽:835
股票數據放哪裡 瀏覽:576
m格式庫文件 瀏覽:279
天際通數據服務怎麼開票 瀏覽:430
寫小說發哪個網站比較好 瀏覽:244
小米電視3藍牙文件路徑 瀏覽:111
shell讀取文件值 瀏覽:909
文件夾路徑欄消失 瀏覽:795
律師哪些業務不能代替大數據 瀏覽:952
lol哪些文件可以刪除 瀏覽:701
匯編程序中del是什麼意思 瀏覽:183
幼兒園免費網站模板下載 瀏覽:210
w619線刷教程 瀏覽:759
怎麼培養編程思想 瀏覽:697
手機捆綁app的軟體怎麼卸載 瀏覽:32

友情鏈接