Created
May 12, 2015 16:38
-
-
Save MrBean83/70f5397eb0eae81cac5e to your computer and use it in GitHub Desktop.
Simple JOptionPane examples in Java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/***************************************************** | |
* | |
* Program Name: Password | |
* | |
* Author: Henry Nichols | |
* | |
* Remarks: JOptionPane examples | |
* | |
*****************************************************/ | |
/********************************** | |
* Imports | |
**********************************/ | |
import javax.swing.JOptionPane; | |
import java.text.*; | |
class Password | |
{ | |
public static void main(String args[]) | |
{ | |
/************************************ | |
* input dialog - ask for a User ID | |
************************************/ | |
String userID = JOptionPane.showInputDialog | |
(null, "Please enter your user name", "Input", JOptionPane.QUESTION_MESSAGE ); | |
/***************************************** | |
* input dialog - ask for user password | |
*****************************************/ | |
String password = JOptionPane.showInputDialog | |
(null, "Please enter your password", "Input", JOptionPane.QUESTION_MESSAGE ); | |
/************************************************************ | |
* if/else if branch for user ID and password authentication | |
************************************************************/ | |
if(userID.equals("admin") && password.equals("open")) | |
{ | |
JOptionPane.showMessageDialog | |
(null, "welcome", "Administrative Logon", JOptionPane.PLAIN_MESSAGE ); | |
} | |
else if(userID.equals("admin") & !(password.equals("open"))) | |
{ | |
JOptionPane.showMessageDialog | |
(null, "invalid password", "Administrative Logon", JOptionPane.ERROR_MESSAGE); | |
} | |
else if(!(userID.equals("admin")) & password.equals("open")) | |
{ | |
JOptionPane.showMessageDialog | |
(null, "invalid user id", "Administrative Logon", JOptionPane.ERROR_MESSAGE); | |
} | |
else | |
JOptionPane.showMessageDialog | |
(null, "invalid user id and password", "Administrative Logon", JOptionPane.ERROR_MESSAGE); | |
System.exit(0); | |
} // end main | |
} // end class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment