高手请指教!!怎样实现鼠标的拖放功能 如何实现把按扭的图标通过鼠标拖拽事件把他转移到画图区域??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 给你个按钮跟着鼠标移动的代码import java.awt.*; import java.awt.event.*; import javax.swing.*; public class TestDraged extends JFrame { public Button button; Panel panel; static Point origin = new Point(); int x=0; int y=0; public TestDraged() { super("TestMouseDragged"); this.setSize(600,400); button=new Button("Test MouseDragged"); panel=new Panel(); panel.add(button); getContentPane().setLayout(new BorderLayout()); getContentPane().add("Center",panel); button.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { origin.x = e.getX(); origin.y = e.getY(); } }); button.addMouseMotionListener(new MouseMotionAdapter() { public void mouseDragged(MouseEvent e) { Point p = button.getLocation(); button.setLocation(p.x + e.getX() - origin.x, p.y + e.getY() - origin.y); repaint(); } }); } public static void main(String args[]) { TestDraged app=new TestDraged(); app.setVisible(true); app.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } } java 综测评分管理系统 递归问题 SQL 的别名中,遇到的问题!!!!!!!!!!!!!!!! jdk1.5环境变量的设置 请问文件对话框和消息框分别是哪个类? netbeans5.0怎么样把java文件生成exe文件 请问如何用正则表达式处理HTML标签? 求助:java里的InputData找不到符号 请问怎么样使另一个窗口从最小化变为NORMAL? 怎样对j2sdk1.4设置,才能够使用它来编辑和编译java程序??? 真的没人懂吗?????????一个毕业设计题目都没人懂??? 请问java结合c语言一般应用在什么场合?能否举个例子?
import java.awt.*;
import java.awt.event.*;
import javax.swing.*; public class TestDraged extends JFrame
{
public Button button;
Panel panel;
static Point origin = new Point();
int x=0;
int y=0; public TestDraged()
{
super("TestMouseDragged");
this.setSize(600,400);
button=new Button("Test MouseDragged");
panel=new Panel();
panel.add(button);
getContentPane().setLayout(new BorderLayout());
getContentPane().add("Center",panel); button.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e)
{
origin.x = e.getX();
origin.y = e.getY();
}
});
button.addMouseMotionListener(new MouseMotionAdapter()
{
public void mouseDragged(MouseEvent e)
{
Point p = button.getLocation();
button.setLocation(p.x + e.getX() - origin.x, p.y + e.getY()
- origin.y);
repaint();
}
});
} public static void main(String args[])
{
TestDraged app=new TestDraged();
app.setVisible(true);
app.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
}