|
where to add thread in the program
in the above program, the main motive of the program is to keep one image fixed at the bottom (the fixed one is red) and start a thread for the image(the blue one) which u can see the code in the comment lines of the program given below .i just want to keep the fixed image and the other image(blue) in thread so that the two images should be visible to me , my program should look like one image(red) is fixed at the bottom and other image (blue) coming from top to bottom and both should be visible to me but they are not if one is fixed then i can see only that image i cant see the other image could u help out with this code and how to use thread in this program.
import java.util.*;
import java.awt.*;
import javax.swing.*;
class load extends JFrame
{
Image r;
Image b;
int y=329;
int floor=329;
int x=3;
load()
{
super("some name");
r=new ImageIcon("red.png").getImage();
b=new ImageIcon("blue.png").getImage();
getContentPane().add(new display());
setVisible(true);
setSize(175,400);
setResizable(false);
}
class display extends JPanel //implements Runnable
{
//Thread t=new Thread(this);
display()
{
repaint();
}
public void paintComponent(Graphics q)
{
Graphics2D n=(Graphics2D)q;
q.drawImage(r,x,y,this);
}
/*
i just want to place the red image fixed at the bottom
and start new blue image thread i,e
try
{
y=0;
while(y!=floor)
{
y++;
q.drawImage(b,x,y,this);
Thread.sleep(10);
}
}
catch(Exception e)
{
}
*/
}
}
class f
{
public static void main(String args[])
{
new load();
}
}
|