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

️ 感谢大家
- 欢迎关注我️,点赞,评论,转发
- 关注
盼盼小课堂,定期为你推送好文,还有群聊不定期抽奖活动,可以畅所欲言,与大神们一起交流,一起学习。
边栏推荐
- golang 压缩和解压zip文件
- The JSON format of the international area code of the mobile phone number is obtained with PHP
- 三重半圆环进度条,直接拿去就能用
- Mysql-数据丢失,分析binlog日志文件
- Some thoughts on cross end development of kbone and applet
- SQL injection -day15
- My brave way to line -- elaborate on what happens when the browser enters the URL
- QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
- MySQL storage engine
- API data interface of A-share index component data
猜你喜欢

QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式

【系统管理】清理任务栏的已删除程序的图标缓存

What is Ba? How about Ba? What is the relationship between Ba and Bi?

25. (ArcGIS API for JS) ArcGIS API for JS line modification line editing (sketchviewmodel)

概率论公式

QT opens a file and uses QFileDialog to obtain the file name, content, etc

Operational amplifier application summary 1

维护万星开源向量数据库是什么体验

Mysql-数据丢失,分析binlog日志文件

API data interface of A-share index component data
随机推荐
浅谈网络安全之文件上传
ABAP Dynamic Inner table Group cycle
Create commonly used shortcut icons at the top of the ad interface (menu bar)
Arduino droplet detection
Index of MySQL
Web service performance monitoring scheme
你心目中的数据分析 Top 1 选 Pandas 还是选 SQL?
Class constant pool and runtime constant pool
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)
[leetcode] 450 and 98 (deletion and verification of binary search tree)
On file uploading of network security
Mysql-数据丢失,分析binlog日志文件
Kotlin Android 环境搭建
easyui出口excel无法下载框弹出的办法来解决
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
MySQL的索引
杭州电 3711 Binary Number
QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
web服务性能监控方案
22. (ArcGIS API for JS) ArcGIS API for JS Circle Collection (sketchviewmodel)