当前位置:网站首页>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 .
边栏推荐
猜你喜欢
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
It's too convenient. You can complete the code release and approval by nailing it!
用头像模仿天狗食月
Docker部署Mysql8的实现步骤
数据的存储
List interview common questions
NoSQL之Redis配置与优化
Antd Comment 递归循环评论
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
Ggplot facet detail adjustment summary
随机推荐
What is Ba? How about Ba? What is the relationship between Ba and Bi?
力扣------路径总和 III
cuda编程
未来发展路线确认!数字经济、数字化转型、数据...这次会议很重要
Redis source code learning (30), dictionary learning, dict.h
List interview common questions
Free PHP online decryption tool source code v1.2
QT 打开文件 使用 QFileDialog 获取文件名称、内容等
ERROR: Could not build wheels for pycocotools which use PEP 517 and cannot be installed directly
【OA】Excel 文档生成器: Openpyxl 模块
[leetcode]Spiral Matrix II
Kotlin Android environment construction
On file uploading of network security
Mobile measurement and depth link platform - Branch
史上最全MongoDB之安全认证
easyui出口excel无法下载框弹出的办法来解决
[development software] tilipa Developer Software
Enter the rough outline of the URL question (continuously updated)
如何编写一个程序猿另一个面试官眼前一亮的简历[通俗易懂]
学习使用js把两个对象合并成一个对象的方法Object.assign()