10 as part of this implementation you need to create a user class that has the follo 5347042
10. As part of this implementation, you need to create a User class that has the following:
Instance variables (private variables in the class)
- User Id
- Password
- First Name
- Last Name
- Phone
Array of books checked out
Methods Implementation
Login
- This method checks a Userid_PassWord file to locate the user in the system.
- If the user is not in the system, it requests the user to create an account. In creating an account the user should be prompted for his/her First Name, Last Name, Phone, UserId and Password.
- A user object is created, and the user information is added to the Userid_PassWord file.
I have much of the UI already built, but I need help to complete the login.java. I will give full points to someone who can parse the code chunks as mentioned here.
Additionally, here are the files I have so far. May help in answering.
https://drive.google.com/folderview?id=0BzYRlHfihw6iWFVfb25sZmpOa2c&usp=sharing
login.java
/* Using JTextFields, JTextArea, and JPasswordField
EXAMPLE 12_03 FROM YOUR BOOK CHANGED
*/
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
//import javax.swing.*;
//import java.awt.*;
//import java.awt.event.*;
public class Login extends JFrame
{
private Container contents;
private JLabel idLabel, passwordLabel, priceLabel, price;
private JButton message;
private JTextField id;
private JPasswordField password;
private JTextArea legal;
private userType;
// Constructor
public Login( )
{
super( “Login Screen” );
contents = getContentPane( );
contents.setLayout( new FlowLayout( ) );
idLabel = new JLabel( “Enter id” ); // label for ID
id = new JTextField( “”,12 ); // instantiate ID text field
passwordLabel = new JLabel( “Enter password” ); // password label
password = new JPasswordField( 8 ); // instantiate password field
password.setEchoChar( '?' ); // set echo character to '?'
message = new JButton( “Log in above” ); // label to hold messages
/* priceLabel = new JLabel( “Price: ” ); // label for result
price = new JLabel( “???” ); // label to hold result
*/
// instantiate JTextArea with legal warning
legal = new JTextArea( “Warning: Any attempt to illegallyn”
+ “log in to this server is punishable by law.n”
+ “This corporation will not tolerate hacking,n”
+ “virus attacks, or other malicious acts.” );
legal.setEditable( false ); // disable typing in this field
// add all components to the window
contents.add( idLabel );
contents.add( id );
contents.add( passwordLabel );
contents.add( password );
contents.add( message );
contents.add( legal );
// instantiate event handler for the text fields
TextFieldHandler tfh = new TextFieldHandler( );
// add event handler as listener for ID and password fields
id.addActionListener( tfh );
password.addActionListener( tfh );
//message.addActionListener( tfh );
setSize( 250,200 );
setVisible( true );
}
//Accessor for UserType
public int getUserType ()
{ return userType;
}
// private inner class event handler
private class TextFieldHandler implements ActionListener
{
//boolean found;
public void actionPerformed( ActionEvent evt )
{
// Set Userid Var
String id = id.getText( );
String password = new String( password.getPassword( ) );
//OPEN THE USER FILE AND COMPARE EACH LINE TO LOCATE USERID AND PASSWORD
//you must loop THROUGH THE WHOLE FILE UNTIL FOUND AND/OR EOF
if ( id.equals( “admin” ) && password.equals( “admin” ) )
{
message.setForeground( Color.BLACK );
message.setText( “Welcome!” );
found =true;
userType =0;
}
else //Search Users file
{
//Open USers file
// Loop to read each record
// you must loop THROUGH THE WHOLE FILE UNTIL FOUND AND/OR EOF
while (stringread != null && !found)
{
if ()
{
//build User Object and create the correct GUI Interface
//if matched Welcome user -do the same as administator above
//Creating an array of user books –
//When building make sure to look for the number of books the
//user has checked out
// where noBooks is the variable that indicates how many books have been checked out
//
for (int ct=0; ct
{
}
}
//read next record
}
}
if (!found)
{
message.setForeground( Color.RED );
message.setText( “Sorry: wrong login” );
}
else
{ //Create user
}
}
public static void main( String [] args )
{
Login login = new Login( );
login.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
}