INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Basic Java Login Form Help - JPasswordField Error

Basic Java Login Form Help - JPasswordField Error

Basic Java Login Form Help - JPasswordField Error

(OP)
Hi All,

I know this is probably a really basic question, however, I am making my first entry into Java programming and I am struggling a little with the coding and errors I'm getting.

My main issue is with this piece of code:

CODE


if(txtPassword.getText().equals("")||txtPassword.getText().equals(null))

It tells me that getText() is deprecated, but a) I'm not sure exactly what that means and b) what I'm supposed to do about it.

Also, if someone has a second, can you have a look over my code and see if I am doing this to the proper standards or have I missed something simple.

CODE

package Forms;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JButton;
import javax.swing.JPasswordField;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Color;
import javax.swing.SwingConstants;

public class frmLogon {

    private JFrame frmLogon;
    private JTextField txtUserID;
    private JPasswordField txtPassword;
    
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    frmLogon window = new frmLogon();
                    window.frmLogon.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public frmLogon() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frmLogon = new JFrame();
        frmLogon.setTitle("Logon");
        frmLogon.setBounds(100, 100, 253, 171);
        frmLogon.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frmLogon.getContentPane().setLayout(null);
        
        txtUserID = new JTextField();
        txtUserID.setBounds(77, 11, 152, 20);
        frmLogon.getContentPane().add(txtUserID);
        txtUserID.setColumns(10);
        
        txtPassword = new JPasswordField();
        txtPassword.setBounds(77, 42, 152, 20);
        frmLogon.getContentPane().add(txtPassword);
        
        JLabel lblUserId = new JLabel("User ID:");
        lblUserId.setBounds(10, 14, 57, 14);
        frmLogon.getContentPane().add(lblUserId);
        
        JLabel lblPassword = new JLabel("Password:");
        lblPassword.setBounds(10, 42, 57, 14);
        frmLogon.getContentPane().add(lblPassword);

        final JLabel lblError = new JLabel(" ");
        lblError.setHorizontalAlignment(SwingConstants.CENTER);
        lblError.setForeground(Color.RED);
        lblError.setBounds(10, 73, 219, 14);
        frmLogon.getContentPane().add(lblError);
        
        JButton btnLogon = new JButton("Logon");
        btnLogon.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
            
            //public final Boolean isEmpty()
                
            if(txtUserID.getText().equals("")||txtUserID.getText().equals(null))
                {
                    System.out.println("No User ID");
                    lblError.setText("Please Enter A User ID");
                }
            else
                {
                    if(txtPassword.getText().equals("")||txtPassword.getText().equals(null))
                        {
                            System.out.println("No Password");
                            lblError.setText("Please Enter A Password");
                        }
                    else
                        {
                            System.out.println("This is the value: xx" + txtUserID.getText() + "xx");
                            System.out.println("This is the value: xx" + txtPassword.getText() + "xx");
                            lblError.setText("  ");
                        }
                }
            }    
            
        });
        btnLogon.setBounds(20, 98, 89, 23);
        frmLogon.getContentPane().add(btnLogon);
        
        JButton btnQuit = new JButton("Quit");
        btnQuit.setBounds(119, 98, 89, 23);
        frmLogon.getContentPane().add(btnQuit);

    }
}

Many thanks for ANY help or support you can provide. I'm new to Java, have done some eTraining, but it's still a mystery.

Truely, Many Thanks,

Fitz

Fitz
Did you know, there are 10 types of people in this world:
* Those who understand binary
  and
* Those who Don't!!

RE: Basic Java Login Form Help - JPasswordField Error

If a method is deprecated then this basically means that it scheduled to be removed in a later Java version. It is still available for backwards compatibility, but it is advised to use another method as replacement.

The JPasswordField.getText() method is deprecated, because it is considered to be less secure than the JPasswordField.getPassword() method (that replaces it).  

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close