Java怎么编写走马灯程序

时间:2023-03-20 15:27:26 JAVA认证 我要投稿
  • 相关推荐

Java怎么编写走马灯程序

  走马灯程序怎么编写呢,不用急,下面小编准备了关于Java怎么编写走马灯程序的文章,提供给大家参考!

  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.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怎么编写走马灯程序】相关文章:

Java编写计算器的的常见做法01-22

sun认证java程序员须知Java日志框架03-30

怎么安装java环境03-29

java程序中如何调用linux命令03-29

java程序员面试试题11-30

SUN认证JAVA程序员简介10-25

初级java程序员面试要求01-22

初级java程序员任职要求03-29

JAVA语言程序设计练习题03-26

Java程序员必备的开发工具03-30