English 中文(简体)
联合国
原标题:Implementing Drag and Drop using MouseListener for custom Components
  • 时间:2010-03-31 21:07:18
  •  标签:
  • java
  • swing

我正在从事一项学校任务,这要求我能够挑选一个徒劳无益的、将它拖到一个地点,然后将它推向一个地点。 我能够利用<密码>TransferHandler<>/code>和从分机组中穿戴的刀子,但根据教授的说法,这并非是履行这一职责的一种可以接受的方式。 因此,我试图通过<代码>MouseListener接口实现同样的效果。

基本结构是:我有一个<条码>。 意见载有<编码>JLabel -dervived cases of TileView。 我需要了解一些事件,这些事件使我了解一下:,这些话题已经修改,而LocationView则已公布。 我正在通过<代码>TileView将其包含在上的模拟活动。 观点,以便我能够妥善处理<条码>受压力的活动。

添加<代码>Systemout.println( s to the mouselecters for mousePressedmouseReleased Location> 观点和<条码> 令我惊讶的是,在A号地点将Tile A的 mo变,然后拖到B号地点,放行将给Tile A和A号地点,而不是B号地点造成一个烟雾释放事件。

为努力围绕这一点开展工作,我尝试在上找到一个玻璃灯。 在添加玻璃灯并添加一个活动听众之后,我可以看到,模拟活动确实通过玻璃灯过滤,但释放的模拟活动仍然只被点击。

是否有办法把与同一行动有关的<代码>mousePressedmouseReleased活动分别列为单独的构成部分?

EDIT: Here is the solution that I arrived at, based off of the answer by lins314159

public void mouseReleased(MouseEvent e) {
    Point p = SwingUtilities.convertPoint(LocationView.this, ((Component)e.getSource()).getLocation(), LocationView.this.wsa.getGameView());
    e.translatePoint((int) p.getX(), (int) p.getY());
    Component tile = SwingUtilities.getDeepestComponentAt(LocationView.this.wsa.getGameView(), e.getX(), e.getY());
}
最佳回答

虽然有可能有<代码>mouseReleased,但实际成分是作为来源释放的,但会比其价值更加麻烦。

下面可以用来确定烟雾释放的成分。

public void mouseReleased(MouseEvent evt) {
    Point p = ((Component) evt.getSource()).getLocation();
    evt.translatePoint((int) p.getX(), (int) p.getY());
    Component tile = f.getContentPane().getComponentAt(evt.getX(), evt.getY());
}
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签