Stuck trying to advance to the next loop in GUI class - java

I'm a long time observer, and first time poster. So forgive me if I seem to skip over some typical guidelines.
Posted below is a link to my GUI class, where I display different "screens"/JPanels in my client program. The client keeps track of these screens by referencing a state variable, which is documented at the top of the class.
Upon launching the client, the GUI builds the JFrame, then starts attaching things to it. First up is a splash screen, then after a short time it moves on to displaying a menu. This part should be clear in the code. The problem I'm experiencing occurs when a menu item component is clicked on. The GUI properly removes the menu from the window, however it doesn't move on to displaying the login screen. Both the menu and, login screens are attached in a similar fashion. Despite my best efforts to debug the code by printing messages at each step, I can't seem to figure out why after changing the state to "3", the GUI doesn't advance into the "Login" phase of the loop and, display the login screen.
http://pastebin.com/xWDpjD14
Also, I should note, the state is being changed by a Mouse Listener class attached to each menu item of the menu screen. I've already debug'd this part. I just can't figure out why the loops aren't working as expected.
Sorry I don't have a SCCE(sp?) to attach, It's my first post, and I'm not quite familiar with the sites posting options yet.

Related

Loading and parsing file and displaying said file as graph with Java GraphStream

The loading and parsing of the file proceeds without an obvious problem but the ViewPanel in which I try to display the graph does not show immediately when initiating the action that should lead to this. Instead the container in which the ViewPanel (=an object that inherits from JPanel) with the graph should show remains empty. This changes when I then click twice on the application window, for instance by first clicking the minimization icon and then enlarging the window again with a click on the corresponding icon. After these two clicks the desired graphs shows up on the screen which implies that the ViewPanel too is then doing what it should be doing. Those two clicks, however, are a nuisance, as far as I can see they have nothing to do with the code I wrote and they should not be necessary. How can I get rid of the necessity for them and have the graph displayed seamlessly after prompting the action that should lead to the graph being displayed?
I am grateful for any kind of helpful advice.

How to stop program until a button is pressed in JAVA?

How do I make it so that the program doesn't keep reading in code until the button is clicked?
Why?: I have a 10x10 grid with buttons in each part and then code running depending on what is clicked. However, my program keeps reading in code so there is never a choice being made and it gives me error. I tried giving it a infinite loop until a button is pressed, but that doesn't work out so well
-edit
I'm a complete beginner with Java.
This is a picture of the GUI
http://imageshack.us/content_round.php?page=done&l=img843/5351/sascp.png
What I want is for the code to not keep running step by step until I click a button.
E.G.:
create gameGUI
wait until and check which button is pressed
if(buttonClicked[i][k] == something){
System.out.println("lool");
}
But what's happening in my code is that it creates the gameGUI and then because the user isn't fast enough to click it just skips over the if statement or gets a run-time error because nothing was pressed.
In both Android & Swing (& I'd expect J2ME), buttons fire events when told to do so (by activating them). You would generally just wait for that to happen before doing anything, and not bother with what the rest of the GUI is doing (or not doing) at the time.
Or in other words:
Add an ActionListener to the buttons.
In the actionPerformed() method, insert the code that you have above.
Also
The code snippet provides almost no useful information. For better help sooner, post an SSCCE.
That GUI looks like Swing to me. If it is not, then what is it?
Please always copy/paste run-time errors.

How to implement an activity into another?

I don't know if it's a dumb question because it is one of my first apps.. but if that's the case, please also explain why!
If I create a Tab-Based Activity-Structure, I get nearly what I am asking for but only for Tabs. What I want is generally opening a second or even third activity in one main-activity which contains the main-interface.
Example: I have a Title-Bar and a little icon at the bottom-left corner for some reason during the whole app runtime. Now: How can I control them with the main activity and open at the same time some other activities/views into the existing interface? It should then be shown below the title bar and lying underneath the little icon (the icon is not really important, just fictional). Also it would be nice if I could add some fade in effects to these embedded activities/views. Is that somehow possible?
I currently only know, how to open activities each over another filling the whole screen, except in the case of tabs... maybe I only haven't inspected the tab structure enough.. however, I would be delighted about each answer!
Regards
What you are looking for, are Fragments.
Fragments can be used to fill a part of the screen, while doing something else entirely in a different one.
In your example you can create a main activity that contains two Fragments. One Fragment controls the title bar, the other one controls the main content area.
By replacing the current Fragment in your content area with a different one on the press of a button, you can achieve the behavior you are looking for. At least, that's how I did it in an app of mine containing a main content area and a music player. The music player stays in place while the main content changes.
Sadly I can't provide any example code right now, but here is a tutorialthat should help you get started:
Android User Interface Design: Working With Fragments

Android, where to put my UI updates and my game loop

So I'm new to Android, and have been having some difficulties with understanding threading/Android UI updating and such. I have some code for a simple game engine I made for an AP computer science final project and I have been trying to make it into an Android app. Coming from the java world I'm not used to threading or worrying about how much time or where a calculation is taking place so I've been having some difficulties getting my game playable. After a splash screen and a main menu, I have it set up so an activity named "Play" starts. In this activity I have found that I can initialize my game engine object(which gets passed from class to class), create an object I created to make an AsyncTask("GuiThreader" in the code linked below) but as soon as I throw in some code in "Play" to do anything more than that (like initialize a button, or start the threader helper class) I get an "Activity has Stopped Unexpectedly" error meaning I'm doing something wrong. I've been looking at a lot of the Android example code but its making little sense to me. So I guess with all that background my bigger question is how can I get this code working? More specifically where should I have my loop that checks when the game is over, and how can I update my button colors outside of the "main" threader to keep it from crashing.
Here is my code:
"Play" Activity (with lines of code commented that I was testing with):
http://pastebin.com/K5kFsMvG
"GuiThreader" used to make the game calculations an AsyncTask: http://pastebin.com/306eUYfq
"GUIdriver" used to call a class that updates the button colors: http://pastebin.com/RANZBH38
"ButtonColorUpdate" saves a value for buttons and updates their colors: http://pastebin.com/qN2fw1RC
If you need anything else just comment and I'll put it up. Thanks in advance for any help!
Start by reading this. Then I'd recommend looking at the code from Replica Island. There's a ton you can learn from studying the code of this project. If you want to interact with GUI "stuff" from a separate thread, a Handler (see the API) can be useful for sending messages between the two.

What in Android would allow me to touch the edge of my screen while playing my game and slide over an Item screen?

Android has many useful tools when coming to views and screens and layouts.
Description: While playing my game (running around as a zombie bear eating humans) I would like to allow the player to access an items menu via sliding a menu from the right side/edge of the screen. Or at the least be able to access a game options menu (not game settings which would be the menu button).
What would be the best fit for description?
P.S How would I make a question like this less like a discussion and more like a straight forward programming question when I don't really know what's available to do this.
Also, if this is the case, please point me to another location to ask a question that may require a discussion.
Thank You!
Try looking at the SlidingDrawer class.
PS I personally don't see a problem with how you have worded your question if you are looking for ideas of views/widgets you need to perform a specific function/effect.
My first thought, and for a simple approach (this wouldn't be animated or dragged really), would be using a RelativeLayout where the portion representing the menu was initially set so that it's visibility were GONE, except for a small tab or arrow or something. When that tab/arrow is touched, the visibility of the View for the menu could be toggled to VISIBLE.
With visibility set to GONE, a view is not drawn or considered in any part of the layout pass when the screen is drawn.
You could populate a listview with some icons and when an particular icon is selected, then figure out which one was selected and then execute some function and hide the sidebar using an animation. I've never developed a game, so I'm not too sure how far it deviates from the standard, but I wish you the best of luck :) ! If you post the source let me know would love to test your game and see how you work with the source!

Categories

Resources