Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Paintwindow moving picture

  1. #1
    Junior Member
    Join Date
    Sep 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Paintwindow moving picture

    PaintWindow pw = new PaintWindow();
                            Random rand = new Random();
                            ImageIcon image = new ImageIcon("C:/Users/Ghostkilla/Desktop/gubbe.jpg");
                            setWidth(pw.getBackgroundWidth());
                            int height = pw.getBackgroundHeight();
                            int dx = -3;
                            int dy = 0;
                            int x = 250;
                            int y = rand.nextInt(height-100);  
     
     
                            while(true) {
                                    pw.showImage(image, x, y);
                                    PaintWindow.pause(20);
                                    x += dx;
                                    y += dy;
                                    if(x<0) {
                                            dx = -dx;
                                            dx = -dx;

    If you run this code it will move a picture from right to left and hit the left wall and then go to right again leaving the window (It stops there). I want to make so it hits left and then right wall continuesly till someones close the window. So basically im using a for loop to make it go left right all the time and i need help.


    Also I dont know how to make so the picture moves from bottomleftcorner to toprightcorner diagonally without leaving the window.
    Last edited by ghostkilla; September 30th, 2014 at 07:20 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,381
    Thanks
    53
    Thanked 2,397 Times in 2,350 Posts

    Default Re: Paintwindow moving picture

    Can you make a small, complete program that compiles, executes and shows the problem?

    What package is the PaintWindow class in? I don't recognize it as part of the Java SE packages.

    how to make so the picture moves from bottomleftcorner to toprightcorner diagonally
    Take a piece of paper and draw the picture in the various locations in the window and note the relationship between the x,y location of the image and its width and height when it is touching on the sides of the window.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 697 Times in 679 Posts

    Default Re: Paintwindow moving picture

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

Similar Threads

  1. pick a color on a picture
    By trenci.jack in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 14th, 2013, 12:39 AM
  2. HELP - placing picture on top of another picture in Java - JLayerPane
    By smasm in forum What's Wrong With My Code?
    Replies: 39
    Last Post: April 27th, 2012, 07:16 PM
  3. Converting a picture made up of 0s and 1s into a colored picture??
    By Kranti1992 in forum Java Theory & Questions
    Replies: 10
    Last Post: November 21st, 2011, 05:25 PM
  4. Need help with a Picture!
    By Scout in forum Java Theory & Questions
    Replies: 1
    Last Post: October 12th, 2009, 05:33 PM