专属于程序员的浪漫

网友投稿 261 2023-03-15


专属于程序员的浪漫

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

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

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 exhttp://tends 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++) {

gMzazw.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 = "★ 一生一世 ★Mzazw";

}

运行结果:

总结

以上就是本文关于专属于程序员的浪漫-Java输出动态闪图iloveyou的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:

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

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

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

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


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:java接口对接开发实例(java对外接口开发实例)
下一篇:深入理解Vue官方文档梳理之全局API
相关文章

 发表评论

暂时没有评论,来抢沙发吧~