Skip to content

Instantly share code, notes, and snippets.

@MrBean83
Created May 12, 2015 16:38
Show Gist options
  • Save MrBean83/70f5397eb0eae81cac5e to your computer and use it in GitHub Desktop.
Save MrBean83/70f5397eb0eae81cac5e to your computer and use it in GitHub Desktop.
Simple JOptionPane examples in Java
/*****************************************************
*
* 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