This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes How to Open Another Window by clicking button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to Open Another Window by clicking button" Watch "How to Open Another Window by clicking button" New topic
Author

How to Open Another Window by clicking button

Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Hello Everyone!

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

waiting!!!
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2158
    
  47
What do you mean by another window, do you mean a JFrame, JDialog or something else?
Shamsa Aziz
Greenhorn

Joined: Dec 06, 2012
Posts: 11
Tony Docherty wrote:What do you mean by another window, do you mean a JFrame, JDialog or something else?



a JFram
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2158
    
  47
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

Joined: Dec 06, 2012
Posts: 11
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

Joined: Aug 07, 2007
Posts: 2158
    
  47
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

Joined: Dec 06, 2012
Posts: 11
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

Joined: Aug 07, 2007
Posts: 2158
    
  47
You could try the Java tutorials http://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html
 
 
subject: How to Open Another Window by clicking button
 
Similar Threads
Using dropdown box in JavaScript
How to control no. of Child Windows
java script for open jsp file
not to allow closing current window..
new tab servlet