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

熱點內容
u盤驅動在哪個文件夾里 瀏覽:938
華為手機跟蘋果手機怎麼克隆app 瀏覽:172
cad文件為什麼顯示文件名是否正確 瀏覽:174
程序配置文件能自動轉換成txt 瀏覽:985
r4燒錄卡不同版本 瀏覽:962
怎麼升級qq群為2000 瀏覽:347
微信己冊除的文件怎樣找回來 瀏覽:715
蘋果美國賬號共享2017 瀏覽:252
ps文件修改後打開還是原圖 瀏覽:220
燒卡機蘋果4微信qq哪裡下載 瀏覽:780
ug120找不到指定文件 瀏覽:522
cda文件怎麼轉換成mp3格式 瀏覽:702
青島hpv疫苗在哪個app預約 瀏覽:881
雙十一成交額2021數據在哪裡看 瀏覽:631
蘋果手機怎麼打開移動數據 瀏覽:637
文件掃描成圖片是彩色的嗎 瀏覽:50
編程里的comply什麼意思 瀏覽:91
電腦上面點了禁用網路怎麼改回來 瀏覽:28
javacatch執行 瀏覽:182
ps軟體文件名字 瀏覽:184

友情鏈接