跪求高人指点,swt中按钮拖动功能。
来源:百度知道 编辑:UC知道 时间:2024/06/15 01:09:00
aaronswon 你的答案很好啊,但是有问题啊。就是只能点一次图片,然后再点,上一次的就没有了,。还有就是图片点进画布过后就再也不能移动了啊。。
//////it works.. 修改过了
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.net.MalformedURLException;
public class ImageButton extends JFrame implements Runnable {
private static final long serialVersionUID = 1L;
JButton b = new JButton();
Canvas c = new Canvas();
Graphics g = null;
String imagePath = "F:/16.png";
File file = new File(imagePath);
ImageIcon icon = null;
boolean begin = false;
int x = 0;
int y = 0;
private void init() {
try {
icon = new ImageIcon(file.toURI().toURL());
b.setIcon(icon);
b.setSize(icon.getIconWidth(), icon.getIconHeight());
this.setBounds(400, 300, 760, 520);
this.setResizable(false);
this.addWindowListener(new WindowAdapter() {