Re: Newbish Question...(s)
Is there a Login class and a class with a main method so your code could be compiled and executed?
Quote:
problem is the program won't stop and wait for the user to give a response via selecting a radio button.
Display the GUI with the radio buttons and exit. The RB need to have listeners.
When the user selects a RB the listener will be called.
Re: Newbish Question...(s)
1. yes of course :) I'm just trying to switch it over to a gui
2. will putting in a listener stop the rest of the program from running until it gets a response? or do I need to loop it in the background somehow until its got a working answer?
Re: Newbish Question...(s)
No, listeners do not stop the program.
You need to show the GUI to the user with listeners set for all the buttons etc and then exit the method that built the GUI. You do NOT put in a loop to wait for the answer. The JVM does that for you. When the user presses/selects/clicks on something, the JVM will call your listener and then your code reacts to what the user did.
Re: Newbish Question...(s)
hmm.. well wont this change the user response like i want? without listeners? because the JVM definitely isn't stopping the rest of my program while its displaying this GUI.
Code :
public void itemStateChanged(ItemEvent event)
{
textField.setFont(font);
if (font == loginFont)
{
Login.response1 = 1;
}
else if (font == registerFont)
{
Login.response1 = 2;
}
else if (font == exitFont)
{
Login.response1 = 3;
}
}
I guess I need to break up my program into more methods so that the rest of the program doesn't keep going until i specifically call its method via listeners or changes in the itemStateChanged
Cause like I said before, it was only stopping before to get input via scanner. then it would load the rest of the information immediately after as part of the process. Login.response1 is the integer I was adjusting with scanner before to know what the user chose.
Sorry if my logic seems illogical, this is my first real attempt at working with a GUI, aside from dialog boxes.
Re: Newbish Question...(s)
Oh and how would I specifically exit a method like the one that called the GUI Without coming to the actual end of the method }?
Cause as far as I can tell, if a method calls a method (say method1 calls method2), it just opens that method (method2) and stops(method1) until that method(method2) ends and then it goes back and finishes the rest of the method(method1). Right?
I'm trying to figure out how I could use DISPOSE_ON_CLOSE to end it somewhere in here?
Code :
if (font == loginFont)
{
Login.response1 = 1;
}
else if (font == registerFont)
{
Login.response1 = 2;
}
else if (font == exitFont)
{
Login.response1 = 3;
}
But I don't know how to make it work?
__________________________________________________ ___________________
Edit:
Well I got it to mostly work so far..
But I still don't know how to make those stupid extra frames close when I'm done with them..
Here Is What It Looks Like
Also if you try it out, you will notice that the program loads in the top left corner.. I'm sure there is a way to get it to load in the middle but I can't find code for it?
And another thing. since I'm going to be working on it soon... Is there a way to make a method reload/redisplay from switching tabs? I want
to display different information on different tabs, but can they be re-loaded somehow just from switching the tabs?
Re: Newbish Question...(s)
Is there a Login class and a class with a main method so your code could be compiled and executed?
Re: Newbish Question...(s)
Quote:
Originally Posted by
Norm
Is there a Login class and a class with a main method so your code could be compiled and executed?
Yup. Look at the link I posted above its a jar file with working so far.
Re: Newbish Question...(s)
There are no .java source files in the GameGUI.jar file.
I'm not going to run anyones jar file without the source.
When I tried to execute your jar file in a Secure environment I get this:
Quote:
Exception in thread "main" java.security.AccessControlException: access denied (java.security.AllPermission <all permissions> <all actions>)
at java.security.AccessControlContext.checkPermission (Unknown Source)
Why does your code try to get ALL Permissions?
Reduce the required permissions required to exactly what is needed.
Re: Newbish Question...(s)
Sorry here is the source
Source
I have no idea if I'm setting this up 'properly' and I can't figure out why after you login it wont load the next window. It's just white on my computer. =/
As far as permissions go I have no clue how to even manage that stuff. I just told eclipse to make me a jar.
Re: Newbish Question...(s)
Quote:
after you login it wont load the next window
What is the next piece of code that is executed after you login? Trace the logic flow from that point. Add printlns if you don't have an interactive debugger.
Re: Newbish Question...(s)
It heads over to CheckInfo, there it sees that it needs more info so it loads up NewCheckInfo class. But that class just freezes. I added println statements like you said and it will go until the end of public NewCheckInfo(int aP) method. But when it doesn't ever seem to get to public void actionPerformed(ActionEvent event). And thats because the user never enters information. Which is because the screen is just white and you cant! =/ so I have no clue why its doing that all of the sudden. Is there a problem with having to many methods inside methods with frames and what not? I don't really see how I could do it a different way..
Re: Newbish Question...(s)
Quote:
But that class just freezes
What code called the NewCheckInfo constructor ( = new ...)
What happens after the constructor returns?
Re: Newbish Question...(s)
NewCheckInfo is called near the beginning of CheckInfo... Oh i forgot i changed it just to test something. I told it to call the login stuff again in CheckInfo lines 29-32. Before I did that it use to be:
So you could just replace 29-32 with this code, to see what I'm trying to do.
And its not returning anything specifically? I was just going to have it call another method once it got done. and move onto the next frame and what not.
Code java:
NewCheckInfo newCheckInfoFrame = new NewCheckInfo(aP);
newCheckInfoFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
newCheckInfoFrame.setSize(400, 100); // set frame size
newCheckInfoFrame.setVisible(true); // display frame
Re: Newbish Question...(s)
You've posted way too much code to look thru. I prefer working with a single source with ALL the code in one file.
And now I see that what is posted won't work.
The only thing I can suggest is to continue working thru the execution path until you find the problem.
If you find a problem and can create a small program that executes and demonstrates the problem post it with your questions.
Re: Newbish Question...(s)
I could probably help if the OP could post the relevant source code (the 'Source' link previously posted shows no code), and explain clearly what the problem is.
Re: Newbish Question...(s)
Source
Alrighty first off here is this for fun: http://i51.tinypic.com/nb25xv.jpg
Anyway here is how the program flows:
The user will first be given an option of what to do: Login.java -> LoginP1()
LoginP1() will load the Gui from here - > NewLogin.java
Once NewLogin receives a response via TextFieldHandler implements ActionListener in NewLogin.java
NewLogin.java will load a method based on the user selection. i.e. Register will load Login.LoginP3();
This is how pretty much I'm doing all the GUI and flow of the program, because I don't know a better way to do it :P .
My problem however is this: Once the user logs in for the first time after successfully creating an account, it will need even more information from them so just like I did before I tried to load another Frame/GUI to collect the input. But this time it just freezes. even though I did the exact same things I've been doing before. This is where this occurs:
See: CheckInfo.java -> Running(int aP) lines 29-32
Then see: NewCheckInfo.java I put in print statements that do print all the way up until the end of the NewCheckInfo(int aP) method. But after that the program just freezes and displays a white GUI box.. No clue why? and I don't really know what my alternatives may be to setting up my GUI.
Re: Newbish Question...(s)
Also, I'd really like to know how to make the other frames disappear once I've collected the Users response. Any ideas how to set it up like this?
Re: Newbish Question...(s)
Have you tried using a modal dialog window to get data vs a Frame?
The program freezing may be some conflict with the way you executing code on the Swing event display thread (EDT).
Re: Newbish Question...(s)
Yes, a modal dialog windows would works just fine. But they are so ugly and unattractive with so minimal customization that it kind of defeats the point of making a GUI in the first place. :( Plus I wanted to be able to control the users response via GUI so that when I'm asking for menu options, they don't have to put in things like 1 or 2 or 3 as a selection, and then have to try catch everything just to make sure they don't put in a character etc.
Re: Newbish Question...(s)
Did you use the JDialog class for that? You should be able to have EXACTLY what you want.
I made these changes to NewLogin:
Code :
public class NewLoginDialog extends JDialog
public NewLoginDialog(Frame owner, String title, boolean modal)
{
super(owner, title, modal);
...
NewLoginDialog nld = new NewLoginDialog(null, "New Login", true); // for testing
Re: Newbish Question...(s)
Well I haven't heard of or seen JDialog before. But I tried the cod you provided in the program, and it works, except that the dialogbox wont let me work with the other jframes I already made.. It wont release control of the program anyway until its resolved. I'm guess if I changed all of them to dialogboxes like that one, they would take precedence over the first one.
But, what really is the difference between using these kinds of dialog boxes and the JFrames I was already using? Maybe it wont glitch like the other one did?
Re: Newbish Question...(s)
Quote:
dialogbox wont let me work with the other jframes
That's what modal mode means.
Why would your design require having multiple windows open/displayed with any of them being alive for input? Seems like a strange design.
Re: Newbish Question...(s)
Yea true. I will try the dialog boxes, and see if it doesn't freeze anymore.
Re: Newbish Question...(s)
Wow it works! =D and it runs a lot smoother!
Thanks so much for showing me that :)