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 2 of 2

Thread: Is this not how the drawImage works?

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

    Default Is this not how the drawImage works?

    I copied this right out of oracle almost. And yet it won't draw.

     ImageIcon salt = createImageIcon("icons/bathsalts.jpg");
     
    /**
         * @Override
         */
        public void draw(Graphics g){
     
            Graphics2D g2d = (Graphics2D) g;
            g2d.drawImage(salt, getX(), getY(), null);
        }
     
     
    Sorry it was a hasty post in frustration. I do not understand why draw image doesnt work for me. drawRect and circle are going just fine...
     
        protected static ImageIcon createImageIcon(String path) {
            try{
                java.net.URL imgURL = ButtonPanel.class.getResource(path);
                return new ImageIcon(imgURL);
            } catch(RuntimeException e) {
                System.out.println("Invalid file path");
            }
            return null;
        }
    Last edited by steuben; June 14th, 2014 at 11:54 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    4,739
    My Mood
    Mellow
    Thanks
    172
    Thanked 622 Times in 609 Posts

    Default Re: Is this not how the drawImage works?

    Have you made any progress? If you still need help, please provide a complete program that we can compile and run to locate the error.

Similar Threads

  1. Question on how this works?
    By sammythesp3rmy in forum Java Theory & Questions
    Replies: 1
    Last Post: December 8th, 2013, 04:11 PM
  2. Replies: 9
    Last Post: September 15th, 2013, 02:48 PM
  3. which class has a default constructor? (Req. guidance on constructor)
    By DragBall in forum Java Theory & Questions
    Replies: 1
    Last Post: June 27th, 2012, 04:42 PM
  4. how array works ?
    By erdy_rezki in forum Java Theory & Questions
    Replies: 4
    Last Post: May 1st, 2012, 09:57 AM
  5. I have no idea how this works.
    By GeneralPihota in forum Algorithms & Recursion
    Replies: 3
    Last Post: December 29th, 2011, 08:55 PM