|
problem with threads
import java.awt.*;
import javax.swing.*;
class d extends JComponent implements Runnable
{
Image r;
Image g;
int y=0;
long floor=329;
public void run()
{
r=new ImageIcon("red.png").getImage();
g=new ImageIcon("blue.png").getImage();
try
{
while(y!=floor)
{
y++;
repaint();
Thread.sleep(10);
}
}
catch(Exception e)
{
}
}
public void paint(Graphics q)
{
q.drawImage(r,229,y,this);
q.drawImage(g,229,y-32,this);
}
}
class f
{
public static void main(String args[])
{
d v=new d();
JFrame b=new JFrame("sdfdsf");
b.getContentPane().add(v);
b.setVisible(true);
b.setSize(300,400);
(new Thread(v)).start();
}
}
in this code i had uploaded two image files iam using the thread so that using sleep method it comes slowly from y=0 and stops at point y=329 the first image should stop and it is stopping also and after that i just want to create another thread so that the existing image which had stopped at point y=329 should exist in the jframe and the new image should come from y=0 and should stop at point y=329-32 because my image height is of 32 , and it should lie on the old image and both the images should appear ,could u help me out of this problem
|