login window - gui with file io
I am trying to make a login window that checks a flat file 'clients.dat' to verify the user name and password. I am not using sql and I don't want to use it. How do I add the file io to my gui?
here is my login window gui:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class mainGUI extends JFrame implements ActionListener
{
private static final long serialVersionUID = 1L;
// textfield labels
private JLabel useridLabel = new JLabel ( "User ID:" );
private JLabel passwordLabel = new JLabel ( "Last Name: " );
// textfields
private JTextField useridText = new JTextField( 20 );
private JPasswordField passwordText = new JPasswordField( 20 );
// message labels
private JLabel mainMessage = new JLabel( " Click Register To Create An Account" );
private JLabel spacer = new JLabel( "" );
// buttons
private JButton submitButton = new JButton("Submit");
private JButton registerButton = new JButton("Register");
private JButton cancelButton = new JButton("Cancel");
public static void main(String[] args)
{
mainGUI app = new mainGUI();
app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public mainGUI()
{
super("Welcome To The Electronic Bidding System");
Container content = getContentPane();
content.setBackground( Color.lightGray );
// Message
JPanel messageArea = new JPanel();
messageArea.setLayout( new BorderLayout() );
mainMessage.setForeground( new Color(0xff0000) );
messageArea.add( mainMessage, BorderLayout.CENTER );
messageArea.add( spacer, BorderLayout.SOUTH );
content.add( messageArea, BorderLayout.NORTH );
// Textfield area and messages
JPanel controlArea = new JPanel( new GridLayout(3, 2) );
controlArea.add( useridLabel );
controlArea.add( useridText );
controlArea.add( passwordLabel );
controlArea.add( passwordText );
content.add( controlArea, BorderLayout.EAST );
// Label Area
JPanel labelArea = new JPanel();
// Preferred height is irrelevant, since using WEST region
labelArea.setPreferredSize(new Dimension(100, 0));
labelArea.add( useridLabel );
labelArea.add( passwordLabel );
content.add( labelArea, BorderLayout.WEST );
// Button Area
JPanel buttonArea = new JPanel();
buttonArea.add( submitButton );
buttonArea.add( registerButton );
buttonArea.add( cancelButton );
submitButton.addActionListener( this );
cancelButton.addActionListener( this );
content.add( buttonArea, BorderLayout.SOUTH );
pack();
setVisible( true );
//setSize(650, 200);
setResizable( false );
//}
cancelButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent event)
{
setDefaultCloseOperation( EXIT_ON_CLOSE );
dispose(); // remove main window
}
}
); // end cancelButton.addActionListener
registerButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent event)
{
NURegister opennureg = new NURegister();
dispose(); // remove main window
}
}
); // end registerButton.addActionListener
submitButton.addActionListener( new ActionListener()
{
public void actionPerformed( ActionEvent event )
{
useridText.setBackground(Color.WHITE);
passwordText.setBackground(Color.WHITE);
// if userid is not digits, error, change color of field to red
if( !useridText.getText().matches("\\d+") )
{
useridText.setBackground(Color.RED);
}
// if firstname is not a string, error, change color of field to red
if( !passwordText.getSelectedText().matches("\\S+") )// password must be a string
{
passwordText.setBackground(Color.RED);
}
}
}
); // end submitButton.addActionListener
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
}

