Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane; //Import JOptionPane Class
- public class P1I
- {
- public static void main (String args[])
- {
- //Stored info
- String my_username = "Joanne";
- int my_password = 1234;
- String username = JOptionPane.showInputDialog ("Enter username:"); //Dialog to get username
- String password = JOptionPane.showInputDialog ("Enter password"); //Dialog to get password
- int int_password = Integer.parseInt(password); //Convert String "password" into integer "int_password". This is done so that the stored password integer and the string can be compared directly. Also, this allows for calculations to be performed on the value.
- if (username.equals(my_username) && (int_password == my_password)) //Check if entered username and password matches the stored ones
- {
- System.out.println("Login Successful!");
- }
- else //If info do not match
- {
- System.out.println("Login Unsuccessful!");
- }
- System.exit(0); //End the program
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement