Codename One Graphics call Method

Viewed 74

I am making my first learning steps with CN1 graphics.

I encounter difficulties when calling the paint method of the following class in the start () method.

public class DrawingCanvas extends Component {

     public void myMethod(Graphics g) {

        // some code
    }

}

In the start() method, I call the method like this:

 public void start() {

     DrawingCanvas drawingCanvas = new DrawingCanvas();           
     drawingCanvas.myMethod(g);

 }

The error message I get is : Cannot find symbol : variable g

In my understanding, I now have to define g somehow.

How do I do that?

 Graphics g = 
1 Answers

You can't and don't initialize graphics. Graphics is created internally within Codename One and passed to the paint method as a callback. You should never invoke paint(Graphics) on your own.

If you want to invoke paint(Graphics) you can invoke cmp.repaint() which will call paint for you. Notice that you don't need to invoke it normally as paint is implicitly invoked when needed e.g. when layout changes etc.

Related