Results 1 to 12 of 12
  1. #1
    reborn567 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Exclamation Images not moving Please help!!!

    I have to do a school project that involves moving a rocket around a screen using images. I wrote most of the program on the school computers which has Windows XP and it worked perfectly fine. But when I tried to run the same program, unchanged, at home on my laptop which has Windows 7, the program would not work properly.

    The main problem is that the images (which are like pictures from the internet) do not move. They just load, but do not move.

    Please help me solve this problem.

    Thanks in advance.

    Oh btw, I'm using Ready to program Java IDE 1.7.1


    Code:
    Java Code:
    import java.awt.*;
    import javax.swing.*;
    
    public class rocketLaunch extends Frame
    {
        ImageIcon rocketUp, rocketUp2, rocketUp3, rocketUp4, rocketSide, rocketDown, rocketLand, rocketChute;
        ImageIcon launchPad, smoke, fire;
        ImageIcon moon, man, nasa;
        ImageIcon mainBooster, sideBooster, sideBooster2;
    
        boolean done;
    
        public rocketLaunch ()
        {
            super ("Rocket Launch"); // Set the frame's name
            setSize (1000, 600);     // Set the frame's size
    
            Toolkit dir = Toolkit.getDefaultToolkit ();
    
            launchPad = new ImageIcon (dir.getImage ("launch pad.gif"));
            rocketUp = new ImageIcon (dir.getImage ("rocket.gif"));
            fire = new ImageIcon (dir.getImage ("fire.gif"));
            sideBooster = new ImageIcon (dir.getImage ("side booster.gif"));
            sideBooster2 = new ImageIcon (dir.getImage ("side booster2.gif"));
            moon = new ImageIcon (dir.getImage ("moon.gif"));
            rocketUp2 = new ImageIcon (dir.getImage ("rocket2.gif"));
            smoke = new ImageIcon (dir.getImage ("smoke.gif"));
            rocketUp3 = new ImageIcon (dir.getImage ("rocket3.gif"));
            mainBooster = new ImageIcon (dir.getImage ("external tank.gif"));
            rocketSide = new ImageIcon (dir.getImage ("rocket side.gif"));
            man = new ImageIcon (dir.getImage ("man.gif"));
            rocketDown = new ImageIcon (dir.getImage ("rocket down.gif"));
            rocketLand = new ImageIcon (dir.getImage ("rocket land.gif"));
            rocketChute = new ImageIcon (dir.getImage ("rocket chute.gif"));
            nasa = new ImageIcon (dir.getImage ("nasa.gif"));
    
    
            done = false;
            show ();                // Show the frame
        } // Constructor
    
    
        public void paint (Graphics g)
        {
    
    
            while (done == false)
    
                {
    
                    g.setColor (Color.black);
                    g.fillRect (0, 0, 1000, 600);
    
                    g.setColor (Color.darkGray); //runway
                    g.fillRect (0, 500, 1000, 100);
    
                    g.setColor (Color.yellow);
                    for (int s = 10 ; s <= 1000 ; s = s + 50)
                    {
                        g.fillOval (s, 500, 5, 5);
                        g.fillOval (s, 587, 5, 5);  //lights on runway
                    }
    
                    launchPad.paintIcon (this, g, 0, 426);
                    nasa.paintIcon (this, g, 850, 395);
                    moon.paintIcon (this, g, 900, 100);
    
                    rocketUp.paintIcon (this, g, 28, 410);
    
                    for (int j = 0 ; j <= 19900000 ; j = j + 1)
                    {
                        double k = 1;
                        k = Math.pow (k, 2);    //delay
                    }
    
                    for (int i = 410 ; i >= 230 ; i = i - 1)
                    {
                        fire.paintIcon (this, g, 26, i + 50);
                        rocketUp.paintIcon (this, g, 28, i);
    
                        for (int j = 0 ; j <= 50000 ; j = j + 1)
                        {
                            double k = 1;
                            k = Math.pow (k, 2);    //delay
                        }
    
                        g.setColor (Color.black);
                        g.fillRect (26, i + 75, 46, 65);
                        smoke.paintIcon (this, g, 20, 440);
    
                        g.setColor (Color.darkGray); //runway
                        g.fillRect (0, 500, 1000, 100);
    
                        g.setColor (Color.yellow);
                        for (int s = 10 ; s <= 1000 ; s = s + 50)
                        {
                            g.fillOval (s, 500, 5, 5);
                            g.fillOval (s, 587, 5, 5);  //lights on runway
                        }
                    }
    
                    g.setColor (Color.black);
                    g.fillRect (26, 230, 100, 100);
    
                    int down = 280;
                    for (int i = 230 ; i >= 100 ; i = i - 1)
                    {
                        rocketUp2.paintIcon (this, g, 28, i);
    
                        if (down <= 350)
                        {
                            sideBooster.paintIcon (this, g, 50, down);
                            sideBooster2.paintIcon (this, g, 0, down);
                        }
    
                        for (int j = 0 ; j <= 50000 ; j = j + 1)
                        {
                            double k = 1;
                            k = Math.pow (k, 2);    //delay
                        }
    
    
                        g.fillRect (26, i + 75, 46, 65);
    
                        if (down <= 350)
                        {
                            g.fillRect (0, down, 100, 65);
                        }
    
                        down = down + 1;
                    }
    
                    down = 120;
                    for (int i = 100 ; i >= 45 ; i = i - 1)
                    {
                        rocketUp3.paintIcon (this, g, 28, i);
                        mainBooster.paintIcon (this, g, 28, down);
    
                        for (int j = 0 ; j <= 50000 ; j = j + 1)
                        {
                            double k = 1;
                            k = Math.pow (k, 2);    //delay
                        }
    
                        g.fillRect (26, i + 50, 46, 65);
                        g.fillRect (28, down, 50, 70);
    
    
                        down = down + 2;
    
                    }
    
                    g.fillRect (28, 145, 100, 120);
    
                    for (int i = 28 ; i <= 800 ; i = i + 1)
                    {
                        rocketSide.paintIcon (this, g, i, 45);
    
                        for (int j = 0 ; j <= 50000 ; j = j + 1)
                        {
                            double k = 1;
                            k = Math.pow (k, 2);    //delay
                        }
    
                        g.fillRect (i - 50, 45, 100, 60);
                    }
    
                    rocketSide.paintIcon (this, g, 800, 45);
                    man.paintIcon (this, g, 910, 60);
    
                    JOptionPane.showMessageDialog (null, "Houston, mission accomplished!! We are returning to base immediately.");
    
                    g.fillRect (800, 45, 100, 50);
                    g.fillRect (250, 300, 525, 200);
    
    
                    for (int i = 800 ; i >= 650 ; i = i - 1)
                    {
                        int diag = 1700 - i * 2;
                        rocketDown.paintIcon (this, g, i, diag);
    
                        for (int j = 0 ; j <= 90000 ; j = j + 1)
                        {
                            double k = 1;
                            k = Math.pow (k, 2);    //delay
                        }
    
                        g.setColor (Color.black);
                        g.fillRect (i, diag, 70, 80);
    
                    }
                    
                    for (int i = 650; i >= 500; i = i - 1)
                    {
                    
    
                    rocketLand.paintIcon (this, g, i, 1000-i );
                    }
                    rocketChute.paintIcon (this, g, 300, 525);
    
    
                    done = true;
                }
    
        } // paint method
    
    
        public static void main (String[] args)
        {
            new rocketLaunch ();    // Create a rocketLaunch frame
        } // main method
    } // rocketLaunch class
    Last edited by Fubarable; 11-07-2010 at 01:12 AM. Reason: moderator edit: code tags added

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Could you please post something you've done? Otherwise how we can comment on your question. Or at least explain here what you've done.

  3. #3
    reborn567 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Could someone please tell me any other program I can use to open and run my program, other than Ready to Program Java.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    If you want just give a try to run the code in command prompt. Did you?

    But why really want to try it in that way?

  5. #5
    reborn567 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    I thought maybe its the program that I'm running with which is kind of bugging out.

    Anyways, I am using GIF images and it is not moving. So I tried replacing the supposed to be moving GIF image to a JPEG image and it works.

    So it loads and moves JPEG images, but not GIF images. Any ideas?

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I kind of worry about your while (true) in a paint method. Paint should be very short and very fast. Also, you would be better off coding this in Swing.

  7. #7
    reborn567 is offline Member
    Join Date
    Nov 2010
    Posts
    4
    Rep Power
    0

    Default

    Ok I know it has definitely got to do with the fact that I am using Windows 7, and the fact that I am using GIF images.
    This is because i sent my program to my friend who has XP, and it worked perfectly fine on his computer.
    Also, when I replaced the GIF image with a random JPEG image, I could see the image moving.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    I kind of worry about your while (true) in a paint method. Paint should be very short and very fast. Also, you would be better off coding this in Swing.
    I agreed, gif take some time to render the status, could be conflict with paint.

  9. #9
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by reborn567 View Post
    Ok I know it has definitely got to do with the fact that I am using Windows 7, and the fact that I am using GIF images.
    This is because i sent my program to my friend who has XP, and it worked perfectly fine on his computer.
    Also, when I replaced the GIF image with a random JPEG image, I could see the image moving.
    Could you check in another Win7 PC? I've check your code and seems fine.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default

    To elaborate on what Fubarable said: don't try to paint multiple successive states by using a loop in a painting method override. Use a loop elsewhere, possibly on a background thread, or use a Swing Timer to update the state and call repaint() repeatedly.

    And never never never put business logic in a apinting method override either.

    db

  11. #11
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,235
    Rep Power
    19

    Default

    Quote Originally Posted by Eranga View Post
    Could you check in another Win7 PC? I've check your code and seems fine.
    A JOptionPane.showMessageDialog(...) in a painting method override seems fine to you?

    db

  12. #12
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. ordering moving images in swing
    By IAnkit in forum AWT / Swing
    Replies: 2
    Last Post: 09-21-2010, 03:56 PM
  2. [Applet] Clicking images & moving them.
    By Perfectworld in forum Java Applets
    Replies: 17
    Last Post: 01-16-2010, 08:09 AM
  3. Moving Box
    By anilanar in forum New To Java
    Replies: 2
    Last Post: 08-30-2009, 12:29 PM
  4. Moving Images in JPanel
    By killpoppop in forum AWT / Swing
    Replies: 7
    Last Post: 03-08-2009, 02:54 PM
  5. Moving textboxes
    By GabWit in forum New To Java
    Replies: 2
    Last Post: 01-26-2009, 04:07 PM

Posting Permissions

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