這篇文章將為大家詳細(xì)講解有關(guān)Java如何輸出動(dòng)態(tài)閃圖iloveyou,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
我們提供的服務(wù)有:做網(wǎng)站、網(wǎng)站設(shè)計(jì)、微信公眾號(hào)開(kāi)發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、金鳳ssl等。為1000多家企事業(yè)單位解決了網(wǎng)站和推廣的問(wèn)題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的金鳳網(wǎng)站制作公司
代碼測(cè)試可用,運(yùn)行結(jié)果非常辣眼睛,有種二十一世紀(jì)初流行于廣大中小學(xué)生之間的失落非主流的感覺(jué)!
還是比較有參考價(jià)值的,獲取當(dāng)前日期時(shí)間,日期類格式化,圖形界面的開(kāi)發(fā)等。
java awt實(shí)現(xiàn)小程序動(dòng)態(tài)閃圖源代碼例子:I Iove You,不方便截取動(dòng)態(tài)圖,這里僅截取png格式圖以供參考,可自行測(cè)試。
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 = "★ 一生一世 ★"; }
運(yùn)行結(jié)果:
關(guān)于“Java如何輸出動(dòng)態(tài)閃圖iloveyou”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。