高手请指教!!怎样实现鼠标的拖放功能 如何实现把按扭的图标通过鼠标拖拽事件把他转移到画图区域??? 解决方案 » 免费领取超大流量手机卡,每月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); } }); } } 小菜鸟求助 一个小问题 String xx = "object"; 生成几个对象??如何验证 点击按钮后作图 特殊的表查询问题 帮忙找一下问题所在. 请教关于struts 多线程技术会提高程序的运行效率吗? 又是一题scjp。 打击,大急,帮忙,谢谢 -- 关于如何设置JLabel,JTextField的多行显示 真的没人懂吗?????????一个毕业设计题目都没人懂??? 请问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);
}
});
}
}