errors in java.Animating An Image In Swing Utilizing The Swing Timer

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

34 Replies - 7273 Views - Last Post: 06 July 2011 - 01:42 AM Rate Topic: -----

#1 deadsoul09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 27-June 11

errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 07:47 PM

java.tutorials.Animating An Image In Swing Utilizing The Swing Timer
i've errors with those lines of code

 ballImage = ball_IMG_ICON.getImage(); 
//incompatible types
required: animation.mainPanel.image
found: java.awt.Image


 g2d.drawImage(ballImage, currentBall.getX(), currentBall.getY(), this); 
//cannot find symbol
symbol: method drawImage(animation.mainPanel.image,int,int,animation.mainPanel)
location: class java.awt.Graphics2D

..
deadsoul09

Is This A Good Question/Topic? 0
  • +

Replies To: errors in java.Animating An Image In Swing Utilizing The Swing Timer

#2 deadsoul09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 27-June 11

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:02 PM

this is the link of the original topic ..

http://www.dreaminco...he-swing-timer/
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:27 PM

We'll need to see more code.
What are ballImage and ball_IMG_ICON ?
How was ball_IMG_ICON initialized ?
Was This Post Helpful? 0
  • +
  • -

#4 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:33 PM

pbl The tutorial he linked to had everything you needed.

OP, I just ran that code in the tutorial just fine. The only thing I had to do was actually add ball.png. That package that you are referencing does not look familiar to me. You have changed it in some way that you have not said. Also, the other error may be due to the Java version you're running. What version are you running?
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:35 PM

View PostDogstopper, on 27 June 2011 - 11:33 PM, said:

pbl The tutorial he linked to had everything you needed.

Just wanted to make sure the cut & paste was correctly done :^:
Was This Post Helpful? 0
  • +
  • -

#6 deadsoul09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 27-June 11

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:36 PM

sir, i've posted the link to the complete original code .. hope u've time to look at it .. i'd appreciate it so much .. thanks ..

this is the link again .. :
http://www.dreaminco...he-swing-timer/

sir, i've posted the link to the complete original code .. hope u've time to look at it .. i'd appreciate it so much .. thanks ..

this is the link again .. :
http://www.dreaminco...he-swing-timer/
Was This Post Helpful? 0
  • +
  • -

#7 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:37 PM

I'm the one who approved the tutorial ;)

It works. You have edited it incorrectly somewhere. Show us the modifications you made to the original code. Also, look at my last post.
Was This Post Helpful? 0
  • +
  • -

#8 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:39 PM

View PostDogstopper, on 27 June 2011 - 11:37 PM, said:

Show us the modifications you made to the original code.

Now you ask the OP to show his code. Make up your mind Stephen :)
Was This Post Helpful? 0
  • +
  • -

#9 deadsoul09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 27-June 11

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:42 PM

i'm using netbeans 6.9 ..
and here is the code i've written with my own hands ..:
package animation;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
/**
 *
 * @author Khaled
 */
public class mainPanel extends JPanel {

    public static void prepareImage(image ballImage, mainPanel aThis) {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    public static class image {

        private static image getImage() {
            throw new UnsupportedOperationException("Not yet implemented");
        }

       
    }
 
         public image ballImage;
     ball currentBall = new ball();

    public mainPanel(){
        ImageIcon ballImageIcon = new ImageIcon("ball.png");
        ballImage = ballImageIcon.getImage();// this line has an error ..
        prepareImage(image.getImage(), this);
        currentBall.setX(10);
        currentBall.setY(10);
        setDoubleBuffered(true);
        ActionListener paintTimer = null;
        new Timer(15, paintTimer).start();
    }

  

    public void Paint(Graphics g){
        super.paint(g);
        Graphics2D g2d= (Graphics2D)g;
            g2d.drawImage(image.getImage(), currentBall.getX(), currentBall.getY(),this);
Toolkit.getDefaultToolkit().sync();  // this line has an error ..
g.dispose();
    }

    Action PaintTimer = new AbstractAction() {
        public void actionPerformed(ActionEvent e){
            currentBall.setX(currentBall.getX()+5);
            currentBall.setY(currentBall.getY()+5);
            repaint();
        }

        };


}


Was This Post Helpful? 0
  • +
  • -

#10 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:49 PM

It's your modification.

 public image ballImage;



That indicates it wants an image that is of the "special" class that you made. However, getImage() returns a java.awt.Image. If you want to continue doing what you are doing, then you will have rewrite Java's Image system.

My advice to you is to totally delete the static inner "image" class. My suspection is that NetBeans made that class for you because it couldn't find a class called "image". Case is important. "image" != "Image"
 public Image ballImage;



is correct.
Was This Post Helpful? 0
  • +
  • -

#11 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8332
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 08:51 PM

public image ballImage;

should be

public Image ballImage;

and I don't see why you added static classes and methods

You would be better to copy the whole tutorial
Make it work
Then start doing your modifications
Was This Post Helpful? 0
  • +
  • -

#12 deadsoul09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 27-June 11

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 09:00 PM

ok .. i got the image mistake i've done ..
i'll try to copy paste the project 1st .. i'd tell u if something happens .. thanks alot 4 u both .. i really appreciate it ..
Was This Post Helpful? 0
  • +
  • -

#13 deadsoul09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 27-June 11

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 09:16 PM

sir , i've copied and pasted everything and there are no errors .. but when i run the project .. it shows a blank grey frame with no ball .. with nothing .. what's wrong i've done ?
Was This Post Helpful? 0
  • +
  • -

#14 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2872
  • View blog
  • Posts: 11,031
  • Joined: 15-July 08

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 09:17 PM

You forgot to load ball.png or aren't loading it correctly. Depends on the IDE.
Was This Post Helpful? 0
  • +
  • -

#15 deadsoul09  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 27-June 11

Re: errors in java.Animating An Image In Swing Utilizing The Swing Timer

Posted 27 June 2011 - 09:24 PM

i copied and pated the tutorial .. it has noo errors .. should it load the ball automatically when i run ?? or should i write something on the runtime ??
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3