int cannot be dereferenced

The g in drawString is the color value you’ve passed in, not your Graphics reference. So the error is when you’re trying to call a method on an int, which you can’t do.

//            Passing an integer 'g' into the function here |
//                                                          V
public void drawString(String str, int x, int y, int r, int g, int b){
//  | This 'g' is the integer you passed in
//  V
    g.setColor(r, g, b);
    g.drawString(str, x, y, 0);
}

Leave a Comment