4 Replies - 3823 Views - Last Post: 18 April 2009 - 12:31 PM Rate Topic: -----

#1 mikeuk20  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 17-April 09

New to Java, how can I insert an image into this code?

Posted 17 April 2009 - 03:01 PM

Hi guys,

I'm trying to make a Pong game for java however I'm trying to insert an image of a ball into this code:
	
public Ball() {
		super();
		 ball = getImage("ballimage.gif");
		 Ball = new Thread(this);
		 Ball.start();

	}



However this isn't working, my image is in my Source Packages folder along with the main class and other class, however it won't appear. How could I get an image of a ball in that code so that it will move?

Sorry if this is a silly question but Im really new to java!
Thanks Alot

Is This A Good Question/Topic? 0
  • +

Replies To: New to Java, how can I insert an image into this code?

#2 markjnj  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 122
  • Joined: 27-October 08

Re: New to Java, how can I insert an image into this code?

Posted 17 April 2009 - 05:07 PM

try putting getDocumentBase() somewhere in there

View Postmikeuk20, on 17 Apr, 2009 - 02:01 PM, said:

Hi guys,

I'm trying to make a Pong game for java however I'm trying to insert an image of a ball into this code:
	
public Ball() {
		super();
		 ball = getImage("ballimage.gif");
		 Ball = new Thread(this);
		 Ball.start();

	}



However this isn't working, my image is in my Source Packages folder along with the main class and other class, however it won't appear. How could I get an image of a ball in that code so that it will move?

Sorry if this is a silly question but Im really new to java!
Thanks Alot

Was This Post Helpful? 0
  • +
  • -

#3 NeoTifa  Icon User is offline

  • Whorediot
  • member icon





Reputation: 2631
  • View blog
  • Posts: 15,651
  • Joined: 24-September 08

Re: New to Java, how can I insert an image into this code?

Posted 17 April 2009 - 07:01 PM

Did you declare ball to be a graphics object? You could also just make a plain colored elipse that looks like a ball like I did. Works just as good, unless you're hellbent on that image.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

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

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

Re: New to Java, how can I insert an image into this code?

Posted 17 April 2009 - 09:38 PM

Easiest way put it in a JLabel and move the JLabel

ImageIcon ball = new ImageIcon("ballimage.gif");
JLabel bLabel = new JLabel(ball);
Was This Post Helpful? 0
  • +
  • -

#5 mikeuk20  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 7
  • Joined: 17-April 09

Re: New to Java, how can I insert an image into this code?

Posted 18 April 2009 - 12:31 PM

Thanks for the replys :)

NeoTifa could you run me through how to create a simple eclipse as that would be perfect!

Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1