applet - How to "disable a method" in java and make it active in an actionPerformed method if that makes any sense -


situation: calling method draw paint method. however, want draw if convert button clicked. how tell java not draw3drectangle unless (ae.getsource==convert)?? new gui can tell, simple answers please. appreciate help.

code:

public class simpgui extends applet implements actionlistener  {     button convert;    label celsius;    label farenheit;    textfield cels;    textfield fare;     string message = "";    public void init()   {      convert = new button("convert");      celsius = new label("celsius");      farenheit = new label("farenheit");      cels = new textfield(15);      fare = new textfield(15);       add(convert);      add(celsius);      add(cels);      add(farenheit);      add(fare);      convert.addactionlistener(this);    }    public void paint(graphics g)   {      fare.setlocation(160,50);      farenheit.setlocation(90,50);      convert.setlocation(310,5);      draw(g);    }    public void actionperformed (actionevent ae)   {      if(ae.getsource() == convert)      {          int farenheit = (int) ((double.parsedouble(cels.gettext())) * (1.8)) + 32;           fare.settext(farenheit+"");     }    }     public static void draw(graphics g)   {     g.setcolor(color.blue);     g.fill3drect(0,0,400,100,true);   } } 

methods can't "disabled" can use boolean variable , if statement achieve same functionality:

 boolean isclicked = false;   public void paint(graphics g)  {     super.paint();     fare.setlocation(160,50);     farenheit.setlocation(90,50);     convert.setlocation(310,5);     draw(g);  }   public void actionperformed(actionevent ae)  {       if (ae.getsource() == convert)       {            isclicked = true;       }  }   public void draw(graphics g)  {      if (isclicked)      {         g.setcolor(color.blue);         g.fill3drect(0,0,400,100,true);      }  } 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -