專屬于程序員的浪漫-Java輸出動態(tài)閃圖iloveyou
代碼測試可用,運行結果非常辣眼睛,有種二十一世紀初流行于廣大中小學生之間的失落非主流的感覺!
還是比較有參考價值的,獲取當前日期時間,日期類格式化,圖形界面的開發(fā)等。
java awt實現(xiàn)小程序動態(tài)閃圖源代碼例子:I Iove You,不方便截取動態(tài)圖,這里僅截取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輸出動態(tài)閃圖iloveyou的全部內(nèi)容,希望對大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:
如有不足之處,歡迎留言指出。
相關文章
SpringBoot中@Conditional注解的介紹及實踐
在 Spring Boot 中,@Conditional 注解用于實現(xiàn) 條件化 Bean 裝配,本文將詳細介紹 @Conditional 相關的注解,并結合實際應用示例講解其使用方式,感興趣的小伙伴可以了解下2025-03-03
Spring?Retry?實現(xiàn)樂觀鎖重試實踐記錄
本文介紹了在秒殺商品SKU表中使用樂觀鎖和MybatisPlus配置樂觀鎖的方法,并分析了測試環(huán)境和生產(chǎn)環(huán)境的隔離級別對樂觀鎖的影響,通過簡單驗證,展示了在可重復讀和讀已提交隔離級別下的不同行為,感興趣的朋友一起看看吧2025-03-03
Java8新的異步編程方式CompletableFuture實現(xiàn)
這篇文章主要介紹了Java8新的異步編程方式CompletableFuture實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-04-04
Java中import java.util.Scanner的用處詳解
文章主要介紹Java中的Scanner類及其常用方法next()和nextLine()的區(qū)別,next()方法在遇到空格、Tab鍵、回車鍵等分隔符時結束輸入,而nextLine()方法則接收所有輸入,直到遇到回車鍵2024-11-11

