当前位置:网站首页>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 .
边栏推荐
- The true face of function pointer in single chip microcomputer and the operation of callback function
- [leetcode] 700 and 701 (search and insert of binary search tree)
- 机械臂速成小指南(十):可达工作空间
- API data interface of A-share index component data
- 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
- Antd comment recursive loop comment
- 二进制、八进制、十六进制
- 什么是 CGI,什么是 IIS,什么是VPS「建议收藏」
- 机器学习笔记 - 使用机器学习进行鸟类物种分类
- 【安全攻防】序列化与反序列,你了解多少?
猜你喜欢
![[security attack and Defense] how much do you know about serialization and deserialization?](/img/1c/e5ae74e65bacf688d7f61cc1b71d3e.png)
[security attack and Defense] how much do you know about serialization and deserialization?

PHP lightweight Movie Video Search Player source code

2022夏每日一题(一)

太方便了,钉钉上就可完成代码发布审批啦!

Free PHP online decryption tool source code v1.2

QT item table new column name setting requirement exercise (find the number and maximum value of the array disappear)

2022年电工杯B 题 5G 网络环境下应急物资配送问题思路分析

tflite模型转换和量化

Summer 2022 daily question 1 (1)

【安全攻防】序列化与反序列,你了解多少?
随机推荐
2022夏每日一题(一)
用头像模仿天狗食月
Implementation of map and set
Storage of data
List interview common questions
【编码字体系列】OpenDyslexic字体
Codeworks 5 questions per day (1700 average) - day 7
Binary, octal, hexadecimal
2022年电工杯B 题 5G 网络环境下应急物资配送问题思路分析
[MySQL] row sorting in MySQL
cuda编程
【安全攻防】序列化与反序列,你了解多少?
Preprocessing - interpolation
POJ培训计划2253_Frogger(最短/floyd)
复杂因子计算优化案例:深度不平衡、买卖压力指标、波动率计算
golang 压缩和解压zip文件
Enter the rough outline of the URL question (continuously updated)
codeforces每日5题(均1700)-第七天
Baidu map JS development, open a blank, bmapgl is not defined, err_ FILE_ NOT_ FOUND
Leetcode: interview question 17.24 Maximum cumulative sum of submatrix (to be studied)