-3

In my application I have 1 jar file which I imported in my project. Now I want to access one method of the class (jar file) which contains arguments Graphics(g). I want this method to be accessed in the startApp() of my application, but I can't directly call this method, because Graphics(g) is not supported. Please help me.

Code flow:

// 1.class

    public void drawscreen(Graphics g)
    {
    }

// 2.class

    public void startApp()
    {
    1.class.drawscreen()--->here graphics is not supported.
    }
gnat
  • 6,213
  • 108
  • 53
  • 73
subbu
  • 146
  • 2
  • 8

2 Answers2

1

In startApp you have to set some kind of Canvas to the Display:

Display.setCurrent(canvas).

Your drawing code in your drawscreen() method belongs into that canvas. There you can access the Graphics context by calling getGraphics().

Honesty you should learn some basics about Java ME if you didn't understand such a basic thing right now.

Kai
  • 38,985
  • 14
  • 88
  • 103
  • I am new to this j2me ..Thanks user714965..Can you please tell me what should i do in my startapp() to call that drawscreen(). – subbu Jun 18 '12 at 10:41
1

You could create a mutable image and pass its graphics to the drawScreen method:


    Image img = Image.createImage(100/*width*/, 100/*height*/);
    class1Instance.drawScreen(img.getGraphics());

Telmo Pimentel Mota
  • 4,033
  • 16
  • 22