0

I am trying to make a chess application, currently i can create the chess board using JPanels in an 8x8 grid, and initialize the chess pieces on the board after implementation. My current problem is figuring out a way to move the images using mouse listeners. In the process figuring this out, i managed to switch the image from one to another as an experiment but this was a semi success as it only did it one way and couldn't change it back.

This lead to me realising the best way to do this is to retrieve the fill path as a string from the image.

My Question: Is there a way to retrieve the file path from the image, or would it be best to have the file path stored within the chess piece classes as a string and change the image using retrieved string?

IgnisSnowman
  • 57
  • 1
  • 6
  • You cannot get the file path from the Image – ControlAltDel Oct 10 '15 at 09:59
  • Store the images within the application context, within your applications classpath/jar. Have them stored in a well know location which you can access simply via `Class#getResource` – MadProgrammer Oct 10 '15 at 10:13
  • 1
    See also the [tag:embedded-resource] info tab, this [example](http://stackoverflow.com/a/2562685/230513) and [variation](http://stackoverflow.com/a/2563350/230513), as well as this [Q&A](http://stackoverflow.com/q/21142686/230513). – trashgod Oct 10 '15 at 10:24
  • 1
    @trashgod *"..as well as this Q&A."* Yes, that'd be how I'd approach this (squints at link). OK.. that's how I **did** that. ;) – Andrew Thompson Oct 10 '15 at 12:47

1 Answers1

0

My current problem is figuring out a way to move the images using mouse listeners.

Here is an example that moves Icons from one label to another: Drawing in JLayeredPane over exising JPanels

It is a simple example of creating a chess board and dragging the icons.

Community
  • 1
  • 1
camickr
  • 321,443
  • 19
  • 166
  • 288