I am working on a Java project where I am to create a Online
I am working on a Java project where I am to create a Online University Registration System, Currently I am having issues with my Login class checking the credentials and sending them to the appropriate second screen. What would I need to do to get this desired effect of logging in based on your credentials what I have currently provides a login screen and a set of credentials I am using as an example.
Credentials.Java
import java.util.ArrayList;
public class Credentials
{
private ArrayList<String> validUsers;
private ArrayList<String> validPasswords;
// This is where users and passwords can be added
public void userList()
{
validUsers = new ArrayList<String>();
validPasswords = new ArrayList<String>();
validUsers.add(\"student\");
validUsers.add(\"professor\");
validUsers.add(\"departmenthead\");
validUsers.add(\"registration\");
validPasswords.add(\"1111\");
validPasswords.add(\"2222\");
validPasswords.add(\"3333\");
validPasswords.add(\"4444\");
}
public ArrayList<String> getValidUsers()
{
return validUsers;
}
public ArrayList<String> getValidPasswords()
{
return validPasswords;
}
}
Loginview.Java:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class LoginScreen {
//needs to be an instance variable to interact with outside classes
private JFrame loginFrame;
BigSystem bsys;
public void hideScreen() {
loginFrame.setVisible(false);
}
public void showScreen() {
loginFrame.setVisible(true);
}
/**
* Constructs a telephone with a speaker, keypad, and microphone.
*/
public LoginScreen(BigSystem b) {
bsys = b;
//JPanel is a generic lightweight container.
//It will contain other components.
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
mainPanel.add(new JLabel(\"Username:\"));
JButton loginButton = new JButton(\"Login\");
mainPanel.add(loginButton);
loginButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
//set state 1 to show student screen
bsys.setState(1); //pass the key pressed as a String
}
});
loginFrame = new JFrame();
loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
loginFrame.add(mainPanel);
loginFrame.pack();
//loginFrame.setVisible(true);
}
}
Solution
Here is the code of NextPage.java
Here is the code of LoginDemo.java
| import javax.swing.*; import java.awt.*; class NextPage extends JFrame { NextPage() { setDefaultCloseOperation(javax.swing. WindowConstants.DISPOSE_ON_CLOSE); setTitle(\"Welcome\"); setSize(400, 200); } } |

