用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();

  }

  }

  }

  }


 
本文转自 ☆★ 包罗万象网 ★☆ - http://www.baoluowanxiang.com 转载请注明出处,侵权必究!
原文链接:http://www.baoluowanxiang.com/a/program/java/2010/0531/918.html

文字滚动-Java文字走马灯,这是大家熟悉的跑马灯特效,文字依次滚动,不停的循环滚动,就类似网页上的文字滚动效果,本例的文字由下到上滚动显示。// 文字跑马灯与信息窗口   public class MessageDemo extends MIDlet implements CommandListener {   private Display display; // 设备的显示器   private Form form; // 表单   private Command cancel; // 取消命令   private String message="随着越来越多手提电话和个人数字助理开始融入到信息高速公路之上,从移动设备上访问Web站点变得越来越重要。Java开创了消费设备中小型的储存容量的先河,它是用于开发手机、传呼机及其他微型设备应用程序的理想语言。";   private StringItem messageItem; //信息显示Item   public MessageDemo() {    form = new Form("信息显示");    cancel = new Command("取消", Command.CANCEL, 1);    messageItem=new StringItem("",message);   }   // 重载抽象类MIDlet的抽象方法startApp()   protected void startApp() {    display = Display.getDisplay(this); //取得设备的显示器    Ticker ticker = new Ticker("使用J2ME设计无线网络应用程序"); // 创建滚动条    form.setTicker(ticker); // 把滚动条加到表单上    messageItem.setFont(Font.getFont(Font.FACE_SYSTEM,Font.STYLE_PLAIN,Font.SIZE_LARGE)); //设置显示字体    form.append(messageItem); // 把显示信息添加到表单上    form.addCommand(cancel); // 为表单加上取消命令    form.setCommandListener(this); // 为表单设置命令监听器    display.setCurrent(form); // 显示表单   }   // 重载抽象类MIDlet的抽象方法pauseApp()   protected void pauseApp() {   }   // 重载抽象类MIDlet的抽象方法destroyApp()   protected void destroyApp(boolean u) {    notifyDestroyed();   }   // 实现接口CommandListener的方法   public void commandAction(Command c, Displayable d) {    if (c == cancel) {    destroyApp(false); // 销毁程序    notifyDestroyed();    }   }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值