走馬燈程序怎麼編寫呢,不用急,下面小編準備了關於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();
}
}
}
}