java桌面宠物swing实现
在bilibili上看到一个少前小人的桌面程序
但他是Python写的。
于是就打算自己写一个java的
csdn上也有不少的桌面宠物程序,也给我提供了很好的参考
利用swing的图片替换实现动画效果
参考文档
https://blog.csdn.net/JunyAn_Cyw/article/details/81346875
https://blog.csdn.net/Shenpibaipao/article/details/78704714
完整代码
package teacher_silence.com.gitee;
import javax.swing.*;
import java.awt.*;
import java.awt.dnd.*;
import java.awt.event.*;
public class TestBody {
private static JFrame frame;
private static JLabel jLabel;
Thread test=new Thread(new Def());
// Thread test2=new Thread(new Cli());
int flag1=1;//动作转换判断标志
// boolean flag2=true;
public TestBody(){
frame = new JFrame("digimonDesktopPet");
//设置随机位置并显示在最前端
frame.setLocation( (int)( Math.random()*100),(int)(Math.random()*100));//注意int强转时后面的括号也药带上
frame.setAlwaysOnTop(true);
// 窗体size
frame.setSize(200, 200);
// 样式
frame.getContentPane().setLayout(null);
frame.setTitle("测试动画");
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setType(JFrame.Type.UTILITY);
// 动画的承载体
setTray();
jLabel = new JLabel();
// 初始化第一张图
cgJLabelImg(jLabel,"res/default/skeleton-standing0.png");
frame.add(jLabel);
// 体透明
frame.setUndecorated(true); // 取消窗口标题栏
frame.setBackground(new Color(0,0,0,0));// 背景
frame.setVisible(true);