當前位置:才華齋>IT認證>JAVA認證>

Java怎麼編寫走馬燈程式

JAVA認證 閱讀(1.01W)

走馬燈程式怎麼編寫呢,不用急,下面小編準備了關於Java怎麼編寫走馬燈程式的文章,提供給大家參考!

Java怎麼編寫走馬燈程式

package clock;

import .*;

import t.*;

import g.*;

import ndar;

import ;

import .*;

public class removingLight extends JFrame {

public removingLight() {

Font font1 = new Font("幼圓", , 16);

Calendar cal = nstance();

SimpleDateFormat formatter = new SimpleDateFormat(

"EEEE,MMMMdd日,yyyy年 HH:mm:ss");

String mDateTime = at(ime());

MovingMessagePanel messagePanel = new MovingMessagePanel(mDateTime);

ont(font1);

ackground(K);

oreground();

add(messagePanel);

}

public static void main(String[] args) {

removingLight frame = new removingLight();

JLabel label = new JLabel("開始除錯時間:5月5日 結束除錯時間:5月6日");

ackground(k);

itle("軟體1班 XXX 3107006757");

ocationRelativeTo(null);

efaultCloseOperation(_ON_CLOSE);

ize(320, 120);

isible(true);

(label, H);

}

static class MovingMessagePanel extends JPanel {

private String message = " ";

private int xCoordinate = 0;

private int yCoordinate = 40;

public MovingMessagePanel(String message) {

age = message;

Timer timer = new Timer(100, new TimerListener());

t();

}

public void paintComponent(Graphics g) {

tComponent(g);

if (xCoordinate > getWidth()) {

xCoordinate = -100;

}

xCoordinate += 5;

String(message, xCoordinate, yCoordinate);

}

class TimerListener implements ActionListener {

public void actionPerformed(ActionEvent e) {

repaint();

}

}

}

}