Bob Tanner wrote:

> Is it just me or are inner-anonymous classes just hard to read?
>
> I believe this is an inner-anonymous class?
>
>   public PasswordAuthentication
>     getPasswordAuthentication() {
>       String username, password;
>
>       String result = JOptionPane.showInputDialog("Enter 'username,password'");
>
>       StringTokenizer st = new StringTokenizer(result, ",");
>       username = st.nextToken();
>       password = st.nextToken();
>
>       return new PasswordAuthentication(username, password);
>   }
>
> I'm not sure how to read this code.
>
> Anyone wanna give this a chatty interpretation?

The method getPasswordAuthentication takes no parameters and returns an object of
type PasswordAuthentication.

1. String username, password;

Initialized the local variables username and password to type String

2. String result = JOptionPane.showInputDialog("Enter 'username,password'");

This one confuses me a bit because I normally do not deal with Swing classes.
However, it looks like it grabs the username and password entered through the
JOptionPane in the form 'username, password'

3. StringTokenizer st = new StringTokenizer(result, ",");

Using the java class StringTokenizer, extract the username and password which are
delimited by a comma

4. username = st.nextToken();

The first String chunk, which is username, is grabed through the nextToken method
and the local variable username is set to the nextToken's return value

5. password = st.nextToken();

The second String chunk, which is password, is grabed through the nextToken method
and the local variable password set to the nextToken's return value

6. return new PasswordAuthentication(username, password);

An instance of PasswordAuthentication is initialized with the values contained in
username and password.  This instance is returned to the calling method.


I suppose you were looking for an explanation of the JOptionPane which is where
this explanation breaks down because I don't know how it works because I don't do
GUIs.  My GUESS is that an instance of JOptionPane pops up, the user is expected to
enter a String in the form of 'username, password' and either the 'Enter' key or a
button is pressed by the user on the dialog box and control is returned to the
getPasswordAuthentication method where the information entered is extracted by use
of the showInputDialog method.

--
Perry Hoekstra
E-Commerce Architect
Talent Software Services
perry.hoekstra at talentemail.com