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

️ 感谢大家
- 欢迎关注我️,点赞,评论,转发
- 关注
盼盼小课堂
,定期为你推送好文,还有群聊不定期抽奖活动,可以畅所欲言,与大神们一起交流,一起学习。
边栏推荐
- QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
- UltraEdit-32 温馨提示:右协会,取消 bak文件[通俗易懂]
- Operational amplifier application summary 1
- MySQL storage engine
- [leetcode]Spiral Matrix II
- 运算放大器应用汇总1
- 2022年上半年HIT行业TOP50
- VHDL implementation of arbitrary size matrix addition operation
- Top 50 hit industry in the first half of 2022
- ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
猜你喜欢
tflite模型转换和量化
Top 50 hit industry in the first half of 2022
codeforces每日5题(均1700)-第七天
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
When QT uses qtooltip mouse to display text, the picture of the button will also be displayed and the prompt text style will be modified
机械臂速成小指南(十):可达工作空间
Docker部署Mysql8的实现步骤
Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
idea gradle lombok 报错集锦
Codeworks 5 questions per day (1700 average) - day 7
随机推荐
中青杯2022A题高校数学建模竞赛与课程教育思路分析
Using thread class and runnable interface to realize the difference between multithreading
Web service performance monitoring scheme
Arduino droplet detection
MySQL的存储引擎
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
golang 根据生日计算星座和属相
SSL certificate deployment
自适应非欧表征广告检索系统AMCAD
2022电工杯A题高比例风电电力系统储能运行及配置分析思路
Storage of data
First understand the principle of network
【安全攻防】序列化与反序列,你了解多少?
The JSON format of the international area code of the mobile phone number is obtained with PHP
Calculation of time and space complexity (notes of runners)
Free PHP online decryption tool source code v1.2
The most complete learning rate adjustment strategy in history LR_ scheduler
Mobile measurement and depth link platform - Branch
Implementation steps of docker deploying mysql8
OSCP工具之一: dirsearch用法大全