| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1893 人关注过本帖
标题:[求助]鼠标拖动事件
取消只看楼主 加入收藏
旋转女孩
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-3-22
收藏
 问题点数:0 回复次数:3 
[求助]鼠标拖动事件
package mousemotion;

import java.awt.Container;
import java.awt.Insets;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JButton;

public class MotionTest extends JFrame implements MouseMotionListener{

JButton button = new JButton("ok");

public MotionTest()
{
init();
}

public void init()
{
Container con = this.getContentPane();
con.setLayout(null);
button.setBounds(100,100,50,30);
button.setMargin(new Insets(1,1,1,1));
con.add(button);

button.addMouseMotionListener(this);

this.setTitle("鼠标拖动事件");
this.setSize(500,500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

public void mouseDragged(MouseEvent e){

button.setLocation(e.getX(),e.getY());
}

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
new MotionTest();

}

public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub

}
}
在方法体中还需要写些什么?

拖动按钮时总是不对

帮帮忙
搜索更多相关主题的帖子: 鼠标 拖动 
2007-04-05 11:34
旋转女孩
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-3-22
收藏
得分:0 
我也说不清楚.你们运行一下就知道了

拖动时按钮的移动不对劲

即使所有人反对,我依然坚持我的选择……
2007-04-05 12:13
旋转女孩
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-3-22
收藏
得分:0 
加了这句还是不行啊
移动起来还是不对……

SwingUtilities.updateComponentTreeUI(this);//加这个,强制更新组件树

即使所有人反对,我依然坚持我的选择……
2007-04-05 13:01
旋转女孩
Rank: 1
等 级:新手上路
帖 子:121
专家分:0
注 册:2007-3-22
收藏
得分:0 
我知道我哪儿错了

谢谢

即使所有人反对,我依然坚持我的选择……
2007-04-05 13:15
快速回复:[求助]鼠标拖动事件
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025774 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved