使用Java做一个走马灯,源代码?

}}网上帮你找的 跑马灯 你可以使用 Timer 也可以使用线程 间隔多少毫秒移动一段距离 实现起来其实也不难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 JFr...
使用Java做一个走马灯,源代码?
显示时间:
<script language=javascript>
todayDate=new Date
date=todayDate.getDate()
month=todayDate.getMonth()+1
year=todayDate.getYear()
document.write("今天是")
document.write(" ")
document.write(year)
document.write("年")
document.write(month)
document.write("月")
document.write(date)
document.write("日")
document.write(" ")
if (todayDate.getDay()==0) document.write("星期日")
if (todayDate.getDay()==1) document.write("星期一")
if (todayDate.getDay()==2) document.write("星期二")
if (todayDate.getDay()==3) document.write("星期三")
if (todayDate.getDay()==4) document.write("星期四")
if (todayDate.getDay()==5) document.write("星期五")
if (todayDate.getDay()==6) document.write("星期六")
</script>
至于走马灯有好几种我不知道你需要的哪一种!2011-01-03
import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.HeadlessException;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent; import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JViewport;import javax.swing.Timer; public class Test84 extends JFrame { private Timer timer; private JLabel view; private JViewport window; public static void main(String[] args) { JFrame frm = new Test84("跑马灯"); frm.setDefaultCloseOperation(EXIT_ON_CLOSE); frm.pack(); frm.setVisible(true); } public Test84(String title) throws HeadlessException { super(title); initComponents(); addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { anchor = new Point(); anchor.x = -window.getExtentSize().width; timer.start(); } }); timer = new Timer(100, new ActionListener() { public void actionPerformed(ActionEvent e) { animate(); } }); timer.setInitialDelay(0); } private void initComponents() { String s = JOptionPane.showInputDialog(null, "请输入要实现效果的文字:"); view = new JLabel(s); view.setFont(Font.decode("Dialog-BOLD-36")); view.setForeground(Color.BLUE); window = new JViewport(); window.setView(view); getContentPane().add(window); } Point anchor; private void animate() { Dimension extSize = window.getExtentSize(); Dimension viewSize = view.getPreferredSize(); anchor.x += 5;//设置移动的速度 window.setViewPosition(anchor); if (anchor.x > viewSize.width) anchor.x = -extSize.width; }}2015-12-16
网上帮你找的 跑马灯 你可以使用 Timer 也可以使用线程 间隔多少毫秒移动一段距离 实现起来其实也不难
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.add(label, BorderLayout.SOUTH);
frame.setVisible(true);

}

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

}2010-12-31
mengvlog 阅读 10 次 更新于 2025-07-19 19:12:41 我来答关注问题0
  • import java.awt.Color;import java.awt.Dimension;import java.awt.Font;import java.awt.HeadlessException;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentAdapter;import java.awt.event.ComponentEvent; import javax.swing....

  •  湖北倍领科技 代码是什么意思

    什么是代码?源代码是指用汇编语言和高级语言编写的程序。目标代码则是源代码经编译程序转换为CPU可直接识别的二进制代码。可执行代码是将目标代码连接后形成的二进制可执行文件。在最直观的意义上,源文件是指源代码的集合,而源代码则是一组具有特定意义的字符,用于实现特定功能。网页的源文件即为网...

  •  rich556677 嵌入式题目2 带开关LED走马灯: 1、程序启动时,实验箱上的八个指示灯循环亮灭,灯亮和灯灭的时间均为1S。

    1、设计一个电路,输出8位数据,每一位表示灯的状态。1,亮,0灭 2、按下键时,布尔值取反,判断是1时,第一个灯亮,然后开始计时,1S后关1灯,亮2灯,依次 做,至到再按下键,布尔值取反,判断0时,灯全灭。第交1S后循环移动一位,输出,当灭灯时全输出0,哈哈哈,

  •  昆明北大青鸟 北大青鸟java培训:web前端编程开发都需要注意哪些问题?

    1.路由变化页面数据不刷新问题出现这种情况是因为依赖路由的params参数获取写在created生命周期里面,因为相同路由二次甚至多次加载的关系没有达到,退出页面再进入另一个文章页面并不会运行created组件生命周期,导致文章数据还是一次进入的数据。解决方法:watch路由是否变化。2.setInterval路由跳转继续运行并没有...

  • 源代码就是用汇编语言和高级语言写出来的地代码。目标代码是指源代码经过编译程序产生的能被cpu直接识别二进制代码。可执行代码就是将目标代码连接后形成的可执行文件,当然也是二进制的。2.最直观的概念 在这个网页上右键鼠标,选择查看源文件.出来一个记事本,里面的内容就是此网页的源代码.关于两者的...

檬味博客在线解答立即免费咨询

Java相关话题

Copyright © 2023 WWW.MENGVLOG.COM - 檬味博客
返回顶部