String User&密码组合不是简单的java检查

时间:2015-06-23 00:27:17

标签: java if-statement passwords

我只是Java的初学者。在这里,我想创建一个用户ID&密码输入,将被检查&告诉它是对还是错。但每次输入正确的组合时它都会给出错误的答案。 这是我的代码:

<?php
if(isset($_POST['Submit'])) {
$gender = $_POST['selectedGender'];
$height = $_POST['patientHeight'];
$result;
if ($gender == "Male") {
    $result = ($height * 4) - 128;
    echo $result; }           
else if ($gender == "Female") {    
    $result = ($height * 3.5) - 108;
    echo $result; }
}
?>
<html>
<div align="center">
<body>
<form name="form" method="post" action="<?php echo $PHP_SELF;?>">
    Select Your Gender: <select name="selectedGender">
        <option value=""></option>
        <option value="Male">Male</option>
        <option value="Female">Female</option>
    </select>
    <br><br>
    Enter Your Height: <input type="number" name="patientHeight" placeholder="Units are in Inches">
    <br><br>
    <input type="submit" name="Submit" value="Calculate Your Ideal Weight"/>
</form>
</body>
</div>
</html>

&安培;这是CheckID类,用于检查Email&amp;密码:

import java.awt.Container;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


public class Zihan {

public JFrame frame;
public JTextField textField;
public JPasswordField passwordField;
public static String gtxt,ptxt;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Zihan window = new Zihan();
                window.frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

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

/**
 * Initialize the contents of the frame.
 */
public void initialize() {
    frame = new JFrame();
    frame.setBounds(100, 100, 450, 300);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(null);

    JLabel lblEmailuserId = new JLabel("Email/User ID:");
    lblEmailuserId.setBounds(76, 30, 90, 14);
    frame.getContentPane().add(lblEmailuserId);

    textField = new JTextField();
    textField.setBounds(171, 27, 86, 20);
    frame.getContentPane().add(textField);
    textField.setColumns(10);

    passwordField = new JPasswordField();
    passwordField.setBounds(171, 87, 86, 20);
    frame.getContentPane().add(passwordField);

    JLabel lblPassword = new JLabel("Password:");
    lblPassword.setBounds(76, 90, 69, 14);
    frame.getContentPane().add(lblPassword);

    JButton btnLogIn = new JButton("Log In");
    btnLogIn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
             gtxt = textField.getText();
             ptxt = passwordField.getText();
             new CheckID(gtxt,ptxt);

            JFrame login = new JFrame("Login window");
            login.setSize(200, 200);
            login.setVisible(true);
            JLabel msg = new JLabel();
            msg.setText(CheckID.msgt);
            login.getContentPane().add(msg);
            frame.setVisible(false);
        }
    });
    btnLogIn.setBounds(121, 137, 89, 23);
    frame.getContentPane().add(btnLogIn);
    }
}

}

1 个答案:

答案 0 :(得分:0)

更改

if(tx==cU && px ==cP)

if(tx.equals(cU) && px.equals(cP))