当前位置:网站首页>Imitate Tengu eating the moon with Avatar
Imitate Tengu eating the moon with Avatar
2022-07-07 04:04:00 【InfoQ】
Use the avatar to imitate Tengu eating the moon
import lombok.extern.slf4j.Slf4j;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.*;
/**
* @Author xiepanpan
* @Description // Eat the moon
* @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){
// The abscissa of the avatar keeps increasing
// So close to the moon and away from , Cause the effect of heavenly dog eating the moon
for (int i=0;i<1024;i++){
x++;
if(x>1024){
x=0;
}
}
try {
// Let the thread sleep 10 millisecond
Thread.sleep(10);
}
catch (InterruptedException e) {
log.info("",e);
}
// Automatically refresh the screen , call paint() Method
repaint();
}
}
}
.start();
}
/*
* @Author xiepanpan
* @Description // Start drawing
* @Date 9:01 2021/9/8
* @Param [g]
* @return void
**/
public void paint(Graphics g){
super.paint(g);
// Sky Color
this.setBackground(Color.BLACK);
// Love stars
g.setColor(Color.RED);
for (int i = 0; i < 20; i++) {
g.drawString("", (int) (Math.random() * 1024), (int) (Math.random() * 768));
}
// The moon
g.setColor(Color.yellow);
g.fillArc(500, 100, 200, 200, 0, 360);
ImageIcon icon = new ImageIcon("D:\\1.png");
// Set the avatar to cover the moon
g.drawImage(icon.getImage(),x,100,200,200,this);
}
}
import javax.swing.JFrame;
/**
* @Author xiepanpan
* @Description // start-up
* @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);
}
}
- Create a new class inheritance Jpanel Rewrite its paint Method
- Draw the sky in the method The moon and stars Then load a picture This picture is used to cover the moon
- Then constantly change the position of the picture ,, So as to achieve the effect of Tengu eating the moon
️ Thank you for your
- Welcome to follow me ️, give the thumbs-up , Comment on , forward
- Focus on
Panpan small class
, Push good articles for you regularly , There are also group chat and irregular lottery activities , You can say what you want , Communicate with the great gods , Learning together .
边栏推荐
- QT 使用QToolTip 鼠标放上去显示文字时会把按钮的图片也显示了、修改提示文字样式
- OSCP工具之一: dirsearch用法大全
- 机器学习笔记 - 使用机器学习进行鸟类物种分类
- [dpdk] dpdk sample source code analysis III: dpdk-l3fwd_ 001
- 运算放大器应用汇总1
- ABAP dynamic inner table grouping cycle
- 机械臂速成小指南(十):可达工作空间
- Mobile measurement and depth link platform - Branch
- Confirm the future development route! Digital economy, digital transformation, data This meeting is very important
- Restore backup data on GCS with br
猜你喜欢
Simple implementation of AVL tree insertion and verification operations
ABAP 動態內錶分組循環
Class常量池与运行时常量池
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
API data interface of A-share index component data
【OA】Excel 文档生成器: Openpyxl 模块
opencv第三方库
用头像模仿天狗食月
Implementation steps of docker deploying mysql8
Mysql-数据丢失,分析binlog日志文件
随机推荐
Tflite model transformation and quantification
如何编写一个程序猿另一个面试官眼前一亮的简历[通俗易懂]
NoSQL之Redis配置与优化
使用Thread类和Runnable接口实现多线程的区别
Binary, octal, hexadecimal
[leetcode] 700 and 701 (search and insert of binary search tree)
The JSON format of the international area code of the mobile phone number is obtained with PHP
QT 项目 表格新建列名称设置 需求练习(找数组消失的数字、最大值)
Implementation of map and set
维护万星开源向量数据库是什么体验
Summer 2022 daily question 1 (1)
Redis configuration and optimization of NoSQL
机器学习笔记 - 使用机器学习进行鸟类物种分类
cuda编程
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
Hisilicon 3559 universal platform construction: RTSP real-time playback support
map和set的实现
Kalman filter-1
【刷题记录】2. 两数相加
什么是 CGI,什么是 IIS,什么是VPS「建议收藏」