🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #16481

Re: newbe: Drag and Drop

#16481
From: oneself
Date: Sun, 14 Feb 1999 00:00
96 lines
3044 bytes

Vasudevan Srinivasan wrote:

> > Hi
>
> can you pls give some more details, like what is the component you are drag n
> dropping and whats to be accomplished ? Just discussing in the "component" level
> sounds too general.
>
> Vasu
>

I'm writing a chess game which uses the TransparentImage component to create the
elution of moving pieces. there are 64 chess piece (in the example i use two of these)

when a piece is dragged and then dropped on another piece the picture is copied to
the dropped on piece and the dragged piece is cleared:

    // this is the chess piece class
class ChessPiece extends TransparentImage {

 private piece;

 byte getPiece ()
 {
  return piece;
 }

 void setPiece ( byte newPiece )
 {
  piece = newPiece;
  // do some more stuff.
 }

    // this is the method the gets activated by the MouseAdapter
 public void onDragDrop ( ChessPiece source )
 {
  setPiece ( source . getPiece () );
  source . setPiece ( ChessPiece . EMPTY ); // = 0;
 }
}


    // the is the MouseAdapter
class ChessPieceAdapter extends MouseAdapter {

 public void mousePressed ( MouseEvent event )
 {
  dragged = true;
  source = ( ChessPiece ) event . getSource ();
 }

 public void mouseReleased ( MouseEvent event )
 {
  if ( dragged )
  {
   ( ( ChessPiece ) event . getSource () ) . onDragDrop ( source );

   source = null;
   dragged = false;
  }
 }

 ChessPiece source = null;
 boolean dragged = false;
}

    // this is the Frame
public class MyFrame extends Frame {

 private ChessPiece firstPiece = new ChessPiece ();
 private ChessPiece scondPiece = new ChessPiece ();

 private ChessPieceAdapter chessPieceAdapter = new ChessPieceAdapter ();

 public MyFrame ()
 {
  firstPiece . addMouseListener ( chessPieceAdapter );
  secondPiece . addMouseListener ( chessPieceAdapter );

  this . add ( firstPiece );
  this . add ( secondPiece );
 }

}



when i drag the firstPiece and drop it on the secondPiece what happens
is that in the mousePressed method the event . getSource method returns a
reference to the firstPiece object (as excepted), but in the mouseReleased
method the event . getSource () also returns a reference to the firstPiece
object ( and here I would have expected to get the socondPiece object).

any thought as to what I doing wrong may be helpful, thanks.
Technical Details
Message-ID: <36C6D6C3.86308016@usa.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <36C09E34.63CBD27A@usa.net> <36C1FD77.9C7652EA@netrisk.com> <36C1F349.ACBE561C@usa.net> <36C34A2B.1683FB63@netrisk.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,d37fb261fcea0d84
X-Google-Attributes: gidf74b3,public
From: oneself <oneself@usa.net>
Subject: Re: newbe: Drag and Drop
Date: 1999/02/14
Message-ID: <36C6D6C3.86308016@usa.net>
X-Deja-AN: 444242444
Content-Transfer-Encoding: 7bit
References: <36C09E34.63CBD27A@usa.net> <36C1FD77.9C7652EA@netrisk.com> <36C1F349.ACBE561C@usa.net> <36C34A2B.1683FB63@netrisk.com>
To: Vasudevan Srinivasan <vasudevan@netrisk.com>
Content-Type: text/plain; charset=us-ascii
Organization: Another Netscape Collabra Server User
Mime-Version: 1.0
Newsgroups: borland.public.jbuilder.java.language