import java.applet.Applet;
import javax.swing.*;public class refrash extends Applet implements Runnable
{ JLabel jLabel1;
Thread thrr;
int i = 0;
public void init()
{
}
public void start()
{
if (thrr == null)
{
thrr = new Thread(this);
thrr.start();
}
}
public void run()
{ while (true)
{
jLabel1 = new JLabel("i+" + i);
add(jLabel1);
validate (); try
{
Thread.sleep(1000);
System.out.println(i);
i++;
}
catch (InterruptedException e)
{
System.out.println(e);
} }
}
}

解决方案 »

  1.   

    Dimension offDimension; 
    Image offImage; 
    Graphics offGraphics; public void update(Graphics g) 

    ??Dimension d = size(); ??if ((offGraphics == null) || (d.width != offDimension.width) 
    ????????????|| (d.height != offDimension.height)) 
    ??{ 
    ????offDimension = d; 
    ????offImage = createImage(d.width, d.height); 
    ????offGraphics = offImage.getGraphics(); 
    ??} ??offGraphics.setColor(getBackground()); 
    ??offGraphics.fillRect(0, 0, d.width, d.height); 
    ??offGraphics.setColor(Color.Black); ??paintFrame(offGraphics); ??g.drawImage(offImage, 0, 0, null); 
    } public void paint(Graphics g) 

    ??if (offImage != null) 
    ??{ 
    ????g.drawImage(offImage, 0, 0, null); 
    ??} 
    } public void paintFrame(Graphics g) 

    ??Dimension d = size(); 
    ??int h = d.height / 2; 
    ??for (int x = 0; x <d.width; x++) 
    ??{ 
    ????int y1 = (int)((1.0 + Math.sin((x - frame) * 0.05)) + h); 
    ????int y2 = (int)((1.0 + Math.sin((x + frame) * 0.05)) + h); 
    ????g.drawLine(x, y1, x, y2); 
    ??}