Drawing image so that it appears on top of another

Alright, this question isn't as straight forward as it may seem. Yes, I want to draw an image so that it appears on top of another drawn image, but the image I am trying to draw is being drawn in another thread like so:
public class myApplet extends Applet implements Runnable
  public Graphics g;
  public Thread myThread;
  public void init()
    myThread = new Thread(this);
    myThread.start();
  public void paint()
     super.paint(g);
     //Assume that I loaded in the images properly
     g.drawImage(image1, 0, 0, null); //Assume image1 is a 50 px X 50 px image
  public void run()
     g.drawImage(image2, 0, 0, null); //Assume image2 is a 20 px X 20 px image
}This also happens if I try to do "g.fillRect();". The 50 X 50 image appears on top of the 20 x 20 image. Does anyone know a way that I can tell the program to draw the image in the thread AFTER the image in the paint method (I know I should be using paintComponent, but this is a sample program. Please don't get too picky about it. I typed it up simply for this post and I wanted to make it simple).
The reason I'm drawing it in the paint method is because I am making an image move along a set of points. The points are formulated inside the run() method. If I draw it inside of the paint() method it skips points.
Any help would be GREAT. Thank you.
Edited by: dustty1818 on Apr 11, 2009 9:05 AM

dustty1818 wrote:
public class myApplet extends Applet implements Runnable
public Graphics g;
public void run()
g.drawImage(image2, 0, 0, null); //Assume image2 is a 20 px X 20 px image
}Edited by: dustty1818 on Apr 11, 2009 9:05 AMDusty,
There are several serious (fatal) flaws with your design. The biggest is that you should NEVER hold
on to a Graphics object. If anything you should be calling dispose at the end of the paint method.
It appears that you are accidentally trying to use a technique called "active rendering".
You can do active rendering in Java but it would look nothing like what you are doing (and is much
more advanced). You must resolve to keep all drawing in (or preferably called from) the paint method.
Have your run() method call repaint() and have your paint() method have all the information it
needs to render the scene.
Also, and this is comparatively minor, extend JApplet.
example:
import java.awt.*;
import javax.swing.*;
public class SceneRenderer extends JApplet implements Runnable{
     Point pt1 = new Point(0, 0);
     Point pt2 = new Point(0, 0);
     public void init(){
          Thread animationThread = new Thread(this);
          animationThread.start();
     public void paint(Graphics g){
          super.paint(g);
          g.setColor(Color.RED);
          g.fillRect(pt1.x, pt1.y, 50, 50);
          g.setColor(Color.BLUE);
          g.fillRect(pt2.x, pt2.y, 20, 20);
     public void run(){
          while(true){
               pt1.x += 1;
               pt2.x += 1;
               repaint();
               try{
                    Thread.sleep(60);
               } catch(Exception e){}
}

Similar Messages

  • Menu bar (that has tools, history, etc.) that must appear on top of firefox page is absent. How do I fix the problem?

    Menu bar (that has tools, history, etc.) that must appear on top of firefox page is absent. How do I fix the problem?

    There are other things that need attention.
    Your above posted system details show outdated plugin(s) with known security and stability risks that you should update.
    # Shockwave Flash 10.1 r85
    # Next Generation Java Plug-in 1.6.0_18 for Mozilla browsers
    Update the [[Managing the Flash plugin|Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/
    Update the [[Java]] plugin to the latest version.
    *http://www.oracle.com/technetwork/java/javase/downloads/index.html (Java Platform: Download JRE)

  • The top bar that usually appeared on top (tools, bookmarks, etc) has disappeared. how do i get it back??

    Top bar is gone. I cant find bookmarks, etc.

    Other things that need attention:<br>
    Your above posted system details show outdated plugin(s) with known security and stability risks that you should update.
    * Shockwave Flash 10.0 r32
    * Java Plug-in 1.6.0_07 for Netscape Navigator (DLL Helper)
    Update the [[Managing the Flash plugin|Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/
    Update the [[Java]] plugin to the latest version.
    *http://java.sun.com/javase/downloads/index.jsp (Java Platform: Download JRE)

  • Getting text to appear on top of Image In InDesign 5

    I am struggling to get some text to appear on top of an image in InDesign 5. I did fiddle with layers but it doesn't appear to have multiple layers.
    Could someone walk me through making this work?
    Appreciate the help!
    Brian

    It seems that even if I turn the image off in layers, the text fiend does not sho up. In other words, if I create a text field outside the printable area for the boot, the text is displayed, but when I drag it into the printable area, the text goes blank.
    Let me get this one thing straight though: But draging the text layer entry above the image layer entry, the text layer would thus be above and on top(visable).??
    But it's not working as a result of the above mentioned. I still seems to have something to do with the image layer that exists on the page.
    Ooops! Bob, you hit the nail on the head. Although there was no text wrap spacing added, the text wrap was on. So, selecting a particular image and removing "text wrap" only applies the attributes only to that image. All other images still have text wrap on.....which is what I want.
    Thanks to all.

  • Last night suddenly when I right-click-view-images in firefox, they appear centered and against a black background. It's usually meant to be a white background and the image appearing at top left. How to revert it?

    I'm having trouble with something in firefox, it's quite minor but still bugs me. Last night suddenly when I right-click-view-images in firefox, they appear centered and against a black background. It's usually meant to be a white background and the image appearing at top left. I can't remember what I did to change this if it's my fault; if someone knows how to revert it I'd be thankful.

    cor-el : thanks for the pointers! I wish the solution isn't an add-on every time ... if such long-standing behaviour is going to change, the least that could be done is put in an about:config option to get back the old behaviour.

  • I have a symbol that has appeared on my iphone 4s top right just left off the bluetooth sign, it's an arrow on a circle with a padlock in the middle any idea where it came from and what it is

    i have a symbol that has appeared on my iphone 4s top right just left off the bluetooth sign, it's an arrow on a circle with a padlock in the middle any idea where it came from and what it is

    That's the portrait orientation lock (keeps the screen from rotating to landscape mode).  To turn it off, double-tap the home button, swipe the list at the bottom to the right, then tap the left-most icon (to the left of the music controls).

  • Small blue question mark appears instead of the photo or images that normally appear

    Following the last update, photos and images that normally appeared now require downloading but are still missing from printouts. Would like to return to automatic images appearing.

    MacBook Pro OR iOS Device?

  • Where can I find a list of the meaning of the symbols that can appear in the headline at the top of the screen on the ipad and iphone?

    where can I find a list of the meaning of the symbols that can appear in the headline at the top of the screen on the ipad and iphone?

    http://support.apple.com/kb/HT1558
    http://support.apple.com/kb/TA38663
    http://support.apple.com/kb/HT4982
    They are also listed in the built-in User Guide accessible directly on the iPhone in Safari.
    Find the "iPhone User Guide" bookmark, then go to iPhone at a Glance > Status icons

  • HT3717 How do I remove a bullet that is appearing next to an image?  Is this a bug?

    I am using Keynote 6.1 and I am getting a bullet point to the left of my images.  It only appears in presentation mode, not edit.
    With the new formatting tools, there is no "bullet" option if you are on an image, which suggests that it is a bug.  However, if there is a clever workaround, I would love to see it.

    Login to your account on iTunes
    you can remove all five and then authorize the one you want.

  • Hi I call you from Iran. Today I encountered a problem I hope you can help me. I have iPhone 5 with version 6.1.4. Jailbreak I would rather not unlock. My problem is that the Operator name (top left) searching ... The appearance of! And no matter how I tu

    Hi
    I call you from Iran.
    Today I encountered a problem I hope you can help me.
    I have iPhone 5 with version 6.1.4. Jailbreak I would rather not unlock.
    My problem is that the Operator name (top left) searching ... The appearance of!
    And no matter how I turn off and I remove the SIM card Sarchyng not stop.
    Even when I'm not on the phone's SIM card No SIM card Does not appear.
    I appreciate your help.
    Thank you for your attention.

    ilove.perspolis wrote:
    Hi
    I call you from Iran.
    Today I encountered a problem I hope you can help me.
    I have iPhone 5 with version 6.1.4. Jailbreak I would rather not unlock.
    My problem is that the Operator name (top left) searching ... The appearance of!
    And no matter how I turn off and I remove the SIM card Sarchyng not stop.
    Even when I'm not on the phone's SIM card No SIM card Does not appear.
    I appreciate your help.
    Thank you for your attention.
    I read this to say that the phone is not jailbroken and the OP does not want to jailbreak it.
    The only way to unlock it is to contact the carrier it is locked to, and ask them to unlock it.
    You are also in the unfortunate position that the iPhone is not supported in Iran due to the international embargo.

  • How do I attached a jpg from iPhoto to mail as so that it appears as an icon and not an image. PC user can nor download as entire image

    How do I attach a jpg from iPhoto to mail so that it appears as an icon only and NOT the photo image. Mac and PC user can no download in format as entire image. thx

    Use Apple Mail as your e-mail client and under the format menu set format to plain text
    LN

  • How do I change the avatar/picture that appears in top right hand corner of my e-mails in mail?

    How do I change the avatar/picture that appears in top right hand corner of my e-mails in mail?

    Change it in System Preferences > Users & Groups, right-click on the picture. Also be aware that this picture is not visible to people who recieve your email, unless they have the same picture for you in their AddressBook.

  • IPhoto has one (random) main photo for everything on top repeatedly with other appropriate photos behind it. How do I get off that one random photo so the real photos appear on top as it should be?

    iPhoto has one same (random) main photo for everything on top repeatedly with other appropriate photos behind it. How do I get off that one random photo so the real photos appear on top as it should be?

    Backup your iPhoto library and hold down the option and command keys while launching iPhoto - hold until the first aid window appears and rebuild thumbnails - it may take a few tries
    LN

  • How to make New Events appear at TOP of page, not Bottom?

    When I import photos, they are automatically put into a new Event. That's great. But that Event appears way at the bottom of my long events list, even though my Events are shown chronologically with the most recent events right at the top. I have to drag the new event all the way through dozens of older events in order to bring it up to the top, where I can figure out which other event folders those new images might belong (ex: "family photos, Fall 2008").
    This isn't the biggest problem in the world, but I'd love to know how to set iPhoto to create the new event at the top of the list instead of the bottom. Any help? Thanks.

    Welcome to the Apple Discussions. In the View->Sort menu select Descending. However that will also have the photos in the Photos mode be sorted descending. In the Event mode you can sort the events in one direction and the photos in those events in the other. In the Photos mode both the Events and photos are sorted the same direction.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto (iPhoto.Library for iPhoto 5 and earlier) database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger or later), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 6 and 7 libraries and Tiger and Leopard. Just put the application in the Dock and click on it whenever you want to backup the dB file. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.
    Note: There's now an Automator backup application for iPhoto 5 that will work with Tiger or Leopard.

  • .swf inside HtmlLoader appears on top of other air content

    When there is an HtmlLoader with a .swf wmode window the .swf file appears over top of everything!
    I understand that .swf should appear above everything inside the HtmlLoader, but I don't think it should appear over top of anything outside of the HtmlLoader.
    A simple example of this would be:
    <?xml version="1.0" encoding="utf-8"?>
    <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
       xmlns:s="library://ns.adobe.com/flex/spark"
       xmlns:mx="library://ns.adobe.com/flex/mx">
    <mx:HTML location="http://youtube.com" width="100%" height="100%" />
    <s:Button width="300" height="300" label="should be over all html content, .swf in html appears over it. click and watch a youtube video to see." />
    </s:WindowedApplication>
    I NEED a fix to this~!
    Even placing a second HtmlLoader with an .swf wmode window over top produces random results with the top .swf sometimes on top and other times below the lower .swf

    As you have discovered, two elements on the surface of a <div> cannot occupy the same space. The solution lies in getting one of the elements to "lie down," either by getting it totally off the surface and making it a background of it or by actually "levitating" one above the other.
    Apply a unique id to each div in which an image now lies.
    Place each image in the background of its div, defining it in your CSS.
    You will not then be able to use the image as a button, and you may want to add something else to click on.
    OR (this second way is probably better)
    Change the .FilmStill definition by adding position: relative;
    Change the .SlantedWritingFilms definition by adding position: absolute; and positioning attributes (left: 0; top: 0; for instance)
    Change each .SlantedWritingFilms <span> into a <div> within <div class="FilmStill">.
    Beth

Maybe you are looking for

  • Microsoft Word 2008 keeps crashing with Mountain Lion 10.8.3.

    I've had this problem off and on, and judging from the forums, it seems to be common. Following advise on one discussion forum and a visit to the genius bar, I tried deleting the .plist files in the preferences folder for Word (following advice found

  • Cmd+tab not functioning correctly

    CMD+Tab to switch windows works correctly when i am trying to switch windows within the same desktop space. However, it does nothing when i choose an application window running in a different desktop space. I am on the latest update 10.10.3 Everythin

  • To implement customization on order level promotion

    ATG 10.1.2 We have a requirement that order can have only one order level promotion. ATG 10.1.2 provides the stacking rule feature where one can mentioned the explicitly excluded promotion, that one easy and clean way. On top of this we need to imple

  • **** Error from PSA **** while loading 0comp_code (processing- info obejct)

    Hi, I am getting error **** Error from PSA **** while loading info object attributes for company code (0comp_code). I am not using oly info obejct in processing.  below is the error message. Error from PSA **** Error message when processing in the Bu

  • Exice wrong values in migo

    Hi, I'm geting wrong excise values during migo- excise capturing, Base price  - 1000 BED - 16% - 160 Ed cess 2% - 3.20 Se cess 1% - 1.60... this is the normal flow, where mine is flowed like blw; Base price  - 1000 BED - 16% - 174 Ed cess 2% - 3.20 S