• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help on this scenario  RSS feed

 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello to all,

Here is the scenario:-

My Swing application makes registry entry when it is installed on machine so that after 60 days of installation it prompts user to enter a passcode.This part is working fine. Now when i am prompting for a passcode using a JFrame the application still gets run i mean tha code after the regidtry checking and displaying the JFrame gets executed. I want that code to not run untill the passcode checking and validation are performed. However when i am simply displaying a messagedialogbox using




the application flow halts and the flow continues only when ok button of the dialog box is pressed.

So my question is
1. How to achieve the desired behaviour using my own JFrame which prompts for passcode. (My guess is this has something to do with Threading )

2. What code is there in JOptionpane that is making possible the behaviour?

Thanks and Regards,
-- Girish --
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Girish,

Before you call a setVisible on your JFrame, you need to check if the pass code is required.
If it is required, you can invoke the same JOptionPane call. However, just pass null instead of "this".
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sir thanks for the reply,

Here is the code i am posting..



Now what I need is I get the same behaviour by using PasscodePrompt panel as i get when i use JOptionPane. When i comment JOptionPane and use PasscodePrompt panel the code below the constructor also gets executed resulting in exposing the main application. I want to expose the main application only after the passcode entered is valid.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Girish,
Please drop the "sir" We are a friendly and informal group here at the ranch!

When i comment JOptionPane and use PasscodePrompt panel the code below the constructor also gets executed resulting in exposing the main application.

As per the code you have posted, invoking the constructor (new JFrame()) does not expose the main application as you call it. That is being done by
frame.setVisible(true);


Check out JOptionPane#showConfirmDialog. You can pass your PasscodePromptPanel to it and then display your main application frame if the passcode is correct.
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Girish Vasmatkar:
Now what I need is I get the same behaviour by using PasscodePrompt panel as i get when i use JOptionPane.


So you want your PasscodePrompt dialog to be modal
like JOptionPane.showMessageDialog()'s--is that it??

Perhaps the easiest way to do this is to actually use
JOptionPane.showXxx(). Note that you can pass in an
entire Panel/JPanel to JOptionPane's show methods, so
you can make it appear exactly the way you want.
[ November 21, 2008: Message edited by: Brian Cole ]
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code i am writing to make things work for me but still no success..



This code doesn't work for me as my PasscodePrompt is not getting displayed rather a their own JOptionPane is being displayed.
 
Brian Cole
Author
Ranch Hand
Posts: 949
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Girish Vasmatkar:
JOptionPane.showConfirmDialog(passcodePrompt, null);


What are you expecting this to do?

The first parameter is used only for screen positioning and modal
"what's on top of what" window behavior. It can even be null (though
it's much better for it not to be null). In your case you are passing
passcodePrompt for this parameter--is it even a visible Frame?

The second parameter is what will actually appear as the content of
the dialog. I can't think of any situation where it would be useful
to pass null for this parameter as you are doing.

You haven't explained what kind of thing PasscodePrompt is, so it's
hard to give you much advice. If it's a JPanel try calling
JOptionPane.showConfirmDialog(frame, passcodePrompt).

If it's a JFrame you could try
JOptionPane.showConfirmDialog(frame, passcodePrompt.getContentPane()).

If it's neither then you might want to disclose what the heck it is.

[edit: fix parens in passcodePrompt.getContentPane()]
[ November 23, 2008: Message edited by: Brian Cole ]
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it is a JPanel and i have got it to work. But now what i am seeing is that the JOptionPane frame's three buttons viz. "Yes","No","Cancel" are also being shown as part of my customized JPanel passcodePrompt. My JPanel contains
1.TextField : to get the passcode
2.Ok and Cancel buttons.

That means not there are five Buttons in total are displayed.

As my JPanel has some designing i can not use the buttons as provided by the JOptionPane.

I have tried to remove that part of the JOptionPane but to no effect. The simle thing that i want is my JPanel should be shown and nothing else.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> The simle thing that i want is my JPanel should be shown and nothing else.

use a JDialog (setModal(true)) instead of a JOptionPane
 
Girish Vasmatkar
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Michael Dunn:

use a JDialog (setModal(true)) instead of a JOptionPane


Thanks Michael It's working now.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!