当前位置:网站首页>用头像模仿天狗食月
用头像模仿天狗食月
2022-07-06 21:33:00 【InfoQ】
用头像模仿天狗食月
import lombok.extern.slf4j.Slf4j;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
/**
* @Author xiepanpan
* @Description //吃月亮
* @Date 9:05 2021/9/8
* @Param
* @return
**/
@Slf4j
public class XppMoonPanel extends JPanel{
int x=700;
public void startRun(){
new Thread(){
public void run(){
while(true){
//头像的横坐标坐标不断自增
//这样去接近月亮和远离,造成天狗食月的效果
for (int i=0;i<1024;i++){
x++;
if(x>1024){
x=0;
}
}
try {
//让线程休眠10毫秒
Thread.sleep(10);
}
catch (InterruptedException e) {
log.info("",e);
}
//自动刷新屏幕,调用paint()方法
repaint();
}
}
}
.start();
}
/*
* @Author xiepanpan
* @Description //开始画
* @Date 9:01 2021/9/8
* @Param [g]
* @return void
**/
public void paint(Graphics g){
super.paint(g);
//天空颜色
this.setBackground(Color.BLACK);
//爱心星空
g.setColor(Color.RED);
for (int i = 0; i < 20; i++) {
g.drawString("", (int) (Math.random() * 1024), (int) (Math.random() * 768));
}
//月亮
g.setColor(Color.yellow);
g.fillArc(500, 100, 200, 200, 0, 360);
ImageIcon icon = new ImageIcon("D:\\1.png");
//设置头像将去覆盖月亮
g.drawImage(icon.getImage(),x,100,200,200,this);
}
}
import javax.swing.JFrame;
/**
* @Author xiepanpan
* @Description //启动
* @Date 9:06 2021/9/8
* @Param
* @return
**/
public class XppMoonFrame {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(1024, 768);
frame.setLocation(100, 100);
XppMoonPanel panel = new XppMoonPanel();
frame.add(panel);
panel.startRun();
frame.setVisible(true);
}
}
- 新建一个类继承Jpanel 重写它的paint方法
- 方法里画天空 月亮和星星 然后加载一张图片 这种图片用来覆盖月亮
- 然后不断改变图片的位置,,从而实现天狗食月的效果

️ 感谢大家
- 欢迎关注我️,点赞,评论,转发
- 关注
盼盼小课堂,定期为你推送好文,还有群聊不定期抽奖活动,可以畅所欲言,与大神们一起交流,一起学习。
边栏推荐
- Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
- 【mysql】mysql中行排序
- Redis源码学习(30),字典学习,dict.h
- 使用切面实现记录操作日志
- 1.19.11.SQL客户端、启动SQL客户端、执行SQL查询、环境配置文件、重启策略、自定义函数(User-defined Functions)、构造函数参数
- QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
- 二叉搜索树的实现
- 机器学习笔记 - 使用机器学习进行鸟类物种分类
- Kalman filter-1
- Antd Comment 递归循环评论
猜你喜欢

Redis configuration and optimization of NoSQL

VHDL implementation of single cycle CPU design

机器学习笔记 - 使用机器学习进行鸟类物种分类

It's too convenient. You can complete the code release and approval by nailing it!

Operational amplifier application summary 1

Ggplot facet detail adjustment summary

List interview common questions

idea gradle lombok 报错集锦

Kotlin Android environment construction

Gpt-3 is a peer review online when it has been submitted for its own research
随机推荐
Introduction to opensea platform developed by NFT trading platform (I)
VHDL implementation of arbitrary size matrix multiplication
tflite模型转换和量化
MySQL的索引
使用 BR 备份 TiDB 集群到 GCS
Native MySQL
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
Web service performance monitoring scheme
Que savez - vous de la sérialisation et de l'anti - séquence?
机械臂速成小指南(十):可达工作空间
力扣------路径总和 III
HW notes (II)
什么是 CGI,什么是 IIS,什么是VPS「建议收藏」
Class常量池与运行时常量池
使用 TiDB Lightning 恢复 GCS 上的备份数据
Probability formula
使用切面实现记录操作日志
Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
OSCP工具之一: dirsearch用法大全
leetcode:面试题 17.24. 子矩阵最大累加和(待研究)