Results 1 to 9 of 9
  1. #1
    poe
    poe is offline Member
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default background image with runnables ugliness

    Hi,I`m using java awt only for simplicity and I have a animation issue.Displaying a animation on to a blank background/set background color works fine when double buffered and media tracked.When I have a image as the background and try to display my animations on top,ugliness.
    Any suggestions appreciated.

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: background image with runnables ugliness

    What does this question have to do with Threads and Synchronization, which is the subject of this section of the forum?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    poe
    poe is offline Member
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default Re: background image with runnables ugliness

    The animation/s is a runnable thread.

  4. #4
    poe
    poe is offline Member
    Join Date
    Aug 2012
    Posts
    3
    Rep Power
    0

    Default applet bg image problem when runnable on top

    Hi,I`m using java awt only for simplicity and I have a animation issue.Displaying a animation on to a blank background/set background color works fine when double buffered and media tracked.When I have a image as the background and try to display my animations on top,ugliness.
    Any suggestions appreciated.


    package sameasindians;

    import java.applet.Applet;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.MediaTracker;


    public class indians extends Applet implements Runnable{

    //problem with adding single image as background
    Image background1;

    int bgx = 0;
    int bgy = 0;

    int x1 = 300;
    int y1 = 0;

    Thread thread1;
    boolean thread1bool = true;

    Image[] imagesfire = new Image[4];
    int frameint = 0;

    private Image Buffer;
    private Graphics gBuffer;

    MediaTracker tr;
    ///////////////////////////////////////////////////////
    public void init() {

    setLayout(null);
    setSize(960,661);
    //test no flicker blackbg
    //setBackground(Color.BLACK);
    //tests confirm animation with mt and db runs smooth as silk with no bg image/s

    tr = new MediaTracker(this);

    Buffer=createImage(size().width,size().height);
    gBuffer=Buffer.getGraphics();

    //animation images
    imagesfire[0] = getImage(getDocumentBase(), "res1.gif");
    imagesfire[1] = getImage(getDocumentBase(), "res2.gif");
    imagesfire[2] = getImage(getDocumentBase(), "res3.gif");
    imagesfire[3] = getImage(getDocumentBase(), "res4.gif");

    //background image
    background1 = getImage(getDocumentBase(),"bg1.gif");
    //add images to mediatracker
    tr.addImage(background1,0); //id = 0,media tracker

    tr.addImage(imagesfire[0], 1);// id =,1 mediatracker
    tr.addImage(imagesfire[1], 1);
    tr.addImage(imagesfire[2], 1);
    tr.addImage(imagesfire[3], 1);

    ///////////////////////////////////////////////////////
    }

    public void start(){
    if(thread1bool == true){
    (thread1 = new Thread(this)).start();
    }
    }

    public void stop(){
    thread1 = null;
    }

    public void run(){
    try{
    tr.waitForID(0);
    tr.waitForID(1);
    } catch (InterruptedException e) {}

    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    // animation firing
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    if(thread1bool == true){
    int delay = 500; // .5 second
    try {
    while (thread1 == Thread.currentThread()) {
    frameint = (frameint+1)%imagesfire.length;
    gBuffer.drawImage(imagesfire[frameint],x1,y1,this);
    repaint();
    Thread.sleep(delay);
    }
    } catch (Exception e) {
    }
    }
    //xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    } //animations end runnables
    ////////////////////////////////////////////////

    public void paint(Graphics g){

    g.drawImage(background1,bgx,bgy,this);//problem

    g.drawImage(Buffer,0,0,this); //if background in doublebuffer should display background without drawimage(background) but // does not.

    }


    }
    Last edited by poe; 08-04-2012 at 01:24 PM.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: background image with runnables ugliness

    That doesn't make it a Threads and Synchronization issue. Moving to Java 2D.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: background image with runnables ugliness

    Quote Originally Posted by poe View Post
    Hi,I`m using java awt only for simplicity and I have a animation issue.Displaying a animation on to a blank background/set background color works fine when double buffered and media tracked.When I have a image as the background and try to display my animations on top,ugliness.
    Any suggestions appreciated.
    Whatever made you decide that AWT is simpler than Swing, which replaced it more than 10 years ago?

    To get better help sooner, post a SSCCE (Short, Self Contained, Correct (Compilable), Example) that demonstrates what you call 'ugliness'. Before you do that, go through these:
    Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Lesson: Using Other Swing Features (The Java™ Tutorials > Creating a GUI With JFC/Swing)
    Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: applet bg image problem when runnable on top

    Don't start two threads for the same problem. I'm merging the threads.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,305
    Rep Power
    20

    Default Re: background image with runnables ugliness

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,518
    Rep Power
    25

    Default Re: background image with runnables ugliness

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. use image for background
    By tony_stark in forum AWT / Swing
    Replies: 1
    Last Post: 05-31-2011, 08:20 PM
  2. [Help] W/ background image
    By gundum584 in forum New To Java
    Replies: 9
    Last Post: 01-10-2011, 05:48 AM
  3. Need help with JFrame background image
    By ProGenius in forum New To Java
    Replies: 6
    Last Post: 12-27-2009, 04:17 PM
  4. Background image
    By leiferouis in forum New To Java
    Replies: 9
    Last Post: 03-08-2009, 05:49 PM
  5. Image as background
    By Java.child in forum AWT / Swing
    Replies: 2
    Last Post: 10-02-2008, 11:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •