Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / May 2005

Tip: Looking for answers? Try searching our database.

How to get one GUI to wait for input on second GUI

Thread view: 
PM - 31 May 2005 08:22 GMT
I have one GUI that opens up a second GUI in a different class. How can I
get the first GUI to pause until the OK (or cancel) button is pressed on the
second GUI? I'm using Swing, JDK1.3.

Thanks

Pete
jonck@vanderkogel.net - 31 May 2005 10:07 GMT
> I have one GUI that opens up a second GUI in a different class. How can I
> get the first GUI to pause until the OK (or cancel) button is pressed on the
> second GUI? I'm using Swing, JDK1.3.

Check out the JOptionPane class.
PM - 31 May 2005 12:27 GMT
> > I have one GUI that opens up a second GUI in a different class. How can I
> > get the first GUI to pause until the OK (or cancel) button is pressed on the
> > second GUI? I'm using Swing, JDK1.3.
>
> Check out the JOptionPane class.

Hi,

JOptionPane looks good, does the showInternal frame allow me to put, say, OK
and Cancel buttons on an internal frame on my GUI, and still have the rest
of the GUI (mainly a JTable) as normal? How does this work if I need to
extend JOptionPane for my GUI class which previously extended JFrame?

Thanks

Pete
jonck@vanderkogel.net - 31 May 2005 13:34 GMT
> JOptionPane looks good, does the showInternal frame allow me to put, say, OK
> and Cancel buttons on an internal frame on my GUI, and still have the rest
> of the GUI (mainly a JTable) as normal? How does this work if I need to
> extend JOptionPane for my GUI class which previously extended JFrame?

The JOptionPane class will allow you to give any JComponent as argument
as well as which buttons and which Icon you want as argument. So in
your case, I would translate your JFrame into a JPanel, and then you
call the following (for example):

JOptionPane jOpt = new JOptionPane(yourPanel,
                           JOptionPane.QUESTION_MESSAGE,
JOptionPane.OK_CANCEL_OPTION);
JDialog dialog = jOpt.createDialog(parentPanel, "");

dialog.setVisible(true);
Object val = jOpt.getValue();
// Check for yes or no button pressed
if(val != null) {
    if(val instanceof Integer) {
        int intVal = ((Integer)val).intValue();
        if(intVal == JOptionPane.OK_OPTION) {
            // do the stuff you want to do if the user presses ok
        } else {
            // do the stuff you want to do if the user presses cancel
        }
    }
}

Kind regards, Jonck
PM - 31 May 2005 14:13 GMT
> > JOptionPane looks good, does the showInternal frame allow me to put, say, OK
> > and Cancel buttons on an internal frame on my GUI, and still have the rest
[quoted text clipped - 5 lines]
> your case, I would translate your JFrame into a JPanel, and then you
> call the following (for example):

<code snipped>

Many thanks for your detailed reply.

Pete


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.