专属于程序员的浪漫-Java输出动态闪图iloveyou

作者:mengwei 时间:2023-12-01 16:00:57 

代码测试可用,运行结果非常辣眼睛,有种二十一世纪初流行于广大中小学生之间的失落非主流的感觉!

还是比较有参考价值的,获取当前日期时间,日期类格式化,图形界面的开发等。

java awt实现小程序动态闪图源代码例子:I Iove You,不方便截取动态图,这里仅截取png格式图以供参考,可自行测试。


package cn.ecit.iloveyou;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.util.Date;
public class ILoveYou extends Frame implements Runnable {
public ILoveYou() {
// this.setComponentZOrder(this, 2);
this.setBounds(Constant.X, Constant.Y, Constant.WIDTH, Constant.HEIGHT);
this.setTitle(Constant.string);
this.setVisible(true);
this.setBackground(Color.BLACK);
this.setExtendedState(MAXIMIZED_BOTH);
this.addWindowListener(new WindowListener() {
@Override
 public void windowOpened(WindowEvent e) {
}
@Override
 public void windowIconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
 public void windowDeiconified(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
 public void windowDeactivated(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
 public void windowClosing(WindowEvent e) {
System.exit(0);
}
@Override
 public void windowClosed(WindowEvent e) {
// TODO Auto-generated method stub
}
@Override
 public void windowActivated(WindowEvent e) {
// TODO Auto-generated method stub
}
}
);
}
public void paint(Graphics g) {
for (int i = 0; i < 500; i++) {
g.setColor(new Color((int) (Math.random() * 256), (int) (Math
  .random() * 256), (int) (Math.random() * 256)));
g.drawString("★", (int) (Math.random() * 1366), (int) (Math
  .random() * 768));
}
g.setFont(new Font("微软雅黑", Font.BOLD, 150));
g.drawString(Constant.string, Constant.X - 80, Constant.Y + 250);
g.setColor(new Color((int) (Math.random() * 256),
 (int) (Math.random() * 256), (int) (Math.random() * 256)));
g.drawString(new Date().toLocaleString(), 5, 200);
g.setColor(new Color((int) (Math.random() * 256),
 (int) (Math.random() * 256), (int) (Math.random() * 256)));
g.setFont(new Font("微软雅黑", Font.BOLD, 200));
g.drawString(Constant.string1, 100, 650);
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(500);
}
catch (Exception e) {
e.printStackTrace();
}
repaint();
}
}
public static void main(String[] args) {
new Thread(new ILoveYou()).start();
}
}

package cn.ecit.iloveyou;
import java.awt.Toolkit;
public class Constant {
static final int WIDTH = 800;
static final int HEIGHT = 450;
static final int X = (Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH) / 2;
static final int Y = (Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT) / 2;
static final int WIDTH_BUFF = 300;
static final int HEIGHT_BUFF = 100;
static final int X_BUFF = (WIDTH - WIDTH_BUFF) / 2;
static final int Y_BUFF = (HEIGHT - HEIGHT_BUFF) / 2;
static final String string = "I LOVE YOU !";
static final String string1 = "★ 一生一世 ★";
}

运行结果:

专属于程序员的浪漫-Java输出动态闪图iloveyou

总结

Java图形化界面设计之容器(JFrame)详解

Java实现控制台输出两点间距离

java编程基础之模仿用户登录代码分享

如有不足之处,欢迎留言指出。

来源:http://blog.csdn.net/yaerfeng/article/details/54962602

标签:java,获取当前日期,动态图
0
投稿

猜你喜欢

  • C++ pair的用法案例详解

    2021-09-21 01:40:20
  • Java 实战范例之校园二手市场系统的实现

    2023-06-10 12:52:17
  • SpringBoot中dubbo+zookeeper实现分布式开发的应用详解

    2023-09-13 19:04:45
  • Java8中Lambda表达式使用和Stream API详解

    2022-04-27 13:25:23
  • Unity打包代码到DLL的实现

    2022-06-28 08:38:17
  • C# 获取属性名的方法

    2023-03-05 07:02:18
  • java实现简单的俄罗斯方块

    2021-08-02 18:13:11
  • 使用工具类-java精确到小数点后6位

    2021-06-24 20:45:39
  • VS2019配置OpenCV4.1.0详细教程与测试代码(推荐)

    2021-11-06 21:55:24
  • SpringBoot结合Vue实现投票系统过程详解

    2022-08-24 16:12:30
  • c# 颜色选择控件的实现代码

    2022-04-27 07:22:58
  • 浅谈EventBus

    2022-12-31 20:23:14
  • Android开发AsmClassVisitorFactory使用详解

    2023-07-22 05:34:53
  • java反射应用详细介绍

    2022-06-14 04:59:45
  • C#(asp.net)多线程用法示例(可用于同时处理多个任务)

    2022-03-09 01:41:30
  • Java持久层框架MyBatis简单实例

    2023-01-09 08:43:16
  • C# Winform 实现屏蔽键盘的win和alt+F4的实现代码

    2021-07-01 11:48:18
  • Java虚拟机内存结构及编码实战分享

    2023-11-29 13:47:47
  • Android 通过TCP协议上传指定目录文件的方法

    2023-11-07 23:34:11
  • JavaWeb建立简单三层项目步骤图解

    2023-03-08 16:51:02
  • asp之家 软件编程 m.aspxhome.com