Results 1 to 9 of 9
- 08-04-2012, 10:00 AM #1
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
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.
- 08-04-2012, 12:04 PM #2
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?
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-04-2012, 12:08 PM #3
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
Re: background image with runnables ugliness
The animation/s is a runnable thread.
- 08-04-2012, 12:35 PM #4
Member
- Join Date
- Aug 2012
- Posts
- 3
- Rep Power
- 0
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.
- 08-04-2012, 03:39 PM #5
Re: background image with runnables ugliness
That doesn't make it a Threads and Synchronization issue. Moving to Java 2D.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-04-2012, 03:44 PM #6
Re: background image with runnables ugliness
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)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-04-2012, 03:46 PM #7
Re: applet bg image problem when runnable on top
Don't start two threads for the same problem. I'm merging the threads.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 08-04-2012, 03:46 PM #8
Re: background image with runnables ugliness
Why do they call it rush hour when nothing moves? - Robin Williams
- 08-04-2012, 05:04 PM #9
Re: background image with runnables ugliness
If you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
use image for background
By tony_stark in forum AWT / SwingReplies: 1Last Post: 05-31-2011, 08:20 PM -
[Help] W/ background image
By gundum584 in forum New To JavaReplies: 9Last Post: 01-10-2011, 05:48 AM -
Need help with JFrame background image
By ProGenius in forum New To JavaReplies: 6Last Post: 12-27-2009, 04:17 PM -
Background image
By leiferouis in forum New To JavaReplies: 9Last Post: 03-08-2009, 05:49 PM -
Image as background
By Java.child in forum AWT / SwingReplies: 2Last Post: 10-02-2008, 11:37 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks