Java弌箭徨?幹秀匯倖辛溶廡夕頭議中医
扮寂:2011-04-05 csdn鴬人 提夛議佚剿
書爺壓胎務貧心欺愉徨錬李嬬壓 Swing 嶄糞??溶仇夕匯劔溶廡夕頭。宸戦頁匯倖恷 酒汽議糞??戻工阻匯倖児云房揃。
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.io.File;
/**
* 壓完悶貧溶廡夕頭。聞喘圭隈?褒似完悶**易侃繍氏起竃嬉蝕夕頭斤三崇。嬉蝕夕 頭朔辛參壓完悶貧溶廡夕頭。
*/
public class DragingFrame extends JFrame {
/**
* 更夛痕方
*
* @throws HeadlessException ???
*/
public DragingFrame() throws HeadlessException {
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(new ImagePanel(), BorderLayout.CENTER);
}
// 殻會秘笥
public static void main(String[] args) throws Exception {
UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName());
DragingFrame frame = new DragingFrame();
frame.setSize(400, 300);
frame.setLocation(300, 300);
frame.setResizable(false);
frame.setTitle("褒似嬉蝕夕頭?隼朔溶廡");
frame.setVisible(true);
}
}
/**
* 嬬校溶廡夕頭議中医
*/
class ImagePanel extends JPanel {
private DragStatus status = DragStatus.Ready; // 溶廡彜蓑
private Image image; // 勣?幣議夕頭
private Point imagePosition = new Point(0, 0), // 夕頭議輝念 了崔
imageStartposition = new Point(0, 0), // 耽 肝溶廡蝕兵扮夕頭議了崔?匆祥頁貧肝溶廡朔議了崔?
mouseStartposition; // 耽肝溶廡蝕兵扮報炎議了崔
ImagePanel() {
addMouseListener(new MouseListener() {
// 褒似報炎扮嬉蝕夕頭
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
openImage();
}
}
// 梓和報炎扮?厚個彜蓑?旺拝芝村溶廡軟兵了崔。
public void mousePressed(MouseEvent e) {
if (status == DragStatus.Ready) {
status = DragStatus.Dragging;
mouseStartposition = e.getPoint ();
imageStartposition.setLocation (imagePosition.getLocation());
}
}
|