0

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..!!

anusha
  • 55
  • 2
  • 10
  • 1
    What isn't working? We need somewhere to start rather than just trying to dig through all of your code. – jzworkman Jan 21 '14 at 17:17
  • 1) Why code an applet? If it is due to spec. by teacher, please refer them to [Why CS teachers should stop teaching Java applets](http://programmers.blogoverflow.com/2013/05/why-cs-teachers-should-stop-teaching-java-applets/). 2) Why AWT rather than Swing? See my answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. 3) Why did you destroy the cat image link? – Andrew Thompson Jan 21 '14 at 17:22
  • problem is in the run method of main class!! do we need to call the start function initially? – anusha Jan 21 '14 at 17:23
  • i find working in applets easy rather than swing since im a beginner@Thompson – anusha Jan 21 '14 at 17:32
  • *"i find working in applets easy rather than swing"* You are very confused. 1) An applet can be Swing or AWT. 2) Applets are a complete PITA, if you'd read that linked article, I go into great detail on the matter. 3) People are better able to help with Swing, because they've forgotten AWT. -- So. You have a code problem and have come here for help, time to start using Swing. And leave applets aside entirely. – Andrew Thompson Jan 21 '14 at 20:16

0 Answers0