資源簡介
Java入門-圖片的拖動處理(實例15).zip
代碼片段和文件信息
import?java.awt.*;
import?java.awt.event.*;
import?javax.swing.*;
import?javax.swing.event.*;
//圖片的拖動效果
public?class?DragPictureDemo?extends?Jframe?{
???JLabel?jlPic;?//圖片,用于拖動
???public?DragPictureDemo()?{
??? super(“圖片的拖動效果“);??//調用父類構造函數
??? Icon?image=new?ImageIcon(this.getClass().getResource(“1.jpg“));??//實例化圖標
jlPic?=?new?JLabel(image);??//實例化帶圖片的標簽
??????getContentPane().add(jlPic);??//增加標簽到容器上
??????
??????DragPicListener?listener=new?DragPicListener();??//鼠標事件處理
??????jlPic.addMouseListener(listener);??//增加標簽的事件處理
??????jlPic.addMouseMotionListener(listener);???????
??????
??????setSize(300200);??//設置窗口尺寸
??????setVisible(true);??//設置窗口為可視
??????setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);??//關閉窗口時退出程序
???}
???
???class?DragPicListener?implements?MouseInputListener{??//鼠標事件處理
??????Point?p=new?Point(00);?//坐標點
??? public?void?mouseMoved(MouseEvent?e){}
??? public?void?mouseDragged(MouseEvent?e){
??????? Point?newP=SwingUtilities.convert
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????27684??2004-05-09?23:37??1.jpg
?????文件??????180054??2004-07-21?19:03??21-1.bmp
?????文件????????1477??2004-07-21?18:50??DragPictureDemo$DragPicListener.class
?????文件????????1300??2004-07-21?18:50??DragPictureDemo.class
?????文件????????1718??2004-05-09?23:28??DragPictureDemo.java
評論
共有 條評論