Page 2 of 2 FirstFirst 12
Results 21 to 35 of 35
  1. #21
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    yes that vector is not needed because you don't use it....
    instead use you controller and store the data in it :P

  2. #22
    Winniee is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    hehe i guess Realised that controller is actually vector!


    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.Date;
    import java.text.*;
    
    public class Project extends JFrame{
    
    	 JPanel pNorth,pSouth;	
    	 JButton btn1,btn2;
    	 JTextField tfUser;
    	 JPasswordField tfPass;
    	 JLabel lblUser, lblPass;
    	 DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    	String [] userName = {"0811111A","0822222B","08333333C"};//for the list of predetermined users
    	String [] userPassword = {"p1", "p2","p3"};//for the list of predetermined users
    	String [] userType = {"Student", "Tutor"};//for checking user type
    	private ProjectController controller;
    
    	
        public Project() {
        setTitle("Student Attendence System");
       	setSize(300,150);
       	setResizable(false);
       	setLayout(new BorderLayout());
       	
    	ProjectController controller = new ProjectController();
    	for (int i=0;i<3;i++){
     	 //insert data into controller
      	controller.createProjectRec(userName[i], userPassword[i], "Student");
    	}
    	Date date = new Date();
        String datetime = dateFormat.format(date);
        
    
       	pNorth = new JPanel();
       	pSouth = new JPanel();
       	pNorth.setLayout(new GridLayout(2,2));
       	pSouth.setLayout(new GridLayout(1,3));
       	
       	lblUser = new JLabel("user ID");
       	tfUser = new JTextField();
       	lblPass = new JLabel("Password");
       	tfPass = new JPasswordField();
       	btn1 = new JButton("Login");
       	btn2 = new JButton("Clear");
       
       btn1.addActionListener(new LoginHandler());
       btn2.addActionListener(new ClearHandler());
       
       pNorth.add(lblUser);
       pNorth.add(tfUser);
       pNorth.add(lblPass);
       pNorth.add(tfPass);
       pSouth.add(btn1);
          pSouth.add(btn2);
          
          add(pNorth, "Center");
          add(pSouth, "South");
          setVisible(true);
        }
        class LoginHandler implements ActionListener
        {
        public void actionPerformed(ActionEvent evt)
        {
        	
         String User = tfUser.getText();
         String pass = "";
        
         try{ pass = tfPass.getText();}
         catch(Exception ex){
      
         //create Project object
         ProjectRec p = new ProjectRec("0811111A", "Date", "Student");   
         }
         if (checkPassword(User,pass)){
    
         Date date = new Date();
         String datetime = dateFormat.format(date);
         ProjectController controller = new ProjectController();   
         String[] info = controller.getProjectInfo(User);//check the type
         
         if (info[1].equals("Student")){
               // do things for student
         
         } else if (info[1].equals("Tutor")){
               // do things for tutor
         }
    	} else {
    	JOptionPane.showMessageDialog(null, "Invalid user & Password!" , "Message", JOptionPane.PLAIN_MESSAGE);
        }
        }
        }
        class ClearHandler implements ActionListener
        {
        public void actionPerformed(ActionEvent evt)
        {
        	tfUser.setText(""); // clear the output fields
        	tfPass.setText("");
        }
        }
        public boolean checkPassword(String nm, String pwd)
    	{
    		int userIndex = -1;
    		
    		for(int i = 0; i<userName.length; i++)
    		{
    			if(userName[i].equals(nm))
    			{
    				userIndex = i;
    			}
    		}
    		
    		// check if user exists
    		if (userIndex == -1) return false;
    		
    		if(userPassword[userIndex].equals(pwd))
    		{
    			// user exists and password is correct
    			return true;
    		}
    		
    		// user exist and password is incorrect
    		return false;
    	}
        public static void main(String args[])
        {
        	JFrame.setDefaultLookAndFeelDecorated(true);
        	Project gui = new Project();
        }  
    }

    Wolf.. can you tell me why i still can't display anything when i entered e correct password & user? i Dont know where my mistake is.. =(

  3. #23
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    you already have a Vector which contains your data in the Controller...
    why should you add another one which you won't use?

  4. #24
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    there are still some basic mistakes....

    1) i have written here only the comments but you should write your code to make to preogram actually do something

    Java Code:
    if (info[1].equals("Student")){
               // do things for student
               // add code for studenti here
         } else if (info[1].equals("Tutor")){
               // do things for tutor
               // add code for tutor here
         }
    2) in your LoginHandler there are some things you should correct

    why you create a ProjectRec and then you don't use it.....choose.....use it or remove that thing

    Java Code:
    //create Project object
    ProjectRec p = new ProjectRec("0811111A", "Date", "Student");
    why do you create another controller in LoginHandler.... I already explained you that you should have only one controller because you want to use only one container of all your data on users

    so the solution for this is to remove the line in LoginHandler

    Java Code:
    ProjectController controller = new ProjectController();
    and create a constructor in LoginHandler where you can pass the controller created in Project constructor to the loginHandler (like a parameter) when you create it

    so now we should have this also in the loginHandler

    Java Code:
    class LoginHandler implements ActionListener
    {
        
        private ProjectController controller = null;
    
        public LoginHandler(ProjectController c){
            controller = c;
        }
    
        public void actionPerformed(ActionEvent evt)
        { //.... this is written }
    }
    and in the Project constructor when you create the LoginHandler it should look like this:

    Java Code:
    btn1.addActionListener(new LoginHandler(controller));

  5. #25
    Winniee is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    Hi wolf. thanks for e help again. I'm kinda confused with the declaration in the Datastorage & controller.

    could you help me with this coding please? Thanks so much. =)
    Java Code:
    if (info[1].equals("Student")){
               // do things for student
               // add code for studenti here
         } else if (info[1].equals("Tutor")){
               // do things for tutor
               // add code for tutor here
         }

  6. #26
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    well i can't help you because i don't know what you wanna do with students or with tutors....
    that is a part you don't have error on....so you should write it yourself and learn hehe ;)

  7. #27
    Winniee is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    This is where i differentiate between Students & tutor's login right ? :)

  8. #28
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    yes and there you should write your specific logic for each type

  9. #29
    Winniee is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    thanks wolf!

    just one more question.. i'm not sure on how to create a JTextArea.

  10. #30
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    JTextArea area = new JTextArea()

    I don't see any difficulties.....
    after that you add it to the desired container (Panel, Popup, Frame.....what you got there)

  11. #31
    Winniee is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    okay thanks for ur help man! Any problems shall consult you again. =) Thanks for ur time all these while. ^_^

  12. #32
    Winniee is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    Hello wolf. I got a question..

    Java Code:
    String [] userName = {"0811111A","0822222B","08333333C", "tutor"};//for the list of predetermined users
    	String [] userPassword = {"p1", "p2","p3","123"};//for the list of predetermined users
    	String [] userType = {"Student", "Tutor"};//for checking user type
    for this code. How do i define tutor = Tutor?? And 0811111A,0822222B,08333333C as Student??

  13. #33
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    you may want to create a class for this, maybe a class User with fields useName, userPassword and userType

  14. #34
    Winniee is offline Member
    Join Date
    Feb 2009
    Posts
    19
    Rep Power
    0

    Default

    Java Code:
    controller.createProjectRec(userName[i], userPassword[i], "Student");//insert data into controller
    	controller.createProjectRec("tutor", "123", "Tutor");
    Can anyone tell me what code should i type in for controller.createProjectRec("tutor", "123", "Tutor");[/CODE]
    to define that he's tutor?

  15. #35
    wolfcro is offline Member
    Join Date
    Feb 2009
    Location
    Italy
    Posts
    51
    Rep Power
    0

    Default

    in the method of the controller

    Java Code:
    createProjectRec(userName, userPassword, userType);
    you already define if the user is a student or a tutor with the userType parameter. You create a user and you say that his type is "Tutor". With that you already said that he's a tutor.... and you can check that after with the user type check

Page 2 of 2 FirstFirst 12

Similar Threads

  1. open existing project project ..
    By itaipee in forum Eclipse
    Replies: 1
    Last Post: 12-28-2008, 09:12 PM
  2. Help With Project!!!
    By jackhammer in forum New To Java
    Replies: 5
    Last Post: 12-04-2008, 06:10 AM
  3. Need Help With Project
    By maggie_2 in forum New To Java
    Replies: 1
    Last Post: 12-02-2008, 09:24 AM
  4. First Project Need Big Help
    By earl in forum New To Java
    Replies: 1
    Last Post: 01-18-2008, 07:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •