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 / December 2004

Tip: Looking for answers? Try searching our database.

Modal dialog?

Thread view: 
Jan Danielsson - 29 Dec 2004 12:40 GMT
Hello,

First, this is what I'm doing..

I have written a class I call AuthenticationManager. It keeps track of a
database name, user name and passphrase. It has a method called
getAuthentication() which opens a windows with three fields (one for
each of the values I listed). The window contains an ok and a cancel
button. The authMgr object is contained in my application's main JFrame
window.

From my main application frame I want to be able to call
authMgr.getAuthentication() and it should return true or false depending
on if ok or cancel was pressed to close the window.

At first, I just created a new window, and all was well, but when I ran
the application this code didn't do what I wanted:
----------------------
  AuthenticationManager authMgr = new AuthenticationManager();
  if(authMgr.getAuthentication())
  {
    System.out.println("Got authentication information: " +
    authMgr.getDBName() + ", " + authMgr.getDBUser() +
    ", " + authMgr.getDBPass());
  }
  else
  {
     System.out.println("Didn't get authentication");
  }
----------------------

Instead of waiting for an action (ok or cancel button), it immediately
printed "Didn't get authentication". Obviously, I'm new to Java
programming...

I did manage to get it working like I want my changing "extends JFrame"
to "extends JDialog" and added "setModal(true)" to the constructor.

Now I'm almost happy, there are just two issues. One major and one minor:

minor: Whenever I move the mouse-pointer over one of the entry fields,
it doesn't change to one of those 'I'-pointers - it just remains looking
like a standard arrow. This is what caused my major concern:

I get the feeling that what I've done is simply create an ugly hack -
that it works because of side-effects. I would like to know how this
should be done .. officially.

Any ideas? Do I need to provide more information? I can post code if
required.
Antti S. Brax - 29 Dec 2004 13:19 GMT
jan.danielsson@gmail.com wrote in comp.lang.java.gui:
> Instead of waiting for an action (ok or cancel button), it immediately
> printed "Didn't get authentication". Obviously, I'm new to Java
> programming...

    Impossible to say for sure, because you did not include the
    relevant code: the AuthenticationManager.

    http://www.physci.org/codes/sscce.jsp

    Still, it sounds like you're not waiting for the button press.
    AuthenticationManager.getAuthentication() has to, in some point,
    stop to wait for the button press event.

Signature

Antti S. Brax                  Rullalautailu pitää lapset poissa ladulta
http://www.iki.fi/asb/         http://www.cs.helsinki.fi/u/abrax/hlb/
       "Disconnect this cable to shorten, re-connect to lengthen."
         -- Instructions on Logitech's USB mouse extension cord.

Andrew Thompson - 29 Dec 2004 13:27 GMT
> minor: Whenever I move the mouse-pointer over one of the entry fields,
> it doesn't change to one of those 'I'-pointers - it just remains looking
> like a standard arrow.

Works here for system and Xplat PLAF's using Java 1.5.0 under WinXP..
<sscce>
import java.awt.*;
import javax.swing.*;

/** Demonstrates the 'I' pointer for textual input for
the xplat and system PLAFs. */
public class WhereIsMyI {

 /** Provide an argument to flip the PLAF. */
 public static void main(String[] args) {

   boolean bXPlatform = !(args.length==0);
   try {
     if (bXPlatform) {
         UIManager.setLookAndFeel(
         UIManager.getCrossPlatformLookAndFeelClassName() );
     } else {
       UIManager.setLookAndFeel(
         UIManager.getSystemLookAndFeelClassName());
     }
   } catch (Exception exc) {
     System.err.println("Error loading L&F: " + exc);
   }
   JDialog dialog = new JDialog((Frame)null, true);
   Container container = dialog.getContentPane();
   container.setLayout(new GridLayout(1,0) );
   container.add(new JLabel("Put a String"));
   container.add( new JTextField(10) );
   dialog.pack();
   dialog.setVisible(true);
 }
}
<sscce>

> Any ideas?

It is a problem in you code (100:1).

>..Do I need to provide more information?

Yes, an SSCCE
<http://www.physci.org/codes/sscce.jsp>

> ..I can post code if required.

No, please, not 'code', so much as an SSCCE.

Oh, and it seems a modal JDialog is just what you need.

HTH

Signature

Andrew Thompson
http://www.PhySci.org/codes/  Web & IT Help
http://www.PhySci.org/  Open-source software suite
http://www.1point1C.org/  Science & Technology
http://www.LensEscapes.com/  Images that escape the mundane



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.