同学们,请问怎样实现通过拖动将两个按钮对换位置的操作,我继承了一个DropTargetAdapter类,奇怪的是没有反应,困扰了好多天,大家帮帮忙- class ButtonDropTargetListener extends DropTargetAdapter{
- JButton jbut,temp;
-
- public ButtonDropTargetListener() {
- // TODO Auto-generated constructor stub
- }
-
- public ButtonDropTargetListener(JButton jbut){
- this.jbut = jbut;
- }
-
- @Override
- public void drop(DropTargetDropEvent event) {
- // TODO Auto-generated method stub
- Rectangle r = jbut.getBounds();
- jbut.setBounds(temp.getBounds());
- temp.setBounds(r);
- System.out.println("drop");
- event.dropComplete(true);
- }
-
- public void dragExit(DropTargetEvent event){
- temp = jbut;
- System.out.println("exit");
- }
- }
复制代码 |