*SOLVED* Please help on Java Transferable interface..code inside

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
Please take a look at the codes below. I am supposed to implement a simple Chess program in java. Right the bottom of this code is the getTransfer() function, where I'm supposed to return an object of type ChessPiece, which is this class itself. How do i do this?

return this.something doesnt work. Any ideas?

Edit:

Solved..thanks to Yomicron.. You're DA man!!! :)

Loving this forum more every minute!
 

VBboy

Diamond Member
Nov 12, 2000
5,793
0
0
Not that I know what's wront, but you might want to explain exactly how it "doesn't work", i.e. what error message you get, etc.
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
My drag-and-drop doesnt work, as in my ChessPiece in my chessboard can be dragged, but it doesnt "move" to the square where i dropped it !
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
I've read all sorts of examples and googled *very* extensively, and found out that most of the examples merely repeats one or two examples from the same websites, and the examples doesnt apply to my program! :(

Anybody willing to help please PM me so that I can send my codes to you!! I've got till midnight b4 I'm screwed !


TIA a lot a lot.
 

manly

Lifer
Jan 25, 2000
13,331
4,100
136
Well your ChessPiece class doesn't compile. I'm not familiar with the Transferable interface, but I'll dig into the source code for a bit. I'm sure you've already read this?

http://java.sun.com/products/jfc/tsc/articles/dragndrop/

Just to be clear, the reason ChessPiece doesn't compile is because this.something does not exist. Specifically, why do you want to add the (missing) cp field to this class?

Because the class design is non-obvious to me, it helps if you explain the general design and I can make more sense of the implementation.

Edit:
Okay, I think I get the Transferable API now. To fix the compilation error on line 42, just
return this;

I think I see what you're saying about DnD not doing anything. Give me a bit to study that issue.
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
I've read through a lot of those things from various websites which show the exact same example.

I understand how the transferable interface works, but not in my particular case and I'm not clear on how to put it in code.

Thanks again.