Some two threaded image prepare and painting applet coordination problem

hi all,
i'm sure this multithreaded gui is complex but anyway. a simple producer&consumer type applet. there is one seperate thread preparing an offscreen image, and the main guy draws it on applet. i can not coordinate them, what's wrong i don't know. simply, applet starts a thread, which paints something on an offscreen image, and then tells to applet repaint(). anyway, here is the code, this small png files are a lot, idea is making a view on them, just imagine a big big png file divided into matrices. afterall this is not the important part. what i see on the screen is, if you ask, nothing.
thanx,
ozz
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.lang.reflect.Array;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MapViewer
     extends JFrame
     Image map[][];
     public MapViewer()
          int dimensions[] = { 58, 46 };
          map = (Image[][]) Array.newInstance(Image.class, dimensions);
          try
               loadImages();
          catch(Exception e)
               e.printStackTrace();
     public void loadImages()
          throws Exception
          for(int i=0; i<58; i++)
               for(int j=0; j<46; j++)
                    StringBuffer sb = new StringBuffer();
                    sb.append("C:\\map\\");
                    sb.append(i+1);
                    sb.append("_");
                    sb.append(46-j);
                    sb.append(".png");
                    map[i][j] = Toolkit.getDefaultToolkit().getImage( sb.toString() );
     public void go()
          initComponents();
          show();
     private void initComponents()
          addWindowListener
               new java.awt.event.WindowAdapter()
                    public void windowClosing(java.awt.event.WindowEvent evt)
                         exitForm(evt);
          getContentPane().setLayout(new BorderLayout());
          getContentPane().add(new MapPanel(), BorderLayout.NORTH);
          pack();
     private void exitForm(java.awt.event.WindowEvent evt)
          System.exit(0);
     public static void main(String args[])
          new MapViewer().go();
     private class MapPanel
          extends JPanel
          implements MouseMotionListener, Runnable
          private int north = 1;
          private int east = 2;
          private int south = 4;
          private int west = 8;
          private int direction;
          private Image model;
          private Boolean refreshModel = Boolean.TRUE;
          private Boolean modelReady = Boolean.FALSE;
          private Point start = new Point(200, 200);
          public MapPanel()
               addMouseMotionListener(this);
               new Thread(this).start();
          public synchronized Image requestImage()
               return createImage(1600, 1600);
          public Dimension getMinimumSize()
               return new Dimension(400, 400);
          public Dimension getPreferredSize()
               return new Dimension(400, 400);
          public void paint(Graphics g)
               synchronized(modelReady)
                    if(modelReady.booleanValue() == true)
                         g.drawImage(model, 0, 0, null);
               g.setColor(Color.white);
               g.fillRect(0, 0, 30, 10);
               g.setColor(Color.black);
               g.drawString(String.valueOf(direction), 0, 10);
          public void mouseDragged(MouseEvent e)
          public void mouseMoved(MouseEvent e)
               Point p = e.getPoint();
               findDirection(p);
          private void findDirection(Point p)
               direction = 0;
               if(p.x < 100)
                    direction |= west;
               else if(p.x > 300)
                    direction |= east;
               if(p.y < 100)
                    direction |= north;
               else if(p.y > 300)
                    direction |= south;
          public void moveIt()
               int px = 20;
               int py = 20;
               synchronized(refreshModel)
                    if(refreshModel.booleanValue() == true)
                         model = requestImage();
                         if(model == null || model.getGraphics() == null)
                              return;
                         Graphics g = model.getGraphics();
                         for(int x=0; x < 4; x++)
                              for(int y=0; y<4; y++)
                                   g.drawImage(map[px+x][py+y], x*200, y*200, null);
                         refreshModel = Boolean.FALSE;
                         modelReady = Boolean.TRUE;
//               start.x -= 3;
//               start.y -= 3;
          public void run()
               while(true)
                    try
                         moveIt();
                         repaint();
                         Thread.currentThread().sleep(20);
                    catch(InterruptedException ie)

Hi.
The Graphics.drawImage method is asynchronyous, that may be the reason of the problem. Set an ImageObserver parameter in drawImage method, when drawing on an offscreen image. Count finished images and when all are done
draw the big image on the screen.
Alternatively you can call Toolkit.prepareImage method in a loop, after loadimages and wait until all images are loaded(true returned).

Similar Messages

  • HT204053 I have two apple ID's and it's causing problems in my contacts. It repeats the same address and sometimes displays email address only but not the full contact details? How do I get my contact list the same in all my devices (iMac, iPhone & iPad (

    I have two Apple ID's and it's casing problems on my contact list as it repeats the address in somecases and in others it only displays email address for a contact. I want to have the same contact list and details on all my devices (iMac, iPhone 4S & iPad Mini)? Is it possible?

    By using 1 of the 2 ID's instead of both, choose one, move everything in the other one to the one you chose and stop using it.

  • Unable to view two different image files at once in PS CS4

    For some reason I am unable to open two separate image files and view them both on my screen in Photoshop CS 4.  My goal is to combine two versions of the same raw file in order to expand the tonal range.  I want to stack the 2 images and then use a layer mask to blend the best parts of both versions.  The problem is that when I open the second version, the first isn't visible until I close the top image.  I want to view both images on the screen and stack them but can't do that because I only see one.  Can some kind soul tell me what I'm doing wrong here?

    Thanks for responding.  This works really well.  I did learn that if I go to Window>Arrange>Float All in Windows (thanks to another email from the forum) that I can view both images at the same time.  I sure appreciate your help.  You have no idea how I've agonized over this darn thing.  Thanks again, Gladys
    Please view this as an Option to perform your task. There are smarter ways to do this but this is what I do...
    *) I pull up the image file (say pic_01) and adjust the levels in the area of the photo I want.
    *) I then open from the RAW doc and it is now sitting as a Tiff in Photoshop.
    *) I rename that file (such as pic_01Top) and SAVE. (But keep it open)
    *) I go back and reopen pic_01 in RAW and adjust the other properties I want.
    *) Open that image from RAW.
    *) Perform a ctrl c to copy.
    *) Close pic_01
    *) Do a cntrl v to copy that over pic_01Top
    *) Go to Layers-Layer mask-Hide all. (This also give you your "free" layer mask)
    *) Go to my brush tool.
    *) Use the black over white box arrow to reveal or conceal your bush strokes.
    *) Flatten file when done and Save anyway you wish.
    Hope this helps.
    >

  • Moving two seperate images in an applet

    Hi i am trying to move two seperate images on an applet. these images are two random cards from a pack of playing card, ie king,jack, queen etc..
    i can get both images moving at the same time but i want i want to do is to animate the movement of one image and when it raches a certain point onscreen, the other image moves to a different position onscreen and i should end up with both card images onscreen at different positions.
    here is the code for the part in which the applet draws the image to the graphics object:
    public void run()
            long tm = System.currentTimeMillis();
             while(Thread.currentThread() == t)
                 repaint();
                 try
                     tm += delay;
                     Thread.sleep(Math.max(0, tm - System.currentTimeMillis()));
                     //increment frame so that image moves 4 pixels at a time
                     f1 = f1 + 4;
                     f2 = f2 + 5;
                     f3 = f3 + 2;
                     f4 = f4 + 2;
                 catch(InterruptedException e)
                     break;
        public void stop()
            t = null;
        public void update(Graphics g)
            //code that generates 5 random card and animate them onscreen.
            Dimension d = size();
            int w = cards[r1].getWidth(this);
            int h = cards[r1].getHeight(this);
            if(f1 <= 100)
                // Erase the previous image
                g.setColor(getBackground());
                g.fillRect(0, 0, d.width, d.height);
                g.setColor(Color.black);
                g.drawImage(cards[r1], f2, f1, this);  //co ordinates
                if((r1 != r2) && (f1 == 100 ) && (f3 <= 300))
                    g.drawImage(cards[r2], f4, f3, this);  //co ordinates
            //g.drawImage(cards[r2], f4, f3, this);  //co ordinates
        }Has u can see from the above code. all 52 card images are stored in an array. I use a random function to generate a random image from the array, in this case two random images.
    i have used if statements that tell me when to stop the animation of an image and when to start the next image for animation using the f1,f2,f3 etc.. these are used for the co ordinates of the actual images.
    i increment them each time the applet is run from within a Thread.

    Sounds like you just need a little swing(or awt if you're using "old java")
    http://java.sun.com/docs/books/tutorial/uiswing/mini/index.html
    BorderLayout might be useful. Be aware that it can be tricky to switch out swing components and you may need to validate the container.
    Also, be aware that a "Frame"(JFrame) in java are what you would call a window and that a "Panel"(JPanel) in java is basically just an area that contains components, kinda like a <div> or <span> in html.

  • Hi I have been having a problem with Bridge in CS4 recently. So uninstalled CS4 and Lightroom 4.4 and reinstalled them on my Desktop PC. When I turned on Bridge through CS4, My thumb nail images disappeared and a thumb nail icon with CR2 appeared. Now som

    Hi I have been having a problem with Bridge in CS4 recently. So uninstalled CS4 and Lightroom 4.4 and reinstalled them on my Desktop PC. When I turned on Bridge through CS4, My thumb nail images disappeared and a thumb nail icon with CR2 appeared. Now some of my images have disappeared from Light room 4.4, but I can find them in CS4 and Bridge now shows some thumb nails as images and some as an icon with CR2. I have spent two weeks going through preferences etc. to find how to resolve my problem. Please can you Help? Meany thanks in advance
      Derek Randall

    I don't use LR and rarely use the bridge so I can not answers about thumbnails in them,  However thumbnails in windows file explorer and windows dialog for CS2 files will only show if you have installed codec into windows that will produce them. Windows does not do CR2 thumbnails on its own. I use FastPictureViewer Codec package for RAW File and PSD files thunbmail support.

  • How can I use some of the image i am working on to paint with? like if I wanted to give someone an extra eye in the forehead, ow could i then paint their own i in the forehead? I know there is a paint tool for that, i just can't find it ... :/

    How can I use some of the image i am working on to paint with? like if I wanted to give someone an extra eye in the forehead, ow could i then paint their own i in the forehead? I know there is a paint tool for that, i just can't find it ... :/

    It sounds like you are talking about the cloning tool?
    Tool looks like this:
    Then when selected you can change the size of the brush and using Alt (windows) and Command (Mac) to select your region you want to copy then start to create you cloned image.
    Hope this helps?

  • Simultaneously trigger and display two camera images with two frame grabbers

    When I try to simultaneously trigger and display two camera images, each with their own frame grabbers, Labview is only able to display one of the images at a time.
    My hardware:
    Two Sony XC-EU50 cameras (not in sync with each other)
    NI-1410
    NI-1405
    My Software:
    Windows XP and Labview 7.1 with IMAQ
    I connect each camera to its own frame grabber.  Both frame grabbers are in the same computer.  I input a trigger into each frame grabber.  Both trigger signals are identical.  Trigger rate is only 0.2 Hz. 
    I want to display and save both images at the same time.  The program i put together only displays one image at a time.  The image that is displayed alternates from one camera to the other.
    Please help with any suggestions.
    Thanks.
    Shahab K.
    Attachments:
    TriggerTwoCameras.vi ‏137 KB

    Hi Shahab.
    Without having triggered two cameras connected to two NI boards with LabVIEW yet: This shouldn't be a limitation in LabVIEW.
    Updating two Image Display Indicators in one run of a while loop definitely works properly, so this cannot be the reason for the problem.
    Your code uses the IMAQ Snap.vi. This VI is not reentrant, so the both instances of this VI on your block diagram cannot execute at the same time.
    I could not find an appropriate example matching your scenario exactly. (Maybe someone else knows better?)
    I recommend to have a look at the examples in the "IMAQ Signal IO.llb" and do some copy and paste to get a VI that satisfies your requirements.
    The "Grab with two boards.VI" illustrates how to acquire images without using the not-reentrant "IMAQ Snap.VI".
    Hope this helps, Guenter
    P.S.: Do you know NI's Vision Forum? http://forums.ni.com/ni/board?board.id=200

  • What does the grey box and brush in some project bin images mean?

    Using Elements 10 with Windows 7:  What does the small grey box and brush in the upper right corner of some project bin images signify?  Thanks!

    Thanks!  Yes, it does seem to be random.  BTW, how did you learn of this?  I've not seen it written anywhere.
    SCB
    Date: Tue, 1 May 2012 17:55:18 -0600
    From: [email protected]
    To: [email protected]
    Subject: What does the grey box and brush in some project bin images mean?
        Re: What does the grey box and brush in some project bin images mean?
        created by Barbara B. in Photoshop Elements - View the full discussion
    Supposed to mean that you have edits you haven't saved yet, but they can be kind of random, sometimes.
         Replies to this message go to everyone subscribed to this thread, not directly to the person who posted the message. To post a reply, either reply to this email or visit the message page: http://forums.adobe.com/message/4373074#4373074
         To unsubscribe from this thread, please visit the message page at http://forums.adobe.com/message/4373074#4373074. In the Actions box on the right, click the Stop Email Notifications link.
         Start a new discussion in Photoshop Elements by email or at Adobe Forums
      For more information about maintaining your forum email notifications please go to http://forums.adobe.com/message/2936746#2936746.

  • How to get OpenSPARC *prom.bin boot files for one core and two threads?

    How can I get OpenSPARC single core two thread files to boot for stand-alone programs and OpenSolaris,
    similar to the release download files
    design\sys\edk\os\OpenSolaris\proto\1c4t_prom.bin and
    design\sys\edk\os\OpenSolaris\proto\1c4t_obp_prom.bin?
    How about for other single core but arbitrary thread counts?
    Thanks,
    sparcMT1

    You can modify the 1c4t machine description files in the directory "softsim/t1_fpga/src/xilinx/configs" to create 1c2t machine description files. You have to modify two makefiles "softsim/t1_fpga/src/xilinx/configs/Makefile" and "softsim/t1_fpga/src/xilinx/prom/Makefile" to create 1c2t prom.bin file. You have to also modify the file "softsim/t1_fpga/src/xilinx/include/xilinx_t1_system_config.h" to specify the threads in the core that are enabled. The parameter that specifies the thread mask is "STRAND_STARTSET". It may be possible to only modify STRAND_STARTSET and use the newly compiled 1c4t prom.bin file. OBP may complain that it couldn't start two threads in the core.
    You can get the source code for the software at the following url
    http://www.opensparc.net/opensparc-t2/downloads.html
    The software is in the "OpenSPARC T2 Processor Download for Architecture and Performance Modeling Tools" package.
    -gopal

  • I have upgraded to Mountain Lion and have found that some of my software no longer works, notably Image Browser and also the Epson Scanner Perfection 3490 software. Is there a 'patch' or way to allow me to use these programmes especially the scanner.

    I have upgraded to Mountain Lion and have found that some of my software no longer works, notably Image Browser and also the Epson Scanner Perfection 3490 software. Is there a 'patch' or way to allow me to use these programmes especially the scanner.

    Apple discontinued support for PowerPC apps with Lion, I think, so you're out of luck there. No patch coming, unfortunately. Best to upgrade whatever old applications you have or, since it seems like you're using some relatively old software, scout around for replacements that give you the functionality you need.
    Go to Apple menu > System Preferences > Print & Scan and select your scanner from the list--if it's not there you'll need to add it (start with the little plus icon). Once you have it in the list you can click on the Open Scanner button and a pretty barebones scanner driver will load for you. But Image Capture (as mentioned previously), found in your Applications folder, will probably do the job as adequately, or better, than your old scanner software.

  • HT3275 Hi, I have backed up 2 IMACs and one Mac Book Pro but for some reason, the 3rd IMAC come up with this problem: The backup disk image "/Volumes/Data/Anthony's iMac.sparsebundle" could not be accessed (error -1). Why? They computer system is up to da

    Hi, I have backed up 2 IMACs and one Mac Book Pro but for some reason, the 3rd IMAC come up with this problem: The backup disk image “/Volumes/Data/Anthony’s iMac.sparsebundle” could not be accessed (error -1). Why? The computer system is up to date and I have had no issue with the other computers, just this one.
    Many thanks
    Anthony

    Try this Discussion...
    https://discussions.apple.com/message/18783684#18783684

  • Photos in my from my iPhone have same numbering as photos from my dig camera.  They all go into iPhoto fine but when I backup to my ext hard drive it will only save one with the name IMG 1002 and I have two separate images both with that name.  Help?

    Photos in my from my iPhone have the same numbering as photos from my digital camera.  They all go into iPhoto fine but when I backup to my ext hard drive it will only save one with the name IMG 1002 and I have two separate images both with that name.  How do I get them all to save on my ext hard drive and hope do I prevent this numbering overlap in the future?  I'm really hoping I don't have to go through and manually rename every single picture.  Thanks.

    How are you backing up the photos?  The best way is to backup the library itself as that will preserve your organizational efforts as well as all metadata like keywords, titles, faces, places, books, etc.
    You can use a backup application that does incremental backups.  Thus only the first backup is a full one and subsequent backups just copy those files that are new or changed. I use Synk Pro.  The lower cost version, Synk, will do the same job.  Other similar apps can be found at MacUpdate.com.  
    OR: upload your camera to a folder on the Desktop. There you can rename the files to something that is more informative than just the file name.  I use the date (international format) along with a brief desc: 2007-1-20-adian1stbday-001.jpg.  File renaming apps can also be found at MacUpdate.com.  Also you can give the folder an informatve name which will become the Event name when you import the folder of photos into iPhoto.
    OT

  • Hi I have two macbook pro, i connected one from another via lan cable , now when i removed it, its showing me some pop up again and again saying server may not exists and there was a problem connecting to ishan's macbook pro

    Hi I have two macbook pro, i connected one from another via lan cable , now when i removed it, its showing me some pop up again and again saying server may not exists and there was a problem connecting to ishan's macbook pro

    If you just reboot it, does the problem go away?

  • IO - Read two image files and put them into one file

    Hi,
    i have 3 files in all. The two image files and one text file. I need to place the image in the first image file, followed by text in the text file and then the image in the second image file, into one file.
    Can anyone tell me how do i go about doing this ?
    i tried using fileinputstream and fileoutputstream, which works fine if all the 3 files have text but when the first and the third file have image, the code doesn't give any error but the result file displays only the image from the first file and nothing else.
    i am running short of time and need to do this really soon.
    if anyone has done anything like this. please let me know,
    thanx,
    poonam

    One approach would be to programmatcally create a single zip/jar file from the three input files. You can use the java.util.zip and java.util.jar packages for this purpose.
    The other apprach would be to create a single image by drawing images and text strings on a BufferedImage object.
    I think the first approach is preferable because you can easily extract the individual files from the zip/jar file

  • I have used Image Capture to scan images/documents and then saved them as either PDFs or PNG files.  For some reason, just this past week Image Capture will no longer save the file.  It scans, and the Scan Results window pops up, but it won't save file.

    I have used Image Capture to scan images/documents and then saved them as either PDFs or PNG files.  For some reason, just this past week, Image Capture will no longer save the file.  It scans, and the Scan Results window pops up, but it won't save file.
    The file name has no special character in it, just letters and no spaces.
    I have done this in the past and it has worked, but now it will not.
    I have not upgraded any software, that I am aware of.
    After scanning, the Image Capture pops up the Scan Results with the file name in the window, but neither the Scan Results nor the Image Capture window responds to inputs.  The Image Capture window is frozen, with only the "Overview" and "Cancel" buttons active (but non-responsive).
    Is this a software issue or a scanner hardware issue?  I am using a HP Photosmart C6200 series printer/scanner on a network using a Time Capsule airport.
    Thanks.

    I had the same problem.
    Got a 90% fix.  Apparently the Mavericks preferences won't work with Yosemite, so I just deleted the Image Capture preferences.
    Unfortunately, the "Scan to" folder seems to be permanently set to the Pictures folder.
    1.  Quit Image Capture
    2.  Go to Finder > Go > Home, which opens up your home folder (named after your user name)
    3.  Open Library > Preferences > com.apple.ImageCapture.plist - Drag this file to the Trash
    4.  Start "Image Capture", click "Details" and change all your settings as you prefer
    5.  Quit and restart "Image Capture".   Notice it remembers all your settings except "Scan to" folder.  It insists on saving to "Pictures".
    That's as far as I was successful.  I tried changing the "Scan to" folder to "Desktop", but on launch, Image Capture always sets it back to "Pictures".
    This is what I tried:
    6.  Download and install "Pref Setter" from http://www.nightproductions.net/prefsetter.html
    7.  Quit "Image Capture".  Right-click on "com.apple.ImageCapture.plist" and open with Pref Setter.
    8.  Search for "Pictures", which finds "~/Pictures" (the tilde character at the start means your home directory).
    9.  Double-click on "~/Pictures" and change it to the folder you prefer.  I like "~/Desktop"
    10. Choose File > Save then Quit from Pref Setter.  Note that re-opening the plist file still shows "~/Desktop"
    11. Start up "Image Capture" -- on startup, "Image Capture" sets "Scan to" folder to "Pictures"
    I consider this a bug.

Maybe you are looking for

  • Worksapce login issue

    Hi I have installed Hyperion, and i think all is ok. All services are running. My Hyperion is installed in: Windows 2003 SP2 Oracle 11g But when I run EPM System diagnostic I get a problem with login in the Workspace service/login. This is the messag

  • My Facebook app has disappeared

    My Facebook app has disappeared. It still appears in the purchased section of the my app store with status OPEN but when I click on OPEN nothing happens. I have restarted my iPad, restored settings and still no help. I was also advised to cable link

  • Windows on mac and robohelp

    Has anyone used Parallels or VMware Fusion on an intel Mac, running Adobe's Robohelp? I have a friend who wants desperately to switch to a Mac, but has a need to run Robohelp for work (apparently a Windoze-only app).

  • What is Cycle or steps to create Stock transfer between plants.

    What is Cycle or steps to create Stock transfer between plants. Reply with T Codes & Justify

  • Assigned Keywords disappearing and phot folders not showing

    I moved a library from my laptop to my desktop via a network connection and then opened the library in lightroom 1.1. After a while of working with my photos, I noticed the following: 1) many of the keywords I assigned, both on the laptop and desktop