Overlapping images in an applet

Hello,
I'm a Java beginner and I would like to write a small applet for a web page. My goal is the following:
The webpage has a background image. So far no problem.The applet should also show a small menu- which is also no greater problem.
Further on, every time the mouse cursor is rolling over a menu image, another image should be displayed overlapping the background image.
This is a problem, because I cannot remove the displayed image without
repainting the entire background image.
I am looking for a method, which can store a well defined image area so I can restore it later.
Thank you for any help !
Stephan

Put your images (rollover or whatever) on a new component - in swing you can use a JLabel - or, I'll assume awt here as its an applet, you can use a Panel. eg
MouseEntered()
inside your area
add(myPanel)
MouseExited()
your area
remove(myPanel)
In the panel you'll need to explicity call on java.awt.Graphics with
Graphics g = myPanel.getGraphics();

Similar Messages

  • Image Processing using applet

    hi,
    I am doing my project in java.My project is " Online Image Processing ".
    I did some processing like gray Scale, Invert , Contrast and rotate 90 degree.
    can any one help me for
    1. I vant to rotate Image to 1 degree...
    2. How to get Blure and Sharpen image?
    3. Can i append frames inside applet?
    plz Help me ..

    I did not read the content of the links (To lazy) just found them for you.
    You say that the examples use frames:
    this should not be a problem as the required code is the same.
    Tip:
    How whould you display a image in a frame?
    How whould you display a image in a applet?
    Concentrate on the above 2 and simply change the code accordingly.
    This should be easy also try asking google.

  • How to writing an image from my applet to my apache webserver

    hi everyone,
    i have a big problem, writing an image from my applet to my apache
    webserver. i tried three way's of writing that file. every way was
    described in forums to solve this problem, but non of them worked and
    i don't know why. i'll give you the code of my writing-methods and
    describe, what happen when i test them, in order someone of you can
    give me an usefull tip, where the problem is.
    as inputparameter i give my method a new URL referring to
    http://localhost/test.jpg (this is the same directory, where my applet
    is loaded from, so i should have reading and writing permission,
    havn't i? while i'm developing, my applet runs on the same pc as my
    webserver, just in case you're wondering about localhost) and a
    selfmade BufferedImage (i already testet if it is not null and shows
    the correct things ... all ok).
    1. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    URLConnection urlConnection = fileURL.openConnection();
    urlConnection.setDoOutput(true);
    OutputStream urlout = urlConnection.getOutputStream();
    BufferedOutputStream out = new BufferedOutputStream(urlout);
    ImageIO.write(img,"jpg",out);
    out.close(); // i also tried without this line -> same result
    // additionally a question: do i need
    out.close()?
    catch( IOException e ){
    e.printStackTrace();
    result:
    test.jpg doesn't appear in the webroot. but some very strange messages
    in the error.log of my apacheserver:
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageOutputStreamSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageReaderSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageInputStreamSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageWriterSpi
    [Tue Jun 08 11:40:22 2004] [error] [client 127.0.0.1] File does not
    exist: c:/programme/apache
    group/apache/htdocs/meta-inf/services/javax.imageio.spi.ImageTranscoderSpi
    i cannot explain this lines to myself, because my apache should have
    nothing to do with java. all my javacode is executed on the client
    side in the browser. do this messages mean i have to add the ImageIO
    package from the sdk to my jar-applet. the jre, used by my iexplorer,
    doesn't contain this files in the meta-inf/services directory of
    rt.jar, but that's version 1.4.2_03, the same as my sdk, and the
    rt.jar contains the corresponding classfiles at javax.imageio.spi. so
    i'm realy confused by this messages.
    2. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    URLConnection urlConnection = fileURL.openConnection();
    urlConnection.setDoOutput(true);
    OutputStream urlout = urlConnection.getOutputStream();
    BufferedOutputStream out = new BufferedOutputStream(urlout);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(img);
    out.close(); // same comments as above
    catch( IOException e ){
    e.printStackTrace();
    result:
    nothing. no error-messages in the error.log, no exceptions in the
    java-console and no test.jpg in the webroot. i searched my whole
    harddrives for it: nothing. isn't this the way, the JPEGImageEncoder
    works?
    3. try:
    private void writeImageToServer(URL fileURL,BufferedImage img){
    try {
    File file = new File(fileURL.toString);
    file.createNewFile();
    BufferedOutputStream out = new BufferedOutputStream(new
    FileOutputStream(file));
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(img);
    out.close(); // same comments as above
    catch( Exception e ){
    e.printStackTrace();
    result:
    the SecurityManager denies this action with "access denied" while
    calling createNewFile(). well, this way was dedicated to run from an
    application, not from an applet. i'd have to sign my applet to get the
    rights to do this, or i can edit java.policy on my client, what i
    don't want, because i cannot do this on every client, the applet will
    run, when i'm finished with it. this brings me to the question: does
    anybody know's how to sign my applet and give it full access to the
    harddrive and the webserver without paying 400$ to VeriSign for a
    commercial CA? i want to do this by myself, without paying anything
    and without giving a lot of information to another company.
    i would realy appreciate, if someone could give me a hint where i am
    wrong or how to do this correct.
    thank you very much
    [email protected]

    You hold several misconceptions. The first is that an applet can write to a server without help from the server. That will never work on a real server (though it might work in testing, if the server is on the same PC as the applet). Applets cannot get a File object that points to any place on the server.
    If you write a servlet designed for accepting image uploads, the applet can communicate back to that servlet and feed it the bytes of the image. There are other technologies that can replace the servlet, of course (PHP, ASP..) but I mention that because you say you are running Apache - and that is very Java oriented.
    For more help on servlets, try the [Web Tier APIs - Java Servlet|http://forums.sun.com/forum.jspa?forumID=33] forum.

  • Loading an image into an Applet from a JAR file

    Hello everyone, hopefully a simple question for someone to help me with!
    Im trying to load some images into an applet, currently it uses the JApplet.getImage(url) method just before registering with a media tracker, which works but for the sake of efficiency I would prefer the images all to be contained in the jar file as oppossed to being loaded individually from the server.
    Say I have a class in a package eg, 'com.mydomain.myapplet.class.bin' and an images contained in the file structure 'com.mydomain.myapplet.images.img.gif' how do I load it (and waiting for it to be loaded before preceeding?
    I've seen lots of info of the web for this but much of it is very old (pre 2000) and im sure things have changed a little since then.
    Thanks for any help!

    I don't touch applets, so I can't help you there, but here's some Friday Fun: tracking image loading.
    import java.awt.*;
    import java.awt.image.*;
    import java.beans.*;
    import java.io.*;
    import java.net.*;
    import javax.imageio.*;
    import javax.imageio.event.*;
    import javax.imageio.stream.*;
    import javax.swing.*;
    public class ImageLoader extends SwingWorker<BufferedImage, Void> {
        private URL url;
        private JLabel target;
        private IIOReadProgressAdapter listener = new IIOReadProgressAdapter() {
            @Override public void imageProgress(ImageReader source, float percentageDone) {
                setProgress((int)percentageDone);
            @Override public void imageComplete(ImageReader source) {
                setProgress(100);
        public ImageLoader(URL url, JLabel target) {
            this.url = url;
            this.target = target;
        @Override protected BufferedImage doInBackground() throws IOException {
            ImageInputStream input = ImageIO.createImageInputStream(url.openStream());
            try {
                ImageReader reader = ImageIO.getImageReaders(input).next();
                reader.addIIOReadProgressListener(listener);
                reader.setInput(input);
                return reader.read(0);
            } finally {
                input.close();
        @Override protected void done() {
            try {
                target.setIcon(new ImageIcon(get()));
            } catch(Exception e) {
                JOptionPane.showMessageDialog(null, e, "Error", JOptionPane.ERROR_MESSAGE);
        //demo
        public static void main(String[] args) throws IOException {
            final URL url = new URL("http://blogs.sun.com/jag/resource/JagHeadshot.jpg");
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch(url);
        static void launch(URL url) {
            JLabel imageLabel = new JLabel();
            final JProgressBar progress = new JProgressBar();
            progress.setBorderPainted(true);
            progress.setStringPainted(true);
            JScrollPane scroller = new JScrollPane(imageLabel);
            scroller.setPreferredSize(new Dimension(800,600));
            JPanel content = new JPanel(new BorderLayout());
            content.add(scroller, BorderLayout.CENTER);
            content.add(progress, BorderLayout.SOUTH);
            JFrame f = new JFrame("ImageLoader");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setContentPane(content);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
            ImageLoader loader = new ImageLoader(url, imageLabel);
            loader.addPropertyChangeListener( new PropertyChangeListener() {
                 public  void propertyChange(PropertyChangeEvent evt) {
                     if ("progress".equals(evt.getPropertyName())) {
                         progress.setValue((Integer)evt.getNewValue());
                         System.out.println(evt.getNewValue());
                     } else if ("state".equals(evt.getPropertyName())) {
                         if (SwingWorker.StateValue.DONE == evt.getNewValue()) {
                             progress.setIndeterminate(true);
            loader.execute();
    abstract class IIOReadProgressAdapter implements IIOReadProgressListener {
        @Override public void imageComplete(ImageReader source) {}
        @Override public void imageProgress(ImageReader source, float percentageDone) {}
        @Override public void imageStarted(ImageReader source, int imageIndex) {}
        @Override public void readAborted(ImageReader source) {}
        @Override public void sequenceComplete(ImageReader source) {}
        @Override public void sequenceStarted(ImageReader source, int minIndex) {}
        @Override public void thumbnailComplete(ImageReader source) {}
        @Override public void thumbnailProgress(ImageReader source, float percentageDone) {}
        @Override public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) {}
    }

  • [CS3][JS]avoid overlap image?

    Hi,
       When I am placing graphic/Image, Is there any way to avoid overlap image( the image lie on the top of other image)? When I am placing textframe in the document, textframe has the textwrappreferences to avoid the overlap. Like that is it possible with Image? I have placed my graphic/image inside the textframe/rectangle.
    Please advice me.Sorry for any confusion.
    Regards,
    Kumar.

    You should understand what happens with the text in a text frame, when it hits the border of a Text Wrapped object. The text itself reflows; yet, it stays inside its own text frame. If the text frame is not large enough to contain the reformatted text, you get the red 'overflow' marker.
    Now imagine there is such a thing such as Image Wrap. You import an image and -- as usual -- you want its frame to have exactly the size of the image itself. What happens if you drag this frame over another one? The image inside the image frame should shift, but where to? (As there is no such thing as 'overset image' -- you would need to invent that too!) So, still analogous to our text frame-with-text (where the text frame is usually much larger than actually needed), you would need to make the image frame large enough to have a reasonable space for the image inside it to move around.
    You can even try this out right now: cut an image and paste it into a text frame. Set the text leading to Automatic, so the image stays totally inside the text frame. Now drag this frame over another one with text wrap and see what happens to the image.
    As this is the Scripting forum, I suppose one could write a javascript that checks whether any image overlaps any other, but having the same javascript solve it automatically seems a bit optimistic.

  • How to draw make the overlapped images on a JToggle Button draggable

    Hello all:
    I have a JPanel chart set with GridBagLayout. Each cell is a JButton,
    I've create several overlaping images (from my existing images) using JLayeredPane
    and adding on one particular cell JToggleButton. The images are displayed, but I don't know
    how to make it draggable for users to drag to another cell within GridbagLayout.
    I have been stuck on this for a long time, I'd appreciate if anyone give me some help
    on this.

    Hi kglad -
    Thanks. That worked perfectly.
    Surely you jest with me.  Since I couldn't script a play button where in my brain do you think I would I find the cells to "use listeners for the video playing/stopping to control bigPlay_btn's _visible property".
    That's okay.  I'm sure after answering almost 50,000 questions it's easy to forget who you're talking to.
    Thanks again.
    Josh

  • New ways to overlap images in CS6?

    Is there any easy way to overlap a float-left image on top of a float-right image ?  I have read previously posted suggestions (layers, z-values..), but maybe it's made easier now in CS6 and CSS3?

    Probably need a little more info to give you a good answer. There are many ways to overlap images.
    The easiest would be to use one container with a background image, then place a standard <img> tag in the same container and position it accordingly.
    A couple of absolutely positioned elements with z-index would be another way.
    Relatively positioned elements with z-index would also work.
    It really all depends on what exactly you want to do and how your page is currently written.

  • 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.

  • Using Java Advanced Imaging (JAI) in Applet

    I'm trying to port a JAI user interface to an applet using Apache Tomcat. When I try to display an image in the applet I get an exception and I have no idea what the cause is. I've opened up security completely (temporarily) to ensure that I'm not getting an error due to an applet security issue. Consequently, I'm able to browse/open files from the client.
    Here is the stack for the error I'm getting. Can anyone tell me what is causing this error? Thanks.
    Java(TM) Plug-in: Version 1.4.1_01
    Using JRE version 1.4.1_01 Java HotSpot(TM) Client VM
    User home directory = C:\Documents and Settings\Administrator
    Proxy Configuration: No proxy
    c:   clear console window
    f:   finalize objects on finalization queue
    g:   garbage collect
    h:   display this help message
    l:   dump classloader list
    m:   print memory usage
    o:   trigger logging
    p:   reload proxy configuration
    q:   hide console
    r:   reload policy configuration
    s:   dump system properties
    t:   dump thread list
    v:   dump thread stack
    x:   clear classloader cache
    0-5: set trace level to <n>
    java.lang.reflect.InvocationTargetException
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:324)
         at javax.media.jai.FactoryCache.invoke(FactoryCache.java:130)
         at javax.media.jai.OperationRegistry.invokeFactory(OperationRegistry.java:1669)
         at javax.media.jai.ThreadSafeOperationRegistry.invokeFactory(ThreadSafeOperationRegistry.java:481)
         at javax.media.jai.registry.RIFRegistry.create(RIFRegistry.java:340)
         at javax.media.jai.RenderedOp.createInstance(RenderedOp.java:805)
         at javax.media.jai.RenderedOp.createRendering(RenderedOp.java:853)
         at javax.media.jai.RenderedOp.getWidth(RenderedOp.java:2135)
         at com.abi.protmodule.GelDisplayData.getGelImage(GelDisplayData.java:558)
         at com.abi.protmodule.ScrollingGelPanel.<init>(ScrollingGelPanel.java:58)
         at com.abi.ris.web.applet.GelEditPanel.showGelImage(GelEditPanel.java:76)
         at com.abi.ris.web.applet.GelEditApplet.openGelJButton_actionPerformed(GelEditApplet.java:159)
         at com.abi.ris.web.applet.GelEditApplet.chooseFileJButton_actionPerformed(GelEditApplet.java:136)
         at com.abi.ris.web.applet.GelEditApplet$1.actionPerformed(GelEditApplet.java:73)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
         at java.awt.Component.processMouseEvent(Component.java:5093)
         at java.awt.Component.processEvent(Component.java:4890)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3598)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3439)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Component.dispatchEvent(Component.java:3439)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
    Caused by: java.lang.NoSuchFieldError: borders
         at com.sun.medialib.mlib.Image.initIDs(Native Method)
         at com.sun.medialib.mlib.Image.<clinit>(Image.java:2903)
         at com.sun.media.jai.mlib.MediaLibAccessor$1.run(MediaLibAccessor.java:223)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sun.media.jai.mlib.MediaLibAccessor.setUseMlib(MediaLibAccessor.java:220)
         at com.sun.media.jai.mlib.MediaLibAccessor.useMlib(MediaLibAccessor.java:185)
         at com.sun.media.jai.mlib.MediaLibAccessor.isMediaLibCompatible(MediaLibAccessor.java:391)
         at com.sun.media.jai.mlib.MediaLibAccessor.isMediaLibCompatible(MediaLibAccessor.java:314)
         at com.sun.media.jai.mlib.MlibScaleRIF.create(MlibScaleRIF.java:82)
         ... 39 more
    Could not find mediaLib accelerator wrapper classes. Continuing in pure Java mode.

    look at
    http://forum.java.sun.com/thread.jsp?thread=290960&forum=20&message=1261471
    and
    http://forum.java.sun.com/thread.jsp?forum=20&thread=173410
    It's something related with DLL libraries...

  • Loading an image in an applet

    I am trying to load and display an existing image to my applet and break the image up into segments to allow the pieces to be moved into their correct position. However it is only getting as far as cutting the image up but it does not complete loading the image. Below is the run() method im using to load it:
    public void run()
            int i;
            MediaTracker trackset;              // Tracker for images
            Image WholeImage;                 // The whole image
                        Image ResizedImage;
            ImageFilter filter;
         // Determine the size of the applet
         r = getSize();
            // Load up the image
            if (getParameter("SRC") == null)
              Error("Image filename not defined.");
         WholeImage = getImage(getDocumentBase(), getParameter("SRC"));
         // Scale original image if needed
            // Make the image load completely and put the image
            // into the track set.  Where it waits in paint() method.
            trackset = new MediaTracker(this);
            trackset.addImage(WholeImage, 1);
            // Mix up the puzzle
            System.out.println("Mixing puzzle.");
            PaintScreen = 2;
            repaint();
            try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            // Tell user of the wait for image loading
           //Trap trackset exceptions that track if the image
           //hasn't loaded properly and output to the user.
            PaintScreen = 0;
            repaint();
            try {
            Thread.sleep(100);
         } catch (InterruptedException e) {
            try {
               trackset.waitForID(1);
            } catch (InterruptedException e) {
               Error("Loading Interrupted!");
            // Check if image loaded up correctly
            //Where is image is held in the same directory
            //as the HTML file use getImage method to pass
            //getDocumentBase(), taking in the getParameter.
            if (WholeImage.getWidth(this) == -1)
                 PaintScreen = 3;
                 repaint();
                 WholeImage = getImage(getDocumentBase(), getParameter("SRC"));
                 trackset = new MediaTracker(this);
                 trackset.addImage(WholeImage, 1);
                 try {
                    trackset.waitForID(1);
                 } catch (InterruptedException e) {
                    Error("Loading Interrupted!");
                 if (WholeImage.getWidth(this) == -1)
                      PaintScreen = 4;
                      repaint();
                      stop();
                      return;
         // Resize picture if needed.
         int ResizeOption = integerFromString(getParameter("RESIZE"));
         if ((r.width != WholeImage.getWidth(this) ||
              r.height != WholeImage.getHeight(this)) &&
                ResizeOption != 0)
              if (ResizeOption == 2)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_FAST);
              else if (ResizeOption == 3)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_SMOOTH);
              else if (ResizeOption == 4)
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_AREA_AVERAGING);
              else
                ResizedImage =
                  WholeImage.getScaledInstance(r.width, r.height - TOP_MARGIN,
                                     WholeImage.SCALE_DEFAULT);
              trackset.addImage(ResizedImage, 2);
              PaintScreen = 5;
              repaint();
              try {
              Thread.sleep(100);
              } catch (InterruptedException e) {
              try {
              trackset.waitForID(2);
              } catch (InterruptedException e) {
              Error("Loading Interrupted!");
              WholeImage = ResizedImage;
            // Complete loading image.  Start background loading other things
            // Also put image into the Graphics class
            // Split up main image into smaller images
            PaintScreen = 1;
            repaint();
            try {
               Thread.sleep(100);
            } catch (InterruptedException e){}
            piecewidth = WholeImage.getWidth(this) / piecesx;
            pieceheight = WholeImage.getHeight(this) / piecesy;
            System.out.println("Image has loaded.  X=" +
                               WholeImage.getWidth(this) + " Y=" +
                               WholeImage.getHeight(this));
            imageset = new Image[totalpieces];
            for (i = 0; i < totalpieces; i++)
                 filter = new CropImageFilter(GetPieceX(i) * piecewidth,
                                              GetPieceY(i) * pieceheight,
                                              piecewidth, pieceheight);
                 imageset[i] = createImage(new
                                           FilteredImageSource(WholeImage.getSource(),
                                                               filter));
            // Set up the mouse listener
            System.out.println("Adding mouse listener.");
            addMouseListener(this);
            // Complete mixing the image parts
            System.out.println("Displaying puzzle.");
            PaintScreen = -1;
            repaint();
            while (end != null)
              try {
                 Thread.sleep(100);
              } catch (InterruptedException e){}
         }Any help to where im going wrong would be much appreciated. Thanks!

    ive seen this one many times and it dosent work for me! Shouldnt the second parameter of the getImage(...) method not include the 'http://..." part as that what getDocumentBase() is for, returning the URL of the page the applet is embedded in? I have tried using code like this and event getting a printout of the doc/code base into the console to make sure my images are in the right place (.gif images), and nothing's happening, null pointer every time!
    {code}
    Image image;
    public void init() {
    // Load image
    image = getImage(getDocumentBase(), "http://hostname/image.gif");
    public void paint(Graphics g) {
    // Draw image
    g.drawImage(image, 0, 0, this);
    {code}
    ps this code is from the site mentioned above
    Edited by: Sir_Dori on Dec 8, 2008 8:37 AM

  • Help!  Image in an applet

    Hi, I'm having some trouble displaying an image in my applet. I drew something in MS Paint, saved it as a gif, and want to draw it in my applet. I have tried using two methods to load the image:
    map = getImage(getCodeBase(),"cheese.gif");
    and
    Toolkit toolkit = getToolkit();
    map =toolkit.createImage("cheese.gif");
    System.out.println(map == null) prints false for both methods, meaning that (I assume) Java has found and knows what .gif I am requesting. I am drawing the image with
    g.drawImage(map, 25, 150, this);
    I have tried replacing "this" with "getContentPane()" as well, but that was fruitless.
    I think am importing all the right classes, like java.awt.*.
    My applet extends JApplet (I don't know this has anything to do with it). I would post the entire applet, but it is quite lengthy at the moment. Any help would be much appreciated, thanks in advance, and sorry about the long post. If anyone needs anymore information to help me, I will be glad to help.

    Try this html and code:
    <HTML>
        <HEAD>
            <TITLE></TITLE
        </HEAD>
        <BODY>
            <APPLET CODE="ImgApplet.class" width=500 height=500>
            <PARAM NAME=pic VALUE="ImgAppletPic.jpg">
            </APPLET>
        </BODY>
    </HTML>
    import java.awt.*;
    import java.applet.*;
    public class ImgApplet extends Applet {
        // var to store the pic;
        Image pic;
            // retrieving image;
            public void init() {
            pic = getImage(getCodeBase(), getParameter("pic"));
            public void paint(Graphics g) {
            g.drawImage(pic, 10, 10, this);
    }

  • Displaying an image in an applet

    hi there - can anyone tell me why the following code only displays the image through the applet viewer but when i load it in a browser it just displays a grey square the same size as the image i'm trying to load?! many thanks.
    import java.awt.*;
    import javax.swing.*;
    import java.net.*;
    public class DisplayImage extends JApplet
         public void init()
              ImageIcon icon = null;
              try
                   icon = new ImageIcon(new URL(getCodeBase(), "map.jpg"));
              catch(MalformedURLException e)
                   System.out.println("Failed to create URL:\n" + e);
                   return;
              int imageWidth = icon.getIconWidth();
              int imageHeight = icon.getIconHeight();
              resize(imageWidth, imageHeight);
              ImagePanel imagePanel = new ImagePanel(icon.getImage());
              getContentPane().add(imagePanel);
         class ImagePanel extends JPanel
              public ImagePanel(Image image)
                   this.image = image;
              public void paint(Graphics g)
                   g.drawImage(image, 0, 0, this);
              Image image;

    Rat fans!

  • Overlapping Images Via A Link

    It's safe to say that I'm pretty new to Dreamweaver... I know
    a little bit, just a heads-up.
    I know more Flash than Dreamweaver.
    I've got two frames, frame one, frame two. In frame one are
    the text links... RedDots, BlueDots, GreenStars, YellowStars. Each
    of these text links links to an image coresponding to its name. In
    frame two is the image (a white circle for arguments sake) that
    will change. I've easily gotten the text links changing the image
    in frame two, you click on RedDots and the image in frame two
    changes to the RedDots image, you click on BlueDots and the image
    in frame two changes to the BlueDots image, etc, etc.
    What I want to do is overlap those images as they are clicked
    on. So you have the white circle in frame two and when you click on
    GreenStars that image is placed over top the white circle in frame
    two. Then if you click on YellowStars that image is placed over the
    GreenStars which is over top the white circle, etc, for up to 6
    overlapping images.
    Also, I would need a separate link that will allow the user
    to go back one step. If they placed the RedDots over the BlueDots
    by mistake and really wanted the GreenStars, they could click this
    'go back one' link.
    Any help is appreciated!
    Thank you!

    Hi,
    Please look under Sample Application page 13.
    In general it is passed with IR_ to the field name...
    select 'f?p='||:APP_ID||':2:'||:app_session||':::2,RIR:IR_CUST_STATE:'||...
    I hope this is helpful
    LK

  • Help with registering (aligning) two partially overlapping images

    I have been digging into the JAI / Java2D algorithms, and I am looking for an algorithm for analyzing two partially overlapping images and returning the coordinates at which to render the second image relative to the first image. The desired end result is to be able to create a mosaic from a series of overlapping tiles. Is there a simple function, transform or library that I've overlooked?
    Thanks.

    EWirch wrote:
    Thanks - it is an interesting problem, but it needn't really be intelligent. One could think of it like stitching a panorama from a series of individual images. I know the relationship between image A and image B (A is to the left of B). There is about 50 pixels of overlap (approximately the 50 right pixels in image A are on the left of image B). I just need a way to find the exact positioning / overlap of image B relative to image A, and thought that brute force is not the proper approach, given that this may be a problem others have seen or conquered.If it were only that simple, and your example is exactly the one I was thinking of. The problem that comes to my mind is one of perspective. You have to take into consideration a spherical projection of the images that are being matched, not to mention the dynamic elements of the scenes. There has to be some sort of heuristic that allows you to find a match that is good enough, that is within some level of tolerance, and this won't be easy to do. But again, I am no graphics expert. I hope someone smarter than I comes along with a decent solution.

  • Add Image to an Applet

    How do I add an image to an applet (along with other components:button, choice etc)? Sample code would be appreciated. I do not see any component to add image.
    Thanks.

    If you are using one of the getImage methods, they don't wait around for the image to load; they return immediately. So we use a MediaTracker to block program execution until the image is completely loaded. This is older java technology and will work in older versions of java. If you are using j2se 1.4+ then you can use the ImageIO class for loading an image.
    /*  <applet code="AppletImage" width="400" height="400"></applet>
    *  use: >appletviewer AppletImage.java
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    public class AppletImage extends Applet
        public void init()
            Button button = new Button("Button");
            Choice choice = new Choice();
            choice.add("item 1");
            choice.add("item 2");
            Panel north = new Panel();
            north.add(button);
            north.add(choice);
            TextField tf = new TextField("text field", 12);
            Panel fieldPanel = new Panel();
            fieldPanel.add(tf);
            ScrollPane scrollPane = new ScrollPane();
            scrollPane.add(new AppletImagePanel());
            Panel panel = new Panel(new BorderLayout());
            panel.add(scrollPane);
            panel.add(fieldPanel, "South");
            setLayout(new BorderLayout());
            add(north, "North");
            add(panel);
        public static void main(String[] args)
            Applet applet = new AppletImage();
            Frame f = new Frame();
            f.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent e)
                    System.exit(0);
            f.add(applet);
            f.setSize(400,400);
            f.setLocation(200,200);
            applet.init();
            applet.start();
            f.setVisible(true);
    class AppletImagePanel extends Panel
        Image image;
        public AppletImagePanel()
            loadImage();
        public void paint(Graphics g)
            super.paint(g);
            int w = getWidth();
            int h = getHeight();
            int imageWidth = image.getWidth(this);
            int imageHeight = image.getHeight(this);
            int x = (w - imageWidth)/2;
            int y = (h - imageHeight)/2;
            g.drawImage(image, x, y, this);
        public Dimension getPreferredSize()
            return new Dimension(image.getWidth(this), image.getHeight(this));
        private void loadImage()
            String fileName = "images/owls.jpg";
            MediaTracker tracker = new MediaTracker(this);
            URL url = getClass().getResource(fileName);
            image = Toolkit.getDefaultToolkit().getImage(url);
            tracker.addImage(image, 0);
            try
                tracker.waitForID(0);
            catch(InterruptedException ie)
                System.err.println("interrupt: " + ie.getMessage());
    }

Maybe you are looking for

  • Running java program in other machines

    i want to run my java program file in other machines , how i can do this without installing jdk1.3 on them?

  • Weblogic portal content published for future date.

    Hi, I am using Weblogic portal 10.3, need to publish a content item for futhre date , i tried adding the date and time to startDate property and published it, and the changes got reflected immediately. has any one got his done. Regards Chandrakant

  • No support for AVCHD video

    Currently Lightroom 4 does not seem to support .m2ts format video, will that change going forward? I'd like to be able to get the most out of my Sony A77, or at least be able to down sample it for use. Thanks!

  • Switching video from widescreen to fullscreen...

    It says quite clearly here: http://www.apple.com/ipodtouch/features.html#video +"Turn your iPod Touch to switch between widescreen and fullscreen".+ But you can't do this with videos played from the video section of the main screen (only with videos

  • Experienced FMS / Flex developer

    Hi, I need to add somebody on my team who is knowledgeable with FMS and Flex. You also need to know about RTMFP in the new FMS 4 (Enterprise) and/or Cirrus. Knowledge of PHP and MySQL are important, and how to effectively communicate with Flex/PHP. E