How to remove present color and get default color of an image using graphics in java -


i have image , use pre-defined position on create oval color. click on again remove oval , color .

this i've done objective,

imagepanel.java

public class imagepanel extends jpanel{     private image img;      public imagepanel(string img, string str){         //this(new imageicon(img).getimage());         }      public imagepanel(string path){         image img = new imageicon(path).getimage();         this.img = img;         dimension size = new dimension(img.getwidth(null), img.getheight(null));         setpreferredsize(size);         setminimumsize(size);         setmaximumsize(size);         setsize(size);         setlayout(null);           try{             bufferedimage image = imageio.read(new file(path));             int rgb = image.getrgb(66, 52);             system.out.println("colour is: "+rgb);         }catch(ioexception e){             e.printstacktrace();         }     }      public void paintcomponent(graphics g) {         g.drawimage(img, 0, 0, null);     } } 

then use below,

public class printdialog extends javax.swing.jdialog{  private int count = 0;  /**  * creates new form printdialog  */ public printdialog(java.awt.frame parent, boolean modal){     super(parent, modal);     initcomponents();     imagepanel panel = new imagepanel("example.jpg");     this.getcontentpane().add(panel);     this.setresizable(false);     this.setlocationrelativeto(panel);     this.pack(); }   private void formmouseclicked(java.awt.event.mouseevent evt){                             // todo add handling code here:     graphics g = getgraphics();     system.out.println("print y - " + evt.gety());     system.out.println("print x - " + evt.getx());      if ((evt.getx() >= 68 && evt.getx() <= 84) && (evt.gety() >= 44 && evt.gety() <= 72)){          count++;         if (count == 1){             system.out.println("count - 1");             g.setcolor(color.red);             g.filloval(66, 52, 20, 20);          } else if (count > 1){             g.setcolor(new color(-3692899));             system.out.println("min - 2");             g.filloval(66, 52, 20, 20);             count = 0;         }     }     g.dispose(); } } 

but couldn't default color of position when click on @ second time. means, can't remove oval created.

have ideas please? .

thank .


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -