java awt 代码_java awt实现小程序动态闪图源代码例子下载:I Iove You

java awt实现小程序动态闪图源代码例子下载:I Iove You,请看图片!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 = "★ 一生一世 ★";

}

5f44669d9023f819b9cfa4031178418d.png

官方验证:

代码可以运行,大家可以放心下载。

由最代码官方编辑于2017-2-10 9:25:58

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值