专属于程序员的浪漫-Java输出动态闪图iloveyou
程序员文章站
2023-12-16 21:40:16
代码测试可用,运行结果非常辣眼睛,有种二十一世纪初流行于广大中小学生之间的失落非主流的感觉!
还是比较有参考价值的,获取当前日期时间,日期类格式化,图形界面的开发等。...
代码测试可用,运行结果非常辣眼睛,有种二十一世纪初流行于广大中小学生之间的失落非主流的感觉!
还是比较有参考价值的,获取当前日期时间,日期类格式化,图形界面的开发等。
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的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站:
如有不足之处,欢迎留言指出。