1. anon(96573)'s Avatar
    Let me start by saying I'm new to java and blackberry programming. I have

    main.java which uses pushScreen(new StartGame()); to pull up the StartGame.java page.

    From the StartGame.java page I want to call Menu.java how would I do that?

    I can't do pushScreen(new Menu()); can I?

    I'm just wondering how you call different methods while inside a method?

    I hope that's not too confusing.
    02-01-09 07:28 PM
  2. delta_foxtrot2's Avatar
    Try the code below, works for me(tm)

    Code:
    class myScreen extends MainScreen
    {
    /* ....... */
        MenuItem quitMenu = new MenuItem("Quit", 50, 50)
        {
             public void run()
             {
                   System.exit(0);
             }
        };
        protected void makeMenu(Menu menu, int instance)
        {
            menu.add(quitMenu);
        }
    }
    02-01-09 09:00 PM
  3. anon(96573)'s Avatar
    Thanks for the help Delta, but that code looks like it creates a menu, like when you press the menu key right? I'm looking to create a menu for the game. Like when you load the game there will be a few different buttons to choose from like Start Game, High Scores etc. I want to display that on the screen rather then in the menu.

    Here is how I have it setup

    Game.java > StartGame.java

    The startgame.java displays a splash screen and when the user clicks the screen I want it to load Menu.java.

    This is the code I have in StartGame.java it listens for a screen click and then I want it to load the method in Menu.java

    Code:
        public boolean touchEvent(TouchEvent te){
            //Set Click Code
                if(!this.isFocus()) return true;
                    switch(te.getEvent()){
                        case TouchEvent.UNCLICK:
                            //Menu.java code here I'm not sure what though 
                            break;
                    }
                    return false;
        }
    Again I hope that isn't confusing lol
    02-01-09 09:26 PM
  4. delta_foxtrot2's Avatar
    I don't know the specifics of what to do, but I would try doing something like this:
    * set the screen to implement FieldChangeListener
    * in the screen creation you would do super(ButtonField.CONSUME_CLICK) or something to that effect.

    Then you just need a function in the class to grab the click and turn it into something useful, alternatively you could just have a timer display the splash and then flick to the menu after 5 seconds or so.
    02-01-09 09:44 PM
  5. anon(96573)'s Avatar
    I don't know the specifics of what to do, but I would try doing something like this:
    * set the screen to implement FieldChangeListener
    * in the screen creation you would do super(ButtonField.CONSUME_CLICK) or something to that effect.

    Then you just need a function in the class to grab the click and turn it into something useful, alternatively you could just have a timer display the splash and then flick to the menu after 5 seconds or so.
    I'm bad at explaing thing so bare with me lol. I have already created the code to show the splash screen and when you click it I have all that. But when you click it nothing happens. That's where I'm stuck. I would like to call a method from Menu.java when the screen gets clicked.
    02-01-09 10:02 PM
  6. delta_foxtrot2's Avatar
    You answered yourself in the first post, push the new screen and/or pop the current one.
    02-01-09 10:58 PM
  7. anon(96573)'s Avatar
    You answered yourself in the first post, push the new screen and/or pop the current one.
    Hmm I guess I don't know how to use it too well even after reading the docs on it. Here are my files can you provide a little feedback?

    Main.java
    Code:
    class StormBowl extends UiApplication{
        
        public static void main(String[] args){
            StormBowl theApp = new StormBowl();
            theApp.enterEventDispatcher();
        }
        private StormBowl(){
            Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_NORTH);
            pushScreen(new StartGame());
        }    
    }
    Start Game
    Code:
    class StartGame extends MainScreen {
        //Vars
            private VerticalFieldManager _manager;
    
        StartGame() {
            //Set Background
                _manager = (VerticalFieldManager)getMainManager();
                Background bg = BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("img/bg.png"));
                _manager.setBackground(bg);
        }
            
        public boolean touchEvent(TouchEvent te){
            //Set Click Code
                if(!this.isFocus()) return true;
                    switch(te.getEvent()){
                        case TouchEvent.UNCLICK:
                            pushScreen(new Menu()); <--This is what I'm trying to do but it isn't working. I'm trying to push a new method called Menu()
                            break;
                    }
                    return false;
        }
    }
    Do I have to do a popScreen(Main) before pushScreen(new Menu())?

    Thanks for all your help so far. The tutorials and help seems to be limited.
    02-02-09 12:30 AM
  8. anon(96573)'s Avatar
    Hmm

    Code:
    net.rim.device.api.ui.UiApplication.getUiApplication().pushScreen(new Menu());
    Works but

    Code:
    pushScreen(new Menu());
    doesn't

    I've included

    import net.rim.device.api.ui.UiApplication;

    but still it doesn't work. I guess it's no biggie but still confusing lol
    02-02-09 12:50 AM
  9. delta_foxtrot2's Avatar
    import net.rim.device.api.ui.UiApplication;

    but still it doesn't work. I guess it's no biggie but still confusing lol
    Not really confusing, if you look at the code it makes perfect sense... Specifically this:

    Code:
    getUiApplication().pushScreen(new Menu());
    02-02-09 03:28 AM
  10. anon(96573)'s Avatar
    Not really confusing, if you look at the code it makes perfect sense... Specifically this:

    Code:
    getUiApplication().pushScreen(new Menu());
    The part I'm confused about is in my Main function I just used this

    Code:
    pushScreen(new StartGame());
    But on the other page I had to add this in front of it.

    [code]net.rim.device.api.ui.UiApplication.getUiApplicati on()[/url]

    I just don't get why I had to add all the stuff on the front of it. I can't find an explanation online though so I will just assume it's magic lol. As long as it works that's all I'm worried about.
    02-02-09 11:43 AM
  11. CMY's Avatar
    I cant really see everything you have in your code, but you had to import the Uiapplication class in the main file. If you did not do this in the second file that is why you had to type all of that. Do an import and then you should be able to just type UiApplication.whatever. Also pushScreen is a UiApplication function which can be called by itself because your main file extends the UiApplication class.
    02-07-09 04:22 AM
  12. cray1000's Avatar
    Did you figure this out dmg?

    i am having the same question.

    the class with the first screen already extends MainScreen, so we cant also have it exten uiapplication

    so i need to use this:

    net.rim.device.api.ui.UiApplication.getUiApplicati on().pushScreen

    to load a 2nd screen off the main screen....

    what did you figure out?
    02-16-09 07:57 PM
  13. ydaraishy's Avatar
    You are *extending* UiApplication!

    Create a UiApplication ui = UiApplication.getUiApplication(); line above, and then push the screen with ui.pushScreen().
    02-19-09 03:25 PM
  14. mike240se's Avatar
    good info.

    i tried adding a menu to my app.

    it used push screen to switch to it and then when they choose their options and hit a button, it closed it with pop screen. this worked fine.

    but then when they try to go back into the menu it errors out. once you push a screen and then pop it, do you use something other than pushscreen to bring it back maybe?
    02-22-09 05:16 PM
  15. ydaraishy's Avatar
    You should treat it like a stack, as the name suggests. Push the menu screen. On a button click, push the new screen. When that screen is closed, pop the new screen, you should be at the menu screen.
    02-22-09 05:51 PM
  16. mike240se's Avatar
    You should treat it like a stack, as the name suggests. Push the menu screen. On a button click, push the new screen. When that screen is closed, pop the new screen, you should be at the menu screen.
    ah ok that clears that up. thanks. is there really no where to read about this stuff? the 4.7 api reference has some info for each thing, but not much for alotl.
    02-22-09 11:05 PM
LINK TO POST COPIED TO CLIPBOARD