- 相關(guān)推薦
Java怎么編寫(xiě)走馬燈程序
走馬燈程序怎么編寫(xiě)呢,不用急,下面小編準(zhǔn)備了關(guān)于Java怎么編寫(xiě)走馬燈程序的文章,提供給大家參考!
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("開(kāi)始調(diào)試時(shí)間:5月5日 結(jié)束調(diào)試時(shí)間: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.setVisible(true);
frame.add(label, BorderLayout.SOUTH);
}
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怎么編寫(xiě)走馬燈程序】相關(guān)文章:
Java怎么編寫(xiě)Oracle存儲(chǔ)過(guò)程03-20
如何編譯java程序03-05
Java編寫(xiě)計(jì)算器的的常見(jiàn)做法01-22
實(shí)現(xiàn)鼠標(biāo)畫(huà)圖的Java程序03-16
Java程序開(kāi)發(fā)與運(yùn)行環(huán)境03-05
sun認(rèn)證java程序員須知Java日志框架03-30
如何使用Swing編寫(xiě)全屏程序03-21
怎么安裝java環(huán)境03-29
初級(jí)java程序員任職要求03-29