×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Red face "PLEASE HELP ME" J2ME Canvas repaint methods

    Can anybody PLEASE help me with using Canvas repaint properly.
    I have an app that i have four menu's in.
    The menu's are made of forms, though i really want to use canvas graphics.
    I have a canvas subclass in my code already for the main menu, i just need to be able to impliment the use of repainting the canvas to draw new text and image for a new menu!!

    This is my canvas subclass (which is the main menu, (first screen)), and my second menu, (using a form).
    How can i change this form to be a new set of graphics on my canvas??
    PLEASE HELP ME!!
    (lables have been replaced with blabla, my apologies)

    /////////////////////////////////////////////////////////////

    }


    public void MainPage(){
    hi = new Ticker("......HomePage.....blabla......");
    form = new Form("HOME");
    exitFlag = false;
    userName = new TextField("LoginID:", "", 30, TextField.ANY);
    password = new TextField("Password:", "", 30, TextField.PASSWORD);
    txtField = new TextField("Imput Data ", "", 1500, TextField.ANY);
    exit = new Command("Exit", Command.EXIT, 1);
    blabla = new Command("blabla", Command.OK, 2);
    main = new Command("blabla", Command.OK, 2);
    blabla = new Command("blabla", Command.OK, 2);
    blabla = new Command("blabla", Command.OK, 2);
    blabla = new Command("blabla", Command.OK, 2);
    form.append(new ImageItem(null, image, ImageItem.LAYOUT_NEWLINE_BEFORE | ImageItem.LAYOUT_CENTER | ImageItem.LAYOUT_NEWLINE_AFTER, null));
    form.setTicker(hi);
    form.append(userName);
    form.append(password);
    form.append(txtField);
    form.addCommand(blabla);
    form.addCommand(blabla);
    form.addCommand(blabla);
    form.addCommand(blabla);
    form.addCommand(blabla);
    form.addCommand(blabla);
    form.setCommandListener(this);
    display = Display.getDisplay(this);
    display.setCurrent(form);
    }

    }

    class CanvasString extends Canvas {
    boolean string = true;
    void toggleString() {
    MainPage();
    }

    public void paint(Graphics g) {
    int width = getWidth();
    int height = getHeight();

    g.setColor(0x000000);
    g.fillRect(0, 0, width, height);



    g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
    Font.STYLE_ITALIC, Font.SIZE_MEDIUM));
    g.setColor(225, 255, 0);
    g.drawString("blabla", 0, 0, Graphics.TOP |
    Graphics.LEFT);

    g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
    Font.STYLE_ITALIC, Font.SIZE_MEDIUM));
    g.setColor(255, 0, 128);
    g.drawString("blabla", 0, 15, Graphics.TOP |
    Graphics.LEFT);

    g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,
    Font.STYLE_ITALIC, Font.SIZE_SMALL));
    g.setColor(51, 0, 255);
    g.drawString("blabla", width, height, Graphics.BOTTOM | Graphics.RIGHT);

    if(image != null){
    g.drawImage(image, getWidth() / 2, getHeight() / 2, Graphics.HCENTER
    | Graphics.VCENTER);
    } else {
    g.setColor(0x000000);
    g.drawString("No image available", getWidth() / 2, getHeight() / 2,

    Graphics.HCENTER | Graphics.BASELINE);
    }

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

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    Please have a look at the FM Wiki page:
    http://wiki.forum.nokia.com/index.ph..._graphical_API

    thanks,
    ~Amitabh

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Unhappy Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    i am a beginner at this, but doing ok... I have had no help, and am having difficulty refferencing documentation properly. It is hard for me to learn that way!!
    I would apreciate it if you/someone could help me more than re-directing me to some random doc, tutorial, example, etc.
    PLEASE, and thanks.

  4. #4
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    well tutorials and documentation are actually the best ways to get a good feel of the basics...
    we could just give you code and say do it like that... but... you wont be learning a lot about the language, the API's, the underlying structure and most importantly why the code looks the way we gave it to you... so you won't have an idea why some methods are used, what they actually do and how they should be used correctly...

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Angry Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    WELL THEN YOU OBVIOUSLY DO NOT KNOW ME...
    I AM OFFENDED BY THAT STATEMENT, AND I HAVE A FAIRLY GOOD KNOWLEAGE OF BASIC MIDLET SCRIPTING.
    TOO IT IS EXTREEMLY HARD FOR ME TO LEARN FROM DOCUMENTATION FOR A COUPLE OF REASONS, ESPECIALLY WITHOUT PERSONAL ASSISTANCE, I HAVE NO OTHER WAY BUT LOOK AT EXAMPLES AND RECONSTRUCT THEM, DOING SO HAS GIVIN ME EXCELLENT INSIGHT IN J2ME.

    "SORRY I GET STUCK!!"

    NOT THAT I HAD TO EXPLAIN MYSELF TO YOU OR ANYONE.

  6. #6
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    You are defintiely right I don't know you, and if you were offended I am sorry that wasn't the intention...
    Even though I used the word "you" it wasn't specifically directed to your person but in general... If you read my post again taking account of this you might see my post makes a lot more sense.. I am talking generally about what in my opinion is the best way to learn something, I am never implying anything about you personally...
    It's an explanation why people aren't too inclined just to give code away, and mostly a response on your own statement: "I would apreciate it if you/someone could help me more than re-directing me to some random doc, tutorial, example, etc."

    Personally people are trying to help you be redirecting you to information (in the form of documentation, tutorials, examples), and no it's not just RANDOM information... So just to get back to the point : to me it seems you are implying people here aren't trying to help you and are on purpose redirecting you to information which isn't of any help at all...
    I'd say, and this is my opinion, that this is a lot more unrespectfull towards those that actually tried to help you by supplying you with any sort of information.. and believe it or not, documentation is actually information also for developers, and it's not just there to mislead people...

  7. #7
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Exclamation Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    sorry, seriously, i did take it the wrong way, but you still do not understand.
    I am not asking for anyone to give me a code, simply help run me through it!!
    I have tried so hard but cannot follow majority of doc,s. I am not that kind of learner, i need to understand it in a different way. Please try and understand, and too it is really really hard doing all of this especially locking new knowleage in my head due to my extremely hectic lifestyle.
    I am no cheat, i am a person that holds great pride in what i do, just check out my all natural (uncommon cichlid display, all my own knowleage with trial n error put in, environment is best any pet store around has ever seen!!)"http://www.youtube.com/watch?v=2oiKdD_k6Lg
    http://www.youtube.com/watch?v=QdKzatzkxpg
    http://www.youtube.com/watch?v=Hv0ggABgYV0"
    Seriously, i hold alot of pride, where is it if you simply just tell me?..
    I took a great deal of pride in the simple app i have wrote even!! I do not ask for a code, but still not to be directed to something i cannot understand, (not meaning i cannot understand j2me, just the way it is represented)
    I really need more direct help.
    The past two days i have been in email conversation with a nice lady from india that understands my situation and is trying to help me in her free time, however it may take a while for she is a busy lady!!
    Well thanks anyway and sorry for being offended earlier.

  8. #8
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Red face Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    "I'd say, and this is my opinion, that this is a lot more unrespectfull towards those that actually tried to help you by supplying you with any sort of information.. and believe it or not, documentation is actually information also for developers, and it's not just there to mislead people..."


    You are right and i apologise. I am just very frustrated that out of all people on the net, in the forums i have requested help... only one person understood what i was asking for and why.

  9. #9
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    well I don't know where your knowledge begins and/or ends... anyways I will try to comment your code a little :
    - all those blabla = new Command("blabla", Command.OK, 2);
    and
    form.addCommand(blabla)
    are unnecessary, especially the creation of "new" Commands which arent new because you are just rewriting the same object (blabla) the whole time...

    - to actually show the Canvas you will have to create an object of it first :
    CanvasString myCanvas = new CanvasString()
    - then you will have to show it onscreen, for that you will have to use the Display object... You will need a reference to it first so somewhere in the constructor of your midlet you will need :
    myDisplay = Display.Display.getDisplay(this);

    so to continue where we were, showing your canvas, you will have to use the Display reference :
    myDisplay.setCurrent(myCanvas);

    If everything went right you will be shown your canvas at this point...

    - You are defining a method MainPage() within your own Canvas... A Canvas is NOT your main class.. your main and central class should be a class extending MIDlet... in this midlet you can get the Display object mentioned before... also it will instantiate the Canvas class and show it thriugh the Display reference...

    To be short, and to set up the BASIC architecture of your program :
    - create two classes : a MIDlet and your Canvas class
    - through the MIDlet class you can show the Canvas object...

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    Please find the code below, that can print MainMenu on Canvas if you use it along the classes (codelets) that I gave in the wiki article on the this link: http://wiki.forum.nokia.com/index.ph...d_applications


    Code:
    import javax.microedition.lcdui.*;
    
    /**
     * MenuCanvas.java  This class is for displaying the Main Menu
     */
    public class MainCanvas implements CanvasScreen   {
        int selRectPos=0;
        BaseCanvas bc;
    	CanvasScreen oldcs; //for back
        
        public MainScreen() {
    		this.bc=BaseCanvas.getCanvas();					               
    		oldcs=bc.setCurrentScreen(this);
        }
        
        /**
         * Renders the Canvas.
         *@param g the Graphics object to be used for rendering the Canvas
         */
        public void paint(Graphics g) {
            showMainMenu(g);
        }
        
        public void keyRepeated(int keyCode){ }
        
        public void repaint() {
            bc.repaint();
        }
        
        /**
         *Called when a key is pressed.
         *@param keyCode - the key code of the key that was pressed
         */
        public void keyPressed(int keyCode) {
              switch(keyCode) {
                    case Canvas.UP: if(selRectPos>0) selRectPos--;
                    break;
                    case Canvas.DOWN: if(selRectPos<2) selRectPos++;
                    break;                
                    case Canvas.RIGHT: // Exit
                        selRectPos=0;
                        bc.setCurrent(new ExitCanvas(this));
                        break;
                    case Canvas.LEFT: // Select
                    case Canvas.FIRE: // Fire
                        gotoModule();
                        break;
                }            
            repaint();
        }
        
        /**
         * It will go to the Particualr module depends upon swith case value
         */
        private void gotoModule() {
            switch(selRectPos) {
    			case 0: bc.setCurrent(new Module1Canvas(this)); // Module1
                break;
                case 1:bc.setCurrent(new Module2Canvas(this)); //Module2
                break;
                case 2:bc.setCurrent(new Module3Canvas(this)); //Module13
                break;            
            }
        }
    //Menu Options.
    	String[] options={"Module1","Module2","Module3"};
    
    	int bgcolor=(255<<16)+(255<<8)+255; /** Background color - white. */
        int fgcolor=(0<<16)+(0<<8)+0; /** Foreground color - black. */
        int hilightcolor=(84<<16)+(171<<8)+67; /** Menu Highhilightcolor color. */
        
    	 /**  Gets the  SMALL, BOLD Font used for displaying messages as bold*/
        Font bldFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_SMALL);
        /**  Gets the  SIZE_MEDIUM, BOLD Font used for displaying  headers */
        Font hedFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_MEDIUM);
    
         /**
         * Shows the Main Screen
         *@param g Graphics object
         */
        private void showMainMenu(Graphics g) {
            int WIDTH=Device.WIDTH;
            int HEIGHT=Device.HEIGHT;
            int gap=20
            
            g.setColor(bgcolor);
            g.fillRect(0,0,WIDTH,HEIGHT);
            g.setColor(fgcolor);
            g.setFont(hedFont);
            g.drawString("MainMenu",5+(WIDTH/2),5,g.TOP|g.HCENTER);
    
    		g.setFont(bldFont);             
            //Draw the Menu Options
    		for(int x=0;x<2;x++) {            
               g.drawString(options[x],60,65*gap,g.TOP|g.LEFT);  // Print the Menu          
            }
    
    		//Highlight the menu
            g.setColor(hilightcolor);
            g.fillRoundRect(2, 55+(selRectPos)*gap, WIDTH-2, gap-3, 3, 3);
            g.setColor(fgcolor);
            g.drawString(options[selRectPos],60,65+(selRectPos)*gap,g.TOP|g.LEFT);
            
    		//Draw Line
            g.drawLine(0,HEIGHT-35,WIDTH,HEIGHT-35);
            g.drawString("Select", 2 , HEIGHT-31  , g.LEFT|g.TOP);
            g.drawString("Fire", WIDTH/2 , HEIGHT-31  , g.HCENTER|g.TOP);
            g.drawString("Exit", WIDTH - 2 , HEIGHT-31  , g.RIGHT|g.TOP);
        }
    }
    The code Example also tell you about SplashCanvas.java

    From your midlet you need to call this MainMenu or SplashCanvas and from this MainCanvas the control will go the following depening on the user action:

    ExitCanvas
    Module1Canvas
    Module2Canvas
    Module3Canvas

    All these ModuleCanvas classes are to be made as the MainCanvas and they need to handle the user Inputs - keypress and control the flow of the app from within themselves.

    thanks,
    ~Amitabh
    Last edited by im2amit; 2009-08-28 at 20:05.

  11. #11
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    that example will help me better figure stuff out, thankyou "im2amit".
    "Tiger79" In my app, main menu is simply a label i chose to know where i am at. All the blabla are a replacement of the actual command lables because i did not want to share that info!! So the add new commands is necessary on each form, list, etc, and i already have a canvas for the first screen upon midlet launch, it is just how to reuse it for another menu instead of my "form menu", though with the example used by "im2amit" and my newly found "india friend", i should be able to aventually figure it out?..
    Thankyou.

  12. #12
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    tmf81.... it was your problem with Canvas (and few other people at FN) that made me contribute the following article on FN wiki, hope it will help all the new commers to work with Canvas in j2me.

    http://wiki.forum.nokia.com/index.ph...d_applications




    thanks,
    ~Amitabh
    Last edited by im2amit; 2009-08-30 at 14:16.

  13. #13
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    I have contributed one more article on FN-Wiki, it's about creating your own menu on Canvas.

    Have a look on it, it may help you.

    http://wiki.forum.nokia.com/index.ph...Menu_on_Canvas

    thanks,
    ~Amitabh

  14. #14
    Registered User
    Join Date
    May 2009
    Posts
    43

    Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    im2amit thanks!

  15. #15
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Smile Re: "PLEASE HELP ME" J2ME Canvas repaint methods

    thank you im2amit. you have been helpful.
    now i just have to free my time to refference!!!

Similar Threads

  1. Replies: 0
    Last Post: 2005-08-17, 11:03
  2. Order of called methods (Constructor,paint(), run()) when using canvas and runnable?
    By edmund66 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 3
    Last Post: 2004-09-22, 09:40
  3. Replies: 2
    Last Post: 2003-11-25, 12:19
  4. Major problem with delegation to Canvas
    By bartekn in forum Mobile Java Media (Graphics & Sounds)
    Replies: 8
    Last Post: 2003-10-08, 17:46
  5. Replies: 0
    Last Post: 2003-06-07, 06:44

Posting Permissions

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