Solved

how to pop up 2 JOptionPane at the same time? and set timer on JOptionPane (currently doing RMI client-server program)

Posted on 2004-03-31
11
890 Views
Last Modified: 2012-06-27
hi to all experts,
i m currently doing RMI client-server program, got a few questions want to ask.

suitation is like that:
there is 1 server to many clients. when each client connect to the server, they will display a list of all clients. client can then choose a client for a little 1-on1 game. when clientA invite clientB for a game, i want to pop up a JOptionPane to clientA saying "waiting for B reply.... u may cancel the game" and clientB will pop up a JOptionPane saying "A is inviting u for a game, YES_NO_OPTION". but since when the JOptionPane is shown, no other input or output will be accepted or sent to the monitor i can only pop up 1 JOptionPane at a time :(   And i would like to make a count down timer to both JOptionPane, say 15secods.... when the timer coun  down to 0, JOptionPane in both side will close and display..... "Time's up baby". and last time, before the timer is running out of time, if clientA click the "CANCEL" button, he/she can terminate the invitation.

so therefore the questions are:
1. how to pop up 2 JOptionPane (must be modal) to 2 clients at the same time?
2. how to set a count down timer to both JOptionPane, so that when the time is up, both JOptionPane will close
3. how to close the opposite JOptionPane (before the time is running out?)

many thanks to you all !
Justin
0
Comment
Question by:ahmehmeh
  • 5
  • 3
  • 2
  • +1
11 Comments
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10728217
You should use JDialog instead of JOptionPane.
0
 
LVL 16

Accepted Solution

by:
gnoon earned 125 total points
ID: 10729196
>but since when the JOptionPane is shown, no other input or output will be accepted or sent to the monitor
You couldn't use modal dialog if you want the background process still active.

>1. how to pop up 2 JOptionPane (must be modal) to 2 clients at the same time?
That could be out of control depends on connection speed of 2 clients to server, but
if you know both of connection speeds, you'll know what time you'll send to who (for good measure).

>2. how to set a count down timer to both JOptionPane, so that when the time is up, both JOptionPane will close
You can, here an example:

        final JLabel label = new JLabel("");
        javax.swing.Timer t = new javax.swing.Timer(1000,
          new ActionListener() {
              int timeOut = 15; // 15sec
              public void actionPerformed(ActionEvent e) {
                  label.setText(""+timeOut--);
              }
          });
        t.start();  // Start the time
        JOptionPane.showMessageDialog(null,label);

>3. how to close the opposite JOptionPane (before the time is running out?)
It needs to be JDialog instead of JOptionPane (as GrandSchtroumpf said) unless you'll implement your own JOptionPane to handle the inner dilaog.
0
 
LVL 16

Expert Comment

by:gnoon
ID: 10729224
>You couldn't use modal dialog if you want the background process still active
and you can if you have done the process before show the dialog.
0
 

Author Comment

by:ahmehmeh
ID: 10730231
thanks :)

i have tried JDialog before, and set the 'modal' parameter to 'true', but still couldnt work (i.e. pop 2 up at the same time)
so what you guys mean, i cannot make these dialog to modal ?  :(
0
 
LVL 16

Expert Comment

by:gnoon
ID: 10730293
> have tried JDialog before, ... i cannot make these dialog to modal
Did you pass it a reference of parent frame (a frame which'll be under the dialog)?
If not, so modal shouldn't works (it needs a parent for modal)?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:ahmehmeh
ID: 10731273
well... yes.. i hv pass it to the parent frame and set the modal to true... but it doesnt allow to pop up dialog at the same time...  and it only works (ie. pop up 2 dialog) if i set the modal to false :/
0
 
LVL 16

Expert Comment

by:gnoon
ID: 10737709
Yes .... you cann't show 2 modal dialogs on the same machine at the same time.
0
 
LVL 16

Expert Comment

by:gnoon
ID: 10737758
However, you can if they're on different VM (just a modal dialog per VM).
0
 

Expert Comment

by:RobCSP
ID: 10739174
Hi, if you want to test your application with only 1 computer, you must  execute it in linux, in this way, you can have a lot of  clients and 1 server at the same time. (and the dialogs will be displayed)
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10739350
what you can do is to show your first modal JDialog with your Frame as owner and show your second JDialog with your first JDialog as owner.
0
 
LVL 30

Expert Comment

by:GrandSchtroumpf
ID: 10739544
oops, i forgot what the original question was about and thought you needed 2 modal JDialogs on one client... which is not the case.
I suppose that you are currently using JOptionPane static show methods, which does not allow you to close the dialog progammatically.  That's why you sould use JDialog.
What you need to do is to create a new thread that handles the communication with the other client (invites the other client to play, and listen to the response).  You start that thread and then you show your modal JDialog.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Cipher Configuration on Apache HTTPD 4 53
difference of if loops 23 41
javap not working 8 37
eclipse apache tomcat admin console 45 55
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now