While g is in the paint method, an object of the Graphics class (which contains methods named setColor, fillRect, and also drawString) in the drawString method is g, defined as an integer that encodes the value for green. Especially in the line g.setColor(r, g, b); you use g to set the color on it, and also as an argument to set the color. int doesn't have a setColor method (which also doesn't make sense), so you get an error. You probably also want to get a Graphics object in this method. When you expand the canvas, you can get the graphic by calling getGraphics (), so your example might look like this:
public void drawString(String str, int x, int y, int r, int g, int b){ getGraphics().setColor(r, g, b); getGraphics().drawString(str, x, y, 0); }
Mnementh
source share