• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to Open Another Window by clicking button

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone!

How to make another window open at on click action of the jbutton?

waiting!!!
 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What do you mean by another window, do you mean a JFrame, JDialog or something else?
 
Shamsa Aziz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tony Docherty wrote:What do you mean by another window, do you mean a JFrame, JDialog or something else?




a JFram
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure you want a JFrame, normally from within an application you would open a JDialog if you wanted another window. But either of these will involve the same process ie:

1. Add an ActionListener to the button.
2. In the ActionListener's actionPerformed method create your new JFrame/JDialog.
3. Add the required components to the frame/dialog object.
4. call pack() on the frame/dialog object.
5. call setVisible(true) on the frame/dialog object.
 
Shamsa Aziz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is this pack() method for?

Here is what I want to perform
On the first page of my application I have a login, create new account, change password buttons with two text boxes(user name and password). By clicking each of the button a new window(jfram) should open with a specific task. for example on Clicking the login button(with username and password filled) a new jfram should be opened.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
pack() causes the components to be laid out and the size of the window to be calculated and set so as to best display the components (within the confines of the screen).

You actually want a JDialog rather than a JFrame and you may want to make some/all of them modal. ie when the user clicks on Log In they probably shouldn't be able to click any other buttons until they have closed the login dialog, you can achieve this by making th JDialog modal.
 
Shamsa Aziz
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well thank you very much Tony but that is not clear to me. Can you please give me some examples, snippets or any link where I could read and make my concepts
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could try the Java tutorials http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic