服务器之家

服务器之家 > 正文

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

时间:2021-02-18 13:05     来源/作者:mengwei

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

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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();
    }
}
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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输出动态闪图iloveyou的全部内容,希望对大家有所帮助。如有不足之处,欢迎留言指出。

原文链接:http://blog.csdn.net/yaerfeng/article/details/54962602

标签:

相关文章

热门资讯

2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
Intellij idea2020永久破解,亲测可用!!!
Intellij idea2020永久破解,亲测可用!!! 2020-07-29
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
返回顶部