I got an assignment to build one program like the question below .. I made a bit of code that has a login and password ..Its also get from the website.. but my friend told me do not meet what the question wants .. is there anyone who can explain to me what the question wants?
I am new in JAVA environment..Thanz
Q1.Many e-commerce websites and intranets require a login and password in order to access data from the site. Write an applet that will ask the user for ID and password through INPUT DIALOG of JoptionPane package. Once the user entered the login and password, the applet will search through an array of Ids and passwords for verification (each array consist of 5 values). The applet then will display an appropriate message. Write the code to create two arrays, one for IDs and one for the corresponding passwords. You will write a loop to progress through the array, searching for a valid ID and password.
Q2.Based on question 1, you are required to accept the user input , login and password through text field and passwordField. Once the user pressed the login and password, the applet will search through an array of Ids and passwords for verification. The applet then will display an appropriate message. Write the code to create two arrays, one for IDs and one for the corresponding passwords. You will write a loop to progress through the array, searching for a valid ID and password.
Q3.Based on question 2, both input, login and password will be from text field. Thepassword is not displayed on the applet. The character ‘*’ is used to displayed instead of the alphanumeric characters. The method setEchoChar() is used to display ‘*’ in the TextField (DO not use passwordField). Once the user pressed the login button, the applet will search through an array of IDs and passwords for verification. The applet then will display an appropriate message.
Coding
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
label1 = new JLabel();
label1.setText("Username:");
text1 = new JTextField(15);
label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);
SUBMIT=new JButton("SUBMIT");
panel=new JPanel(new GridLayout(3,1));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("LOGIN FORM");
}
public void actionPerformed(ActionEvent ae)
{
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("Bacteria") && value2.equals("Bacteria")) {
NextPage page=new NextPage();
page.setVisible(true);
JLabel label = new JLabel("Welcome:"+value1);
page.getContentPane().add(label);
}
else{
System.out.println("enter the valid username and password");
JOptionPane.showMessageDialog(this,"Incorrect login or password",
"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
class LoginDemo
{
public static void main(String arg[])
{
try
{
Login frame=new Login();
frame.setSize(300,100);
frame.setVisible(true);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}
}
import javax.swing.*;
import java.awt.*;
class NextPage extends JFrame
{
NextPage()
{
setDefaultCloseOperation(javax.swing.
WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Welcome");
setSize(400, 200);
}
}