当前位置:网站首页>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 .
边栏推荐
- Class constant pool and runtime constant pool
- Redis源码学习(31),字典学习,dict.c(一)
- 运算放大器应用汇总1
- Allow public connections to local Ruby on Rails Development Server
- OSCP工具之一: dirsearch用法大全
- 复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
- map和set的实现
- opencv第三方库
- The JSON format of the international area code of the mobile phone number is obtained with PHP
- Use br to back up tidb cluster to GCS
猜你喜欢
随机推荐
Do you choose pandas or SQL for the top 1 of data analysis in your mind?
史上最全MongoDB之Mongo Shell使用
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
Preprocessing - interpolation
[leetcode] 450 and 98 (deletion and verification of binary search tree)
Antd comment recursive loop comment
Construction of Hisilicon universal platform: color space conversion YUV2RGB
杭州电 3711 Binary Number
cuda编程
Docker部署Mysql8的实现步骤
GPT-3当一作自己研究自己,已投稿,在线蹲一个同行评议
Mysql-数据丢失,分析binlog日志文件
SQL injection -day15
Kbone与小程序跨端开发的一些思考
MySQL data loss, analyze binlog log file
使用 Dumpling 备份 TiDB 集群数据到 GCS
Restore backup data on GCS with br
2022年上半年HIT行业TOP50
NoSQL之Redis配置与优化