public class XiaoLei extends JFrame
{
static int sizex = 50;
static int sizey = 50;
JPanel jPanel= new JPanel(new BorderLayout());
public XiaoLei(String name)
{
ImageIcon imgpIcon = new ImageIcon(name);
JLabel img = new JLabel(imgpIcon);
jPanel.add(img);
this.add(jPanel);
this.setUndecorated(true);//设置没有标题栏
this.setVisible(true);
this.setSize(sizex, sizey);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setAlwaysOnTop(true);//设置窗口最前
}
public static void main(String[] args)
{
run1 run1 = new run1(new XiaoLei(“1“));/*传入图片文件 1 */
Thread xiao1 = new Thread(run1);
run1 run2 = new run1(new XiaoLei(“2“));/*传入图片文件 2 */
Thread xiao2 = new Thread(run2);
// run1 run3 = new run1(new XiaoLei(“3“));
// Thread xiao3 = new Thread(run3);
// run1 run2 = new run1(new XiaoLei());
// Thread xiao3 = new Thread(run2);
/*这是我用java编写的窗口飘动的程序,这是效果图,就是两个任意的图片,在窗口上飘动,当然,也可以自己添加*/
xiao1.start();
xiao2.start();
// xiao3.start();
}
}
public class run1 implements Runnable
{
XiaoLei xiaoLei;
public run1(XiaoLei xiaoLei)
{
this.xiaoLei = xiaoLei;
}
@Override
public void run()
{
mov(xiaoLei);
}
public static void mov(XiaoLei xiaoLei)
{
System.out.println();
int x = (int)(Math.random()*1000),y = (int)(Math.random()*1000);
boolean x1 =false;
boolean y1 = false;
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
while(true)
{
try
{
Thread.sleep(10);
}catch(Exception e)
{
}
if(x >= dim.width-xiaoLei.getSize().width)
{
x1 = true;
}
if(y >= dim.height-xiaoLei.getSize().height)
{
y1 = true;
}
if(x <= 1)
{
x1 = false;
}
if( y<= 1)
{
y1 = false;
}
if(x1)
{
x -= 2;
}
if(!x1)
{
x+= 1;
}
if(y1)
{
y -= 2;
}
if(!y1)
{
y+= 1;
}
xiaoLei.setLocation(x, y);
}
}
}
只要把图片名字自己修改就行!很简单的!
估计也没多少人会去学!唉。。
再说一次“对不起”!!!!

























