Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
SQL
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());}
  }
}



C#
import javax.swing.*;
import java.awt.*;

class NextPage extends JFrame
{
  NextPage()
 {
 setDefaultCloseOperation(javax.swing.
  WindowConstants.DISPOSE_ON_CLOSE);
 setTitle("Welcome");
 setSize(400, 200);
  }
 }
Posted
Comments
Joan M 29-Aug-12 11:03am    
Your friend is right, at least the requirement for having two arrays is not met.
Punggak code 29-Aug-12 11:16am    
Thanz for remind me..I got it..Thanz again
Joan M 29-Aug-12 11:18am    
You are welcome...
TorstenH. 30-Aug-12 2:05am    
It's talking about a Applet - but is a GUI part of the task? I don't really think so.

1 solution

Sounds like OP resolved it by himself so posting this to put it out of unanswered list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900