How do I change the drawString font colour in java applet -


i have written paint method java applet , allows drawstring change colour whatever user inputs 3 text fields (r,g,b). default font colour black however, trying change green can't because font change colour have write g.setcolor(mixcolor). know how can make font colour start off green when run applet instead of black.

import java.awt.*; import java.awt.event.*; import java.applet.*;      public class text2 extends applet implements actionlistener {  font textfont;  textfield t1; textfield t2; textfield t3; int redcolor, greencolor, bluecolor; string as, ag, ab; button bttn; button bttn2;  public void init() {      // routine called system initialize     // applet.  sets font , initial colors     // applet.  adds button applet     // changing message color.      setbackground(color.lightgray);      // applet filled background color before     // paint method called.  button , message     // in applet appear on light gray background.      redcolor=0;     greencolor=0;     bluecolor=0;       textfont = new font("serif",font.bold,24);       t1 = new textfield("",12);     t2 = new textfield("",12);     t3 = new textfield("",12);         add(t1);     add(t2);     add(t3);      bttn = new button("change colour");     bttn2 = new button("reset");     // create new button.  "changecolour" text     // displayed on button.      bttn.addactionlistener(this);     bttn2.addactionlistener(this);     // set bttn send "action event" applet     // when user clicks button      add(bttn);     add(bttn2);        // add button applet,     // appear on screen.  }     public void paint(graphics g) {      // routine called system whenever content     // of applet needs drawn or redrawn.  displays     // name , reg number in proper colour , font.     this.bttn2.setlocation(600, 600);     color mixcolor = new color(redcolor, greencolor,bluecolor);     g.setcolor(mixcolor);     g.setfont(textfont);       // set font.     g.drawstring("welcome applet by: joshua", 330, 300);  }     public void actionperformed(actionevent e) {      // routine called system when user clicks     // on button.  response change colornum     // determines color of message, , call     // repaint() see applet redrawn     // new color.       if (e.getsource() == bttn2) {         t1.settext(null);         t2.settext(null);         t3.settext(null);      }      if (e.getsource() == bttn)     {          as=t1.gettext();         ag=t2.gettext();         ab=t3.gettext();         as=as.trim();         ag=ag.trim();         ab=ab.trim();          redcolor= integer.parseint(as);         greencolor= integer.parseint(ag);         bluecolor= integer.parseint(ab);          repaint();  // tell system applet needs redrawn     }   }  } 

you can use setforeground method. synatax setforeground(color.green). instead of green can take color value.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -