Hi all
I try to copy paste from a site java example ,there are 3 files,Main.java,Login.java,and LoginDialog.java.
I can compile Login.java ,but when I compile LoginDialog.java,it said that it cannot find symbol Login.authenticate (a method in Login.java)
I have check that there is this Login.authenticate method

to make clearer I attach Login.java,and LoginDialog.java below
the source site is http://www.javaswing.org/jdialog-login-dialog-example.aspx
Hope that someone with more experience can teach me where to fix.
I place source code and class in c:\java\jdialogdemo

thank you
denny

///----------------------------------------

package jdialogdemo;

public class Login {

    public static boolean authenticate(String username, String password) {
        // hardcoded username and password
        if (username.equals("bob") && password.equals("secret")) {
            return true;
        }
        return false;
    }
}

//---------------------------------

package jdialogdemo;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;

public class LoginDialog extends JDialog {

    private JTextField tfUsername;
    private JPasswordField pfPassword;
    private JLabel lbUsername;
    private JLabel lbPassword;
    private JButton btnLogin;
    private JButton btnCancel;
    private boolean succeeded;

    public LoginDialog(Frame parent) {
        super(parent, "Login", true);
        //
        JPanel panel = new JPanel(new GridBagLayout());
        GridBagConstraints cs = new GridBagConstraints();

        cs.fill = GridBagConstraints.HORIZONTAL;

        lbUsername = new JLabel("Username: ");
        cs.gridx = 0;
        cs.gridy = 0;
        cs.gridwidth = 1;
        panel.add(lbUsername, cs);

        tfUsername = new JTextField(20);
        cs.gridx = 1;
        cs.gridy = 0;
        cs.gridwidth = 2;
        panel.add(tfUsername, cs);

        lbPassword = new JLabel("Password: ");
        cs.gridx = 0;
        cs.gridy = 1;
        cs.gridwidth = 1;
        panel.add(lbPassword, cs);

        pfPassword = new JPasswordField(20);
        cs.gridx = 1;
        cs.gridy = 1;
        cs.gridwidth = 2;
        panel.add(pfPassword, cs);
        panel.setBorder(new LineBorder(Color.GRAY));


        btnLogin = new JButton("Login");

        btnLogin.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                if (Login.authenticate(getUsername(), getPassword())) {
                    JOptionPane.showMessageDialog(LoginDialog.this,
                            "Hi " + getUsername() + "! You have successfully logged in.",
                            "Login",
                            JOptionPane.INFORMATION_MESSAGE);
                    succeeded = true;
                    dispose();
                } else {
                    JOptionPane.showMessageDialog(LoginDialog.this,
                            "Invalid username or password",
                            "Login",
                            JOptionPane.ERROR_MESSAGE);
                    // reset username and password
                    tfUsername.setText("");
                    pfPassword.setText("");
                    succeeded = false;

                }
            }
        });
        btnCancel = new JButton("Cancel");
        btnCancel.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });
        JPanel bp = new JPanel();
        bp.add(btnLogin);
        bp.add(btnCancel);



        getContentPane().add(panel, BorderLayout.CENTER);
        getContentPane().add(bp, BorderLayout.PAGE_END);

        pack();
        setResizable(false);
        setLocationRelativeTo(parent);
    }

    public String getUsername() {
        return tfUsername.getText().trim();
    }

    public String getPassword() {
        return new String(pfPassword.getPassword());
    }

    public boolean isSucceeded() {
        return succeeded;
    }
}

Please post the FULL text of the error message.
To copy the contents of the command prompt window:
Click on Icon in upper left corner
Select Edit
Select 'Select All' - The selection will show
Click in upper left again
Select Edit and click 'Copy'

Paste here.

Also show the commandline that you are using to compile the program.
The classpath should be set to the folder that contains the package folder: jdialogdemo

here is the command line error

thank you
denny

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.


C:\Documents and Settings\han>cd\


C:\>cd\


C:\>cd c:\program files\java\jdk1.6.0_25\bin


C:\Program Files\Java\jdk1.6.0_25\bin>javac c:\java\jdialogdemo\LoginDialog.java


c:\java\jdialogdemo\LoginDialog.java:60: cannot find symbol
symbol: variable Login
if (Login.authenticate(getUsername(), getPassword())) {
^
1 error


C:\Program Files\Java\jdk1.6.0_25\bin>

and here is the command line to compile Login.java

thank you
denny

//-----------------------------

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\han>cd\Program Files\java\jdk1.6.0_25\bin

C:\Program Files\Java\jdk1.6.0_25\bin>javac c:\java\jdialogdemo\Login.java

C:\Program Files\Java\jdk1.6.0_25\bin>

do learn to use your tools. You NEVER run the JDK tooling from the installation directory.
Run them from the root of your source directory, setting the appropriate environment variables to point to the JDK tooling, and the appropriate commandline parameters for the compiler to direct its input and output directories as well as its classpath.

Documentation for both is available with your tooling and operating system.

For the javac command to find a class definition the definition needs to be on the classpath. The compiler can not find the definition for the Login class.

The classpath should be set to the folder that contains the package folder: jdialogdemo
since Login is in that package.

Hello

I have succeded create class,but I wonder why there are more than one class
made ,this time I use another example ,and it logically has to create 2 classes DialogDemo.class and CustomDialog.class,but it create DialogDemo$1.class,Dialogdemo$2 Custom Dialog$1 CustomDialog$2 etc (there are 11 clases all), when I run java DialogDemo ,it ok , run as it has to be.
is that ok ? Or there is still something wrong ?

thanks
denny

You're using inner classes, the XXX$YYY.class are inner classes to XXX.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.