java愛心代碼完整示例(脫單必備)
愛心代碼示例:
package com.example.test;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.jar.JarOutputStream;
import javax.swing.JFrame;
class Cardioid extends JFrame {
//定義窗口大小
private static final int WIDTH = 900;
private static final int HEIGHT = 800;
//獲取屏幕大小
private static final int WINDOW_WIDTH = Toolkit.getDefaultToolkit().getScreenSize().width;
private static final int WINDOW_HEIGHT = Toolkit.getDefaultToolkit().getScreenSize().height;
//構(gòu)造函數(shù)
public Cardioid() {
//設(shè)置窗口標(biāo)題
super("?愛心");
//設(shè)置背景色
this.setBackground(Color.BLACK);
//設(shè)置窗口位置
this.setLocation((WINDOW_WIDTH - WIDTH) / 2, (WINDOW_HEIGHT - HEIGHT) / 2);
//設(shè)置窗口大小
this.setSize(WIDTH, HEIGHT);
//設(shè)置窗口布局
this.setLayout(getLayout());
//設(shè)置窗口可見
this.setVisible(true);
//設(shè)置窗口的默認(rèn)關(guān)閉方式
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
//圖形函數(shù)
public void paint(Graphics g) {
//橫縱坐標(biāo)及半徑
double x, y, r;
//繪制圖形
double z = 0.0;
double size=10;
int jj=0;
while (true) {
Image image = this.createImage(WIDTH, HEIGHT);
Graphics pic = image.getGraphics();
if (jj%2==0){
size=14.5;
}else {
size=15;
}
for (int ii = 30; ii > 0; ii--) {
Color color = new Color(255, 175, (int) (20 * Math.random()) + 220);
for (int i = 1; i < 400; i++) {
// try {
// Thread.sleep(10);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
int px = (int) (Math.random() * 10);
int py = (int) (Math.random() * 10);
x = 16 * (Math.sin(z) * Math.sin(z) * Math.sin(z)) * (size) + Math.pow((-1), px) * Math.random() * ii * Math.sqrt(ii) + WIDTH / 2;
y = -(13 * Math.cos(z) - 5 * Math.cos(2 * z) - 2 * Math.cos(3 * z) - Math.cos(4 * z)) * (size) + Math.pow((-1), py) * Math.random() * ii * Math.sqrt(ii) + HEIGHT * 1 / 3;
z += (Math.PI / 2.0) / 80;
pic.setColor(color);
// pic.setColor(new Color(0, 255, 255));
pic.fillOval((int) x, (int) y, 2, 2);
// g.drawImage(image, 0, 0, this);
}
// if (ii < 12) {
// g.drawImage(image, 0, 0, this);
// try {
// Thread.sleep(100);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
if (ii < 3) {
pic.setFont(new Font("楷體", Font.BOLD, 40));//設(shè)置字體
pic.setColor(Color.pink);
pic.drawString("Love You", WIDTH / 2 - 100, 240);//繪制字符串
pic.drawString("Forever", WIDTH / 2, 280);//繪制字符串
g.drawImage(image, 0, 0, this);
}
}
jj++;
if (jj>100){
break;
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public class Love {
public static void main(String[] args) {
new Cardioid();
}
}結(jié)果如下:

總結(jié)
到此這篇關(guān)于java愛心代碼(脫單必備)的文章就介紹到這了,更多相關(guān)java愛心代碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
MyBatis中insert操作返回主鍵的實(shí)現(xiàn)方法
在使用MyBatis做持久層時(shí),insert語句默認(rèn)是不返回記錄的主鍵值,而是返回插入的記錄條數(shù)。這篇文章主要介紹了MyBatis中insert操作返回主鍵的方法,需要的朋友可以參考下2016-09-09
Mybatis Generator自動(dòng)生成對(duì)應(yīng)文件的實(shí)現(xiàn)方法
這篇文章主要介紹了Mybatis Generator自動(dòng)生成對(duì)應(yīng)的文件的實(shí)現(xiàn)方法,需要的朋友可以參考下2017-09-09
Java發(fā)送form-data請(qǐng)求實(shí)現(xiàn)文件上傳
這篇文章主要為大家詳細(xì)介紹了Java發(fā)送form-data請(qǐng)求實(shí)現(xiàn)文件上傳,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-06-06
Java移除無效括號(hào)的方法實(shí)現(xiàn)
本文主要介紹了Java移除無效括號(hào)的方法實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-08-08
JPA @GeneratedValue 四種標(biāo)準(zhǔn)用法TABLE,SEQUENCE,IDENTITY,
這篇文章主要介紹了@GeneratedValue 四種標(biāo)準(zhǔn)用法TABLE,SEQUENCE,IDENTITY,AUTO詳解,需要的朋友可以參考下2024-03-03

