Here is my code..have used multithreading concept in applet graphics im trying to ove the image in either direction and make the string appear in swirly colors.Its working in seperate class but not in multithreading.I can guess problem is in run method.please check the code ![][a busy cat]
import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
//guess problem is in this class...!!
public class threadone extends Applet implements Runnable
{
int x;
int ux1,ux2;
private Image img;
boolean running=true;
Font f=new Font("TimesRoman", Font.BOLD + Font.ITALIC, 40);
Color colors[]=new Color[50];
private Thread thread1,thread2;
public void start()
{
img=getImage(getCodeBase(),"c232.gif");
Runnable job=new threadtwo(this);
Runnable job2=new threadthree(this);
thread1=new Thread(job);
thread2=new Thread(job2);
thread1.start();
thread2.start();
}
public void destroy()
{
running=false;
}
public void stop()
{
running=false;
}
public void paint(Graphics g)
{
g.setFont(f);
int i = 0;
setForeground(colors[i]);
g.drawString("flames",750,50);
g.drawImage(img, x,250, this);
ux1=ux2=0;
}
public void run()
{
}
}`
//this is second class in multithread have tried to move an image//
public class threadtwo implements Runnable
{
threadone parent;
public threadtwo(threadone parent)
{
this.parent=parent;
}
public void run()
{
while(true)
{
int x;
int ux1 = 0,ux2 = 0;
for (x = 5; x <= 505; x+=4)
{
ux2 = x + 90;
parent. repaint();
try {
Thread.sleep(100);
}
catch (InterruptedException e)
{
if (ux1 == 0) ux1 = x;
}
for (x = 505; x > 5; x -=4)
{
ux1 = x;
parent. repaint();
try {
Thread.sleep(100);
}
catch (InterruptedException e)
{
}
if (ux2 == 0) ux2 = x + 90;
}
}
}
}
}
// this is third class in multithread have tried to implement swirly colors//
import java.awt.Color;
public class threadthree implements Runnable{
threadone parent;
Color colors[]=new Color[50];
public threadthree(threadone parent)
{
this.parent=parent;
}
public void run() {
// TODO Auto-generated method stub
float c = 0;
for( int i=0;i<colors.length;i++)
{
colors[i]=Color.getHSBColor(c,(float)1.0,(float)1.0);
c+=0.02;
}
int i = 0;
while (true)
{
parent.repaint();
i++;
try {
Thread.sleep(50);
}
catch (InterruptedException e)
{
}
if (i == colors.length )
i = 0;
}
}
}
`
you can also verify this in implementing in 3different class ...the code realy works..!!