edit_note帖子
214
stars积分
13,626
event加入
2011-12-10
电脑网络
对不起,发一个我自己用java编写的东西【附视频教程】!
schedule发表于 2013-11-20 12:55:00
visibility查看 707
chat_bubble回复 6
#1 楼主
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);
}
}
}
只要把图片名字自己修改就行!很简单的!
估计也没多少人会去学!唉。。
再说一次“对不起”!!!!
{
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);
}
}
}
只要把图片名字自己修改就行!很简单的!
估计也没多少人会去学!唉。。
再说一次“对不起”!!!!
全部回复 (6)
2013-11-20 13:11:00
沙发
支持
2013-11-20 13:16:00
板凳
我们日常在电脑用最好用的软件,玩最好玩游戏,手机也是,都是离不开程序,当然要懂得编写程序才可以的,所以,不懂程序的你想找师傅就找对了,他就是编程狂人。
2013-11-20 13:20:00
地板
虽然看的不懂吧。。嘿嘿。支持!
2013-11-20 13:32:00
#5
同二楼!
2013-11-20 23:33:00
#6
看上去好深奥的样纸!赞一个
2013-12-02 09:05:00
#7
刚开始学java
登录 后才能回复
flag举报帖子