×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    159

    help me please,how to use canvas code in lwuit form

    I am working on S40 using sdk2.0 and lwuit1.5 .Now I want to add functionality to app of font size.so I used canvas class but I don't know that how to call canvas class in lwuit form and how to use it I want to append following code to lwuit
    Code:
     public void paint(Graphics g) {
    			
    	
                g.setColor(WHITE);  
                //g.fillRect(0, 0, width, height);
                
              
                Font f1 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_LARGE);  
                Font f2 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);  
                Font f3 = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);  
                int yPos = 0;
                if (COLOR)
                    g.setColor(BLUE);       
                else 
                    g.setColor(LIGHT_GRAY);
                
    				//g.fillRect(0, yPos, width, f1.getHeight());
    
                if (COLOR)
                    g.setColor(WHITE);       
                else
                    g.setColor(BLACK);
    			g.setFont(f1);
                g.drawString(string, 50, 100, Graphics.LEFT | Graphics.TOP);
                
                
    			yPos = yPos + f1.getHeight() + 10;
          
                 
                painting = false;
            }
            
    	}
    please tell me how to use this code in lwuit form.

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: help me please,how to use canvas code in lwuit form

    If you just want to use the paint methods code, just make a custom component in your app and use them in your LWUIT forms.

    To make a custom component extend your class from Component and override the paint method there !!
    Last edited by gaba88; 2013-07-22 at 10:25.

  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    159

    Re: help me please,how to use canvas code in lwuit form

    thanks ,send me source code regarding it

  4. #4
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: help me please,how to use canvas code in lwuit form

    Quote Originally Posted by vikranttanwar@ View Post
    thanks ,send me source code regarding it
    hi i think you should try before asking for code at least

    what i was saying:
    Code:
    class CustomComponent extends Component {
    
    public void paint(Graphics g) {
    
    // your paint code here !!
    }
    }
    and in your form:

    Code:
    form.addComponent(customComp)
    where customComp is an object of your CustomComponent class !!
    this should help you !!

  5. #5
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    683

    Re: help me please,how to use canvas code in lwuit form

    LWUIT and Canvas code do not mix together (unless your super expert and know the real deep dive of both lwuit and canvas)
    If you want to paint something on screen use the LWUIT paint method of the component and their font system (Font.createFont(...)).

  6. #6
    Registered User
    Join Date
    May 2013
    Posts
    159

    Re: help me please,how to use canvas code in lwuit form

    thanks ,I done same as you told me but when I call the object of canvas class in form it give an error. my code is
    Form form =new form();
    form addcomponent(customcanvas);
    it thorw an error "The method addComponent(Component) in the type Form is not applicable for the arguments (customcanvas)"
    customcanvas is object of class which extends Canvas which is following
    Code:
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Graphics;
    
    
    public class SelectDate extends Canvas{
    
    	protected void paint(Graphics g) {
    		// TODO Auto-generated method stub
    		
    		        int width = getWidth();
    		        int height = getHeight();
    		        g.drawString("Hello",10 ,30, 20);
    		        g.drawRect(40, 40, width-80, height-80);
    		        g.setColor(220, 0, 0);
    		        g.fillRect(40, 40, width-80, height-80);
    	}
    
    }
    I am using lwuit form

  7. #7
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    683

    Re: help me please,how to use canvas code in lwuit form

    I already told you that LWUIT and Canvas code do not mix together.

    change your SelectDate class to extend Component and not Canvas (and change your imports accordingly that Graphics is lwuit's Graphics object and not LCDUI's graphics object)
    and you would also need to change the paint signature to public.

  8. #8
    Registered User
    Join Date
    May 2013
    Posts
    159

    Re: help me please,how to use canvas code in lwuit form

    thanks shai,i did as you told me my Canvas code is
    Code:
    public class SelectDate extends Component{
    
    	public void paint(com.sun.lwuit.Graphics g) {
    		// TODO Auto-generated method stub
    			System.out.println("paint");
    			  int width = getWidth();
    		        int height = getHeight();
    		        g.drawString("Hello",10 ,30, 20);
    		        g.drawRect(40, 40, width-80, height-80);
    		       // g.setColor(220, 0, 0);
    		        g.fillRect(40, 40, width-80, height-80);
    	}
    and my midlet code is in which I am using lwuit form
    Code:
    protected void startApp() throws MIDletStateChangeException {
    		// TODO Auto-generated method stub
    		Display.init(this);
    		Form form=new Form();
    		form.addComponent(new SelectDate());
    		form.show();
    	}
    but after using it I didn't get any output as I required
    please tell me more and I also used Graphics of lwuit.

  9. #9
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: help me please,how to use canvas code in lwuit form

    i think you also need to override the calcPreferredSize which returns a dimension.

    I recommend you to go through this link for writing custom components in LWUIT http://docs.oracle.com/javame/dev-to...chapter15.html

Similar Threads

  1. LWUIT Form as Canvas, black screen when swiping
    By DanielZolnai in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2013-04-17, 13:48
  2. How to append LWUIT List screen to a LWUIT Form in j2me?
    By pavanragi in forum Mobile Java General
    Replies: 1
    Last Post: 2012-08-06, 07:01
  3. problem in back and forth of LWUIT form and normal form in j2me
    By jugal.inani in forum Mobile Java General
    Replies: 8
    Last Post: 2010-06-09, 12:24
  4. Repaint in Form(LWUIT) is diffirent from Repaint in Canvas
    By hoangpx in forum Mobile Java General
    Replies: 9
    Last Post: 2010-04-16, 05:06
  5. need to put canvas in LWUIT Form
    By yatin.frankline in forum Mobile Java General
    Replies: 5
    Last Post: 2010-04-05, 13:23

Posting Permissions

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