• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

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

screw3d

Diamond Member
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!
 
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.
 
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 !
 
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.
 
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.
 
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.
 
Back
Top