0

I'm making a game for my software design class. I have a JPanel set up where I drag and drop these 100x100 pixel JLabels around the screen (the game is essentially a puzzle that snaps these labesls to locations on my panel). My professor says that he'd prefer I not use JLabels, so I need some advice on what you all think I could use. I need an object that:

  1. I can size to 100x100 pixels

  2. I can set an on click mouse listener

  3. I can change the location of it in the JPanel based on an (x,y) pair (in pixels)

  4. And, finally, I need to draw some lines on top of it. So, based on four values (x0,y0,x1,y1). I need to draw a solid line from a pixel point on the square, say from (0,50) to (50, 50). Would look something like: (with multiple lines)

Example Square:

https://i.stack.imgur.com/xY0Ki.jpg

Any suggestions? Also, any help on where to find how to draw on top of these projects?

Thanks!

seenukarthi
  • 8,241
  • 10
  • 47
  • 68
pcd13
  • 51
  • 3
  • Is there any reason why he is asking you to not use jLabels? If you can't then I'd recommend just drawing objects and placing them into an array and testing their drawn (x,y) positions with where they are on the screen. Also, you could just take a photo and cut it up into , lets say 12 pieces (4*3) and then store them into an array (like a sprite sheet) and do the same thing. – Ashton Apr 08 '16 at 17:48
  • Create a drawing panel from a JPanel and draw your lines in the drawing panel. See this [Stack Overflow answer](http://stackoverflow.com/questions/34981403/bufferedimage-not-being-cleared-before-each-rendering/35002727#35002727) for an example of a drawing panel. – Gilbert Le Blanc Apr 08 '16 at 18:42
  • There is a good example here: http://stackoverflow.com/a/36161031/971067 – rdonuk Apr 08 '16 at 19:27
  • So we read in the lines to draw from a file of bytes, so I unfortunately can't pre-create the image because it could differ depending on the file he asks us to read in... – pcd13 Apr 08 '16 at 19:47

0 Answers0