×

Discussion Board

Results 1 to 12 of 12
  1. #1
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Ahemdabad
    Posts
    80

    Question draw graph in Lwuit Form

    Hello

    i need to draw graph on LWUIT Form, i know that if i override the paint method of form then i easily draw the line,point,string on form. i don't know how to implement this in j2me,
    i need some code help,
    Please help me anybody?

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: draw graph in Lwuit Form

    If you want to draw a graph on the Canvas (or overwriting paint of LWUIT form), just draw X & y axis of the graph using g.drawline();
    PHP Code:
            g.setColor(192,192,192); // Grey
            
    g.fillRect(Ox,Oy-Hy,Wx,Hy);
               
    g.setColor(fgR,fgG,fgB);
            
    g.drawLine(Ox,Oy,Wx+Ox,Oy); // x-axis
            
    g.drawLine(Ox,Oy-Hy,Ox,Oy); // y-axis 
    Now if you want to draw a line graph and you have data to be plotted in an array {dx,dy}, you can draw all the points on teh screen and join them by drawline() and paint the node values using drawString.

    thanks,
    ~Amitabh

  3. #3
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Ahemdabad
    Posts
    80

    Question Re: draw graph in Lwuit Form

    Quote Originally Posted by im2amit View Post
    If you want to draw a graph on the Canvas (or overwriting paint of LWUIT form), just draw X & y axis of the graph using g.drawline();
    PHP Code:
            g.setColor(192,192,192); // Grey
            
    g.fillRect(Ox,Oy-Hy,Wx,Hy);
               
    g.setColor(fgR,fgG,fgB);
            
    g.drawLine(Ox,Oy,Wx+Ox,Oy); // x-axis
            
    g.drawLine(Ox,Oy-Hy,Ox,Oy); // y-axis 
    Now if you want to draw a line graph and you have data to be plotted in an array {dx,dy}, you can draw all the points on teh screen and join them by drawline() and paint the node values using drawString.

    thanks,
    ~Amitabh



    Thanks for your reply

    but where i put this code in my class , means how can i call the paint method from startup method of midlet , did you provide me any sample code? or clear me how can i use this code in my class?
    ,i just know that if i override the paint method of form then i easily draw the line,point,string on form. i don't know how to implement this in j2me?
    but i have just try the below code
    how can i call the paint method from the constructor of the secondclass?
    in MainMidlet Class:-
    //in command selection listner method
    public void commandAction(Command arg0, Displayable arg1) {
    if (arg0 == cmdOK){
    new seconclass();//opening other form
    }
    }

    //secondclass
    import...
    import...

    public Class secondclass extend Form{
    public secondclass(){
    Form f1 =new Form("Graph");
    f1.Paint(what should i pass here)
    f1.show();
    }
    public Void Paint(Graphics G){
    g.setColor(192,192,192);
    g.fillRect(Ox,Oy-Hy,Wx,Hy);
    g.setColor(fgR,fgG,fgB);
    g.drawLine(Ox,Oy,Wx+Ox,Oy);
    g.drawLine(Ox,Oy-Hy,Ox,Oy);
    }
    }
    please help me ?
    Last edited by yatin.frankline; 2010-03-31 at 11:30.

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: draw graph in Lwuit Form

    means how can i call the paint method from startup method of midlet
    You dont need to call paint method of the form from the midlet, it will be automatically called when you set the form as current displayable.

    Just write the above codelet in the public void paint(Graphics g){ } method of the form which you will be making as current displayable where you want to display the Graph.

    thanks,
    ~Amitabh

  5. #5
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Ahemdabad
    Posts
    80

    Re: draw graph in Lwuit Form

    Quote Originally Posted by im2amit View Post
    You dont need to call paint method of the form from the midlet, it will be automatically called when you set the form as current displayable.

    Just write the above codelet in the public void paint(Graphics g){ } method of the form which you will be making as current displayable where you want to display the Graph.

    thanks,
    ~Amitabh
    Hello

    i have just try the following code , can you tell me what is wrong with the following and i have add the LWUIT jar file in that sample

    PHP Code:
        

    import com
    .sun.lwuit.Display;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.Graphics;
    import javax.microedition.midlet.*;

    /**
     * @author indianic
     */
    public class GraphMidlet123 extends MIDlet {
         private 
    Form mFirstForm;
         public 
    Display d1;
           public 
    void startApp() {

           
    Display.init(this);
         
    //d1=Display.getInstance();


             
    mFirstForm = new Form("First Form");

           
    //mFirstForm=Display.getInstance().getCurrent();
           
    mFirstForm.show();
          
        }

        public 
    void pauseApp() {
        }

        public 
    void destroyApp(boolean unconditional) {
        }
        public 
    void paint(Graphics g){

            
    g.fillRect(10,30,50,70);
              
    g.drawLine(5,9,60,90); // x-axis
           
        
    }

    please reply me

  6. #6
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,073

    Re: draw graph in Lwuit Form

    This paint method:

    PHP Code:
        public void paint(Graphics g){ 

            
    g.fillRect(10,30,50,70); 
              
    g.drawLine(5,9,60,90); // x-axis 
            
        

    should go in the mFirstForm.java not in the midlet class.

    thanks,
    ~Amitabh

  7. #7
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    208

    Smile Re: draw graph in Lwuit Form

    Create a class that extends Form class and then override the paint method of it. Put the given code and use this class at the place where you are using Form object. You have created a new method paint inside MIDlet class instead of overridding the paint method of Form class. That's it.

  8. #8
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Ahemdabad
    Posts
    80

    Question Re: draw graph in Lwuit Form

    Quote Originally Posted by gaurav007 View Post
    Create a class that extends Form class and then override the paint method of it. Put the given code and use this class at the place where you are using Form object. You have created a new method paint inside MIDlet class instead of overridding the paint method of Form class. That's it.
    Hello gaurav007

    Hello can you give me any sample code , i do not understand what you say,
    right now i have try following code with my self and it is working fine, but i want to also know of your way ,please give me any sample code of your way
    PHP Code:
       
    import com
    .sun.lwuit.Display;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.Graphics;
    import com.sun.lwuit.Painter;
    import com.sun.lwuit.geom.Rectangle;

    import javax.microedition.midlet.*;

    public class 
    GraphMidlet123 extends MIDlet implements Painter {
         private 
    Form mFirstForm;
         public 
    Display d2;
               public 
    void startApp() {
      
       
    Display.init(this);
            
    mFirstForm = new Form("First Form");
           
    mFirstForm.getStyle().setBgPainter(this);
             
    mFirstForm.show();
          
          
        }
        public 
    void pauseApp() {
        }

        public 
    void destroyApp(boolean unconditional) {
        }
           public 
    void paint(Graphics arg0Rectangle arg1) {
               
    arg0.setColor(70);
                
    arg0.drawString("Drawing text",16085);
              
    arg0.fillRect(10,30,50,70);
              
    arg0.drawLine(5,9,60,90);
           
    int h=   mFirstForm.getHeight();
           
    int g=mFirstForm.getWidth();
               
    arg0.drawLine(0,0,g,h);// x-axisy
        
    }
           

    Last edited by yatin.frankline; 2010-04-02 at 12:05.

  9. #9
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    208

    Re: draw graph in Lwuit Form

    Let me try to explain:

    Create one class CustomForm that extends Form. Write the code inside CustomForm's paint method to draw the graph.

    PHP Code:
    public class CustomForm extends Form {
    public 
    void paint(Graphics arg0) {
               
    arg0.setColor(70);
                
    arg0.drawString("Drawing text",16085);
              
    arg0.fillRect(10,30,50,70);
              
    arg0.drawLine(5,9,60,90);
           
    int h=   this.getHeight();
           
    int g=this.getWidth();
               
    arg0.drawLine(0,0,g,h);// x-axisy
        
    }


    Now your MIDlet should have code as given below:

    PHP Code:
    ...
    private 
    CustomForm mFirstForm;
    ...
    Display.init(this);
    mFirstForm = new CustomForm();
    mFirstForm.show(); 

  10. #10
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Ahemdabad
    Posts
    80

    Smile Re: draw graph in Lwuit Form

    Quote Originally Posted by gaurav007 View Post
    Let me try to explain:

    Create one class CustomForm that extends Form. Write the code inside CustomForm's paint method to draw the graph.

    PHP Code:
    public class CustomForm extends Form {
    public 
    void paint(Graphics arg0) {
               
    arg0.setColor(70);
                
    arg0.drawString("Drawing text",16085);
              
    arg0.fillRect(10,30,50,70);
              
    arg0.drawLine(5,9,60,90);
           
    int h=   this.getHeight();
           
    int g=this.getWidth();
               
    arg0.drawLine(0,0,g,h);// x-axisy
        
    }


    Now your MIDlet should have code as given below:

    PHP Code:
    ...
    private 
    CustomForm mFirstForm;
    ...
    Display.init(this);
    mFirstForm = new CustomForm();
    mFirstForm.show(); 
    Solution Of Problem:
    thank you very much gaurav007,
    i have try this code i get the expected result,Thank you for your way for drawing graph in LWUIT form.
    By the way, my way is also right.

    so if anyone have problem to drawing Graph in LWUIT Form
    they can use this code which is giving by gaurav007 to me
    PHP Code:
    //your first Midlet class code, please first add  LWUIT jar file in project then use this code
    import com.sun.lwuit.Display;
    import com.sun.lwuit.Form;
    import javax.microedition.midlet.*;

    public class 
    CheckMidlet extends MIDlet {
        public 
    Form f1;
        public 
    void startApp() {
            
    Display.init(this);
         
    f1=new CustomForm();
            
    f1.show();
        }

        public 
    void pauseApp() {
        }

        public 
    void destroyApp(boolean unconditional) {
        }

    and your second class code
    PHP Code:
    public class CustomForm extends Form {
    public 
    void paint(Graphics arg0) {
               
    arg0.setColor(70);
                
    arg0.drawString("Drawing text",16085);
              
    arg0.fillRect(10,30,50,70);
              
    arg0.drawLine(5,9,60,90);
           
    int h=   this.getHeight();
           
    int g=this.getWidth();
               
    arg0.drawLine(0,0,g,h);// x-axisy
        
    }


    and Second way of drawing graph in LWUIT form is Created by me

    PHP Code:
    import com.sun.lwuit.Display;
    import com.sun.lwuit.Form;
    import com.sun.lwuit.Graphics;
    import com.sun.lwuit.Painter;
    import com.sun.lwuit.geom.Rectangle;

    import javax.microedition.midlet.*;

    public class 
    GraphMidlet123 extends MIDlet implements Painter {
         private 
    Form mFirstForm;
         public 
    Display d2;
               public 
    void startApp() {
      
       
    Display.init(this);
            
    mFirstForm = new Form("First Form");
           
    mFirstForm.getStyle().setBgPainter(this);
             
    mFirstForm.show();
          
          
        }
        public 
    void pauseApp() {
        }

        public 
    void destroyApp(boolean unconditional) {
        }
           public 
    void paint(Graphics arg0Rectangle arg1) {
               
    arg0.setColor(70);
                
    arg0.drawString("Drawing text",16085);
              
    arg0.fillRect(10,30,50,70);
              
    arg0.drawLine(5,9,60,90);
           
    int h=   mFirstForm.getHeight();
           
    int g=mFirstForm.getWidth();
               
    arg0.drawLine(0,0,g,h);// x-axisy
        
    }      

    Last edited by yatin.frankline; 2010-04-05 at 13:26.

  11. #11
    Regular Contributor
    Join Date
    May 2007
    Location
    India
    Posts
    208

    Wink Re: draw graph in Lwuit Form

    Indeed your way is right. I simply told another way of doing it

  12. #12
    Regular Contributor
    Join Date
    Mar 2010
    Location
    Ahemdabad
    Posts
    80

    Smile Re: draw graph in Lwuit Form

    Quote Originally Posted by gaurav007 View Post
    Indeed your way is right. I simply told another way of doing it
    Thank you very much
    for your suggestion of drawing on LWUIT Form

Similar Threads

  1. need to put canvas in LWUIT Form
    By yatin.frankline in forum Mobile Java General
    Replies: 5
    Last Post: 2010-04-05, 13:23
  2. LWUIT 1.3 : bad form refresh
    By frasene in forum Mobile Java Tools & SDKs
    Replies: 7
    Last Post: 2010-02-06, 18:54
  3. LWUIT with GRAPH
    By yatin_indianic in forum Mobile Java General
    Replies: 1
    Last Post: 2010-02-01, 11:03
  4. Form troubles
    By matdodgson in forum Symbian User Interface
    Replies: 2
    Last Post: 2008-12-06, 10:49
  5. how to draw dynamic form in symbian c++
    By Kapil Kaushik in forum Symbian
    Replies: 0
    Last Post: 2006-03-20, 04:21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •