- 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 PMLike 0 - 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 PMLike 0 - 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; }
02-01-09 09:26 PMLike 0 - 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 PMLike 0 - 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 10:02 PMLike 0 - 02-01-09 10:58 PMLike 0
-
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()); } }
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; } }
Thanks for all your help so far. The tutorials and help seems to be limited.02-02-09 12:30 AMLike 0 - Hmm
Code:net.rim.device.api.ui.UiApplication.getUiApplication().pushScreen(new Menu());
Code:pushScreen(new Menu());
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 lol02-02-09 12:50 AMLike 0 -
-
Code:pushScreen(new StartGame());
[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 AMLike 0 - 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 AMLike 0
- 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 PMLike 0 - 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 PMLike 0 - 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 PMLike 0
- Forum
- BlackBerry Developers
- Developers Lounge
How can I do this?
LINK TO POST COPIED TO CLIPBOARD