Java实现动态雪花、心形图案、炫动字体
发布日期:2021-05-10 03:26:58 浏览次数:16 分类:精选文章

本文共 3444 字,大约阅读时间需要 11 分钟。

������������������������������������������

Java������������������������������������������������������

������������������Java���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������Swing������������������������������������������������������������������������������������������������������������������������������������

������������������

���������������������������������������Swing������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������������������

������������������������������������������

package uu;import java.awt.Color;import java.awt.Graphics;import java.awt.Font;import java.awt.Image;import javax.swing.JFrame;import javax.swing.JPanel;import java.util.Random;public class u {      public static void main(String[] args) {          JFrame frame = new JFrame();          frame.setSize(800, 600);        frame.setLocationRelativeTo(null);        frame.setDefaultCloseOperation(3);        frame.setBackground(Color.BLACK);        MyPanel p = new MyPanel();        frame.add(p);        frame.setVisible(true);        Thread t = new Thread(p);        t.start();    }}class MyPanel extends JPanel implements Runnable {    private static final long serialVersionUID = 1L;    Font font = new Font("font", Font.BOLD, 50);    String[] colors = {"red", "yellow", "blue"};    Random random = new Random();    int[] snowx = new int[600];    int[] snowy = new int[600];    public MyPanel() {        for (int i = 0; i < 600; i++) {            snowx[i] = random.nextInt(800);            snowy[i] = random.nextInt(600);        }    }    public void snowspaint(Graphics g) {        g.setColor(Color.WHITE);        for (int i = 0; i < 600; i++) {            g.drawString("*", snowx[i], snowy[i]);            for (int j = -1; j < 1; j++) {                g.rotate(g, snowx[i] + j, snowy[i] + j, 30, Color.WHITE);            }        }    }    public void run() {        while (true) {            try {                Thread.sleep(40);                Graphics g = this.getGraphics();                snowspaint(g);                g.dispose();            } catch (InterruptedException e) {                e.printStackTrace();            }        }    }}

������������������������

  • ���������������������������������������������������������������������������������������������������������������������
  • ���������������������������������������������������������������������������������������������������������������������������������������������������������������
  • ������������������������������������������������������������������������������������
  • ������������������

    ������������������������������Swing���������������������������������������������������������������40ms���������������������������������������������������������������������

    • ���������������������������colors������������������������������������������������������
    • ���������������������������������������������������������������������������������
    • ���������������������������������������������������������������������������
    • ������������������������������������������������������������������������������

    ���������������������������������������������������������������������������������������������������������������

    上一篇:AttributeError: module ‘torch‘ has no attribute ‘gesv‘
    下一篇:mysql使用use关键字使用、切换数据库

    发表评论

    最新留言

    路过按个爪印,很不错,赞一个!
    [***.219.124.196]2025年04月12日 23时57分02秒