循环显示图片问题 setSize(400,300);show();放在One的构造函数中,循环显示还要大改. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 怎么改?那为什么我向CMD输出数字 就可以? import javax.swing.*;import java.awt.*;class One extends JFrame{ JLabel jj; JPanel pp; public One() { jj=new JLabel(); pp=new JPanel(); pp.add(jj); Container cc=getContentPane(); cc.add(pp); setSize(400,300); show(); } void display(ImageIcon n) { for(int i=0;i<100;i++) { try { jj.setIcon(n); Thread.sleep(10); } catch(InterruptedException e) {} } } /*public static void main(String args[]) { One rr=new One(); rr.setSize(400,300); rr.show(); }*/}class Two implements Runnable{ ImageIcon nnn; Thread t; static One one=new One(); public Two(ImageIcon n) { nnn=n; //one=new One(); t=new Thread(this); t.start(); } public void run() { //synchronized(one) //{ one.display(nnn); //} } public static void main(String args[]) { ImageIcon aa=new ImageIcon("1.gif"); ImageIcon bb=new ImageIcon("2.gif"); ImageIcon cc=new ImageIcon("3.gif"); Two t1=new Two(aa); Two t2=new Two(bb); Two t3=new Two(cc); }}//看一看 你这个也不行,虽然能够出结果,但是结果不稳定,有错!我这里有一个以前做的,可以参考!/** *author FuTao */import javax.swing.*;import java.awt.*;public class TestThreadImage extends Thread{ JFrame jFrame; JPanel jPanel; JLabel jLabel; ImageIcon imageIcon[]; int a; public TestThreadImage() { a=0; imageIcon = new ImageIcon[3] ; imageIcon[0] = new ImageIcon("1.JPG"); imageIcon[1] = new ImageIcon("2.GIF"); imageIcon[2] = new ImageIcon("3.GIF"); jFrame = new JFrame(); jPanel = new JPanel(); jLabel = new JLabel(""); jPanel.add(jLabel); jFrame.getContentPane().add(jPanel); jFrame.setSize(200,200); jFrame.setVisible(true); } public void run() { while(true) { if(a<3) { jLabel.setIcon(imageIcon[a]); a++; } else a=0; try { sleep(1000); }catch(InterruptedException e){} } } public void dis() { this.start(); } public static void main(String args[]) { TestThreadImage testThreadImage = new TestThreadImage(); testThreadImage.dis(); }} 我是想用同步实现的 没了synchronized就不能叫同步了吧用同步怎么实现啊? 高手们,java的内嵌机制指的是什么啊? 关于setBounds()方法代码放置位置和图片的读入问题~! Java JPanel问题 利用多态机制时,Java虚拟机的内存情况如何? java 里的 “<<“ 是什莫意思? 有关于jfreechart的疑问 58分请教APPLET一难题,不胜感激. 高手请指点! 如何实现email和传真机的互传? 我自己测试一下,给自己加分回怎样! 极菜问题:怎样将byte[]转换成String ? 急:请教高手一个算法
那为什么我向CMD输出数字 就可以?
import java.awt.*;
class One extends JFrame
{
JLabel jj;
JPanel pp;
public One()
{
jj=new JLabel();
pp=new JPanel();
pp.add(jj);
Container cc=getContentPane();
cc.add(pp);
setSize(400,300);
show();
}
void display(ImageIcon n)
{
for(int i=0;i<100;i++)
{
try
{
jj.setIcon(n);
Thread.sleep(10);
}
catch(InterruptedException e)
{}
}
}
/*public static void main(String args[])
{
One rr=new One();
rr.setSize(400,300);
rr.show();
}*/
}
class Two implements Runnable
{
ImageIcon nnn;
Thread t;
static One one=new One();
public Two(ImageIcon n)
{
nnn=n;
//one=new One();
t=new Thread(this);
t.start();
}
public void run()
{
//synchronized(one)
//{
one.display(nnn);
//}
}
public static void main(String args[])
{
ImageIcon aa=new ImageIcon("1.gif");
ImageIcon bb=new ImageIcon("2.gif");
ImageIcon cc=new ImageIcon("3.gif");
Two t1=new Two(aa);
Two t2=new Two(bb);
Two t3=new Two(cc);
}
}
//看一看
*author FuTao
*/
import javax.swing.*;
import java.awt.*;
public class TestThreadImage extends Thread
{
JFrame jFrame;
JPanel jPanel;
JLabel jLabel;
ImageIcon imageIcon[];
int a;
public TestThreadImage()
{
a=0;
imageIcon = new ImageIcon[3] ;
imageIcon[0] = new ImageIcon("1.JPG");
imageIcon[1] = new ImageIcon("2.GIF");
imageIcon[2] = new ImageIcon("3.GIF");
jFrame = new JFrame();
jPanel = new JPanel();
jLabel = new JLabel("");
jPanel.add(jLabel);
jFrame.getContentPane().add(jPanel);
jFrame.setSize(200,200);
jFrame.setVisible(true);
}
public void run()
{
while(true)
{
if(a<3)
{
jLabel.setIcon(imageIcon[a]);
a++;
}
else
a=0;
try
{
sleep(1000);
}catch(InterruptedException e){}
}
}
public void dis()
{
this.start();
}
public static void main(String args[])
{
TestThreadImage testThreadImage = new TestThreadImage();
testThreadImage.dis();
}
}
没了synchronized就不能叫同步了吧
用同步怎么实现啊?