I'm working on a Java Appet that fades an image then shows it again in a different spot in the applet window -


this question has answer here:

the applet working fine, in showing image , text, image fade reappear in spot, reload in same spot later.

i fade , move test well,

here's code far, forgive me i'm newbie!

import java.applet.*; import java.awt.*; import java.awt.image.*; import java.net.*;  public class fadeimage extends applet { image   img, faded; int level, sign; mediatracker tracker; alphafilter f; filteredimagesource fis; string  msg2 = "university of utah football";   public void init() {    setbackground(color.red);    setforeground(color.black);     level = 0;  sign =  15;  tracker = new mediatracker(this);  try {     img = getimage(new url(getdocumentbase(), "uofu.jpg"));    tracker.addimage(img,0);    tracker.waitforid(0);     }  catch (exception e) {    e.printstacktrace();    }  f = new alphafilter();  f.setlevel(level);  fis = new filteredimagesource(img.getsource(), f) ;   fadethread ft = new fadethread();  ft.delayedfading(this, 20);   ft.start();  }  public void paint(graphics g) {    font myfont = new font("times new roman", font.bold, 24);    g.setfont(myfont);    g.setcolor(color.red);    g.drawstring(msg2, 10, 465);    if (faded != null) {     g.drawimage(faded,0,0,this);      font myfont2 = new font("times new roman", font.bold, 33);     g.setfont(myfont2);     setbackground(color.black);    setforeground(color.white);        g.setcolor(color.white);        g.drawstring("get season tickets now!", 10, 490);     }  }  public void fadeit() {   graphics g = this.getgraphics();  level += sign;  if (level < 0) {     level=0;      sign = sign * -1;     }  if (level > 255) {     level=255;      sign =  sign * -1;   try {     thread.sleep(1000);     }   catch (exception e) {}     }  f.setlevel(level);  if (faded != null) faded.flush();  faded = this.createimage(fis);  tracker.addimage(faded,0);  try {     tracker.waitforid(0);     }  catch (exception ex) {    ex.printstacktrace();    }  repaint();  }   class fadethread extends thread {  fadeimage fadeapplet;  int delay;    public void delayedfading(fadeimage f, int delay) {    this.fadeapplet = f;    this.delay = delay;    }   public void run() {    while (true) {      try {        sleep(delay);        fadeapplet.fadeit();        }       catch (exception e) {        e.printstacktrace();        }      }    }  }  class alphafilter extends rgbimagefilter {   private int level;    public alphafilter() {      canfilterindexcolormodel = true;     }    public void setlevel(int lev) {     level = lev;     }    public int filterrgb(int x, int y, int rgb) {     int = level * 0x01000000;     return (rgb &   0x00ffffff) | a;     }   } } 


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -