In Office software we can insert and delete pictures, of course, can also move pictures, this move is how to achieve it.
I believe that the students who like to study must be very interested to know, I have consulted the data, combined with just learning GUI interface design, drag and drop function to achieve, we can refer to the code, their own drag and drop function to see, very good application Oh, I also found inside the Swingutilities.convertpoint (Lblpic, E.getpoint (), lblpic.getparent ()); This can be the screenshot of the program to change to the graphical interface, hey, with empty to change, Upgrade the next version.
Package software; Import java.awt.*; Import java.awt.event.*; Import javax.swing.*; Import javax.swing.event.*; public class Dragpicturedemo extends jframe{JLabel lblpic, public Dragpicturedemo () {super ("picture can Drag"); Setdefaultcloseo Peration (Jframe.exit_on_close); Below c://aa.jpg is you want to put in the picture position (the picture should be small, otherwise will cover the entire interface) Icon image=new imageicon ("c://aa.jpg"); Lblpic=new JLabel (image); Getcontentpane (). Add (Lblpic); Dragpiclistener listener=new Dragpiclistener (); Lblpic.addmouselistener (listener); Lblpic.addmousemotionlistener (listener); SetSize (320,240); SetVisible (TRUE); public static void Main (string[] args) {Dragpicturedemo obj=new dragpicturedemo ();}//Internal listener class//mouseinputlistener if implemented Many ports can be introduced into the system class Dragpiclistener implements Mouseinputlistener {point p=new Point (0,0), public void mousedragged (Mousee Vent e)/Drag function {point newp=swingutilities.convertpoint (Lblpic, E.getpoint (), lblpic.getparent ());//Below is the new location of the picture Lblpic.setlocation (Lblpic.getx () + (newp.x-p.x), (NEWP.Y-P.Y) +lblpic.gety ()); Lblpic.geTparent (); P=NEWP; Mousemoved (MouseEvent e) {} public void mouseclicked (MouseEvent e) {} public void mousereleased (MouseEvent e) { public void mouseentered (MouseEvent e) {} public void mouseexited (MouseEvent e) {} @Override//Mouse down time public void mousepre ssed (MouseEvent e) {//TODO auto-generated Method Stub p=swingutilities.convertpoint (Lblpic, E.getpoint (), Lblpic.getparent ()); } } }