java - I want to move the rectangle with mouse drag over the image, What's wrong with the code -


any code below...

i want move rectangle mouse drag on image, what's wrong code. need paint image or jlabel causing problem.

 public class imagecrop  extends jframe  {           int  x,y,width=90, height=96 ;       public imagecrop(bufferedimage image) {            super("crop");                    getcontentpane().setlayout(null);         setsize(546, 452);         jlabel lblnewlabel = new jlabel(corner(image));         lblnewlabel.setbounds(0, 0, 530, 382);         getcontentpane().add(lblnewlabel);         jbutton btnnewbutton = new jbutton("ok");         btnnewbutton.setbounds(220, 393, 89, 21);         getcontentpane().add(btnnewbutton);         setvisible(true);     }      private imageicon corner(bufferedimage image) {          javaxt.io.image image1 = new javaxt.io.image(image);         image1.setheight(382);         image=image1.getbufferedimage();         imageicon image2 = new imageicon(image);          addmousemotionlistener(new mouseadapter()         {              @override             public void mousedragged(mouseevent e) {                 repaint();                 x=e.getx();                 y=e.gety();         }});         graphics2d graph = (graphics2d) image.getgraphics();         graph.draw((shape) new rectangle( x, y, width, height));         system.out.println(x+y);         return image2;         }     } 

you in fact create image once , store in jlabel. after coordinates changed image not recreated.

i suggest ot override paintcomponent() method of jlabel , call g.draw((shape) new rectangle( x, y, width, height)); in method reflect changes.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -