当前位置:网站首页>用头像模仿天狗食月
用头像模仿天狗食月
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方法
- 方法里画天空 月亮和星星 然后加载一张图片 这种图片用来覆盖月亮
- 然后不断改变图片的位置,,从而实现天狗食月的效果

️ 感谢大家
- 欢迎关注我️,点赞,评论,转发
- 关注
盼盼小课堂,定期为你推送好文,还有群聊不定期抽奖活动,可以畅所欲言,与大神们一起交流,一起学习。
边栏推荐
- Using thread class and runnable interface to realize the difference between multithreading
- Redis configuration and optimization of NoSQL
- 链表面试常见题
- 太方便了,钉钉上就可完成代码发布审批啦!
- 10 ways of interface data security assurance
- UltraEdit-32 温馨提示:右协会,取消 bak文件[通俗易懂]
- 【OA】Excel 文档生成器: Openpyxl 模块
- MySQL的存储引擎
- 如何检测mysql代码运行是否出现死锁+binlog查看
- ABAP 動態內錶分組循環
猜你喜欢

Antd Comment 递归循环评论

AVL树插入操作与验证操作的简单实现

web服务性能监控方案

QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)

Codeworks 5 questions per day (1700 average) - day 7

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

Introduction to opensea platform developed by NFT trading platform (I)

2022年上半年HIT行业TOP50

机械臂速成小指南(十):可达工作空间

Tencent cloud native database tdsql-c was selected into the cloud native product catalog of the Academy of communications and communications
随机推荐
【安全攻防】序列化与反序列,你了解多少?
Simple implementation of AVL tree insertion and verification operations
QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
ABAP Dynamic Inner table Group cycle
Que savez - vous de la sérialisation et de l'anti - séquence?
PHP implements lottery according to probability
It's too convenient. You can complete the code release and approval by nailing it!
Tflite model transformation and quantification
ggplot 分面的细节调整汇总
机械臂速成小指南(十):可达工作空间
如何编写一个程序猿另一个面试官眼前一亮的简历[通俗易懂]
MySQL的索引
史上最全学习率调整策略lr_scheduler
termux设置电脑连接手机。(敲打命令贼快),手机termux端口8022
使用 BR 备份 TiDB 集群到 GCS
AVL树插入操作与验证操作的简单实现
Kalman filter-1
接口数据安全保证的10种方式
Gpt-3 is a peer review online when it has been submitted for its own research
机器学习笔记 - 使用机器学习进行鸟类物种分类