• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about centering of the frame and using the new frame

 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
first I set choices then if any of that choices been selected a new frame will appear, but my problem is i want to use the button of that new frame but i cant click. i know it is because i use do while in there but i put it there because when i close the new frame the choices will then appear until the user enter exit.

how to rearrange the code or is there something else i will add to my code.



and also how to make the new frame into center, because it always appear at the top left of the screen.
 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to do something on button click, you have to add actionListener to the button. You can find information in the related Java tutorial.
For centering the frame, you have to get the size of the screen, and then based on that you can position your frame. You can easily find a solution for this by a little search.
 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes i know how to add an actionlistener to that button but i mean when i clik the frame, i cannot because theres a priority window which is my choices.

about the centering of the new frame i dont know how to search because i dont know the name of what i am going to search.
 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all I can't believe what you say. Just try a simple google search with the keywords: java center frame
Second:
Now I checked the code, more carefully. Please always post real code. The line

is not a valid line.
One solution for you problem would be to change the ending condition of the while loop. The current condition has no meaning, since when choice equals 0 you quit the application.
So you should write something like:

P.S.:
Please always use meaningful subject line.
Here you can find the FAQ of question posting. I highly recommend to read it carefully.
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To put the frames in the middles of the screen, try their setBounds or similar methods.
JOptionPane dialogues are modal dialogues by default. As soon as you have got rid of the dialogue, another appears, and that blocks the thread.
And please always tell us what the thread is about
 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i apologize for the code and for the topic, i will edit it. and i now make it center, what i did is i made frame.setLocation(450,300) i dont know when i run this on other PC if it will be the same location, because i think it differs to the screen of the monitor.

my other problem is the do while which affects the new frame, and i cant use it.

 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I answered both of your question Roldan, just read it;)
Your solution obviously won't work correctly on other computers, it won't even work on your computer whenever you change the screen resolution or you change the size of the frame.
 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im sorry for that, but it still didnt work, what i mean is

when i choose 1 or 2 or 3 except 0 a new frame will appear, and in the new frame i have something to work on, like buttons to click, etc, i have some codes to add, when i will close the frame, the choices will then appear, it is just like that.

the problem is i cant work on the new frame, like clicking a button, because the choices frame will bother the new frame.
 
Rob Spoor
Sheriff
Pie
Posts: 20514
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:To put the frames in the middles of the screen, try their setBounds or similar methods.

setLocationRelativeTo(null) is a better option. Let the API do the hard work
 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, i now centered it..

only the other problem is lacking..
 
Miklos Szeles
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now I understand your problem. Why don't you use modal JDialogs instead of JFrames? That would solve your problem.
 
Roldan Baldo
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, thanks a lot guys.. that solves the problem.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic