Results 1 to 6 of 6

Thread: Urgent Help!!

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

    Default Urgent Help!!

    Java Code:
    /**
     * @(#)Project.java
     *
     *
     * Han Wei'An 0800680A
     * @version 1.00 2009/1/13
     */
    
    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,TutorPanel;	
    	JButton btn1,btn2;
    	JTextField tfUser;
    	JPasswordField tfPass;
    	JLabel lblUser, lblPass;
    	JTextArea area = new JTextArea();
    	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    	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
    	private ProjectController controller;
    	
    	
        public Project() {
        setTitle("Student Attendence System");
       	setSize(300,150);
       	setResizable(false);
       	setLayout(new BorderLayout());
       	
       	area = new JTextArea(5,5);
        area.setEditable(true);
        JScrollPane scrollPane = new JScrollPane(area);
        
     	
    	ProjectController controller = new ProjectController();
    	for (int i=0;i<3;i++){
      	controller.createProjectRec(userName[i], userPassword[i], "Student");//insert data into controller
    	}
    	{	
    	controller.createProjectRec("tutor", "123", "Tutor");
    	}
       	pNorth = new JPanel();
       	pSouth = new JPanel();
       	TutorPanel = 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(controller));
        btn2.addActionListener(new ClearHandler());
        
       	pNorth.add(lblUser);
       	pNorth.add(tfUser);
       	pNorth.add(lblPass);
       	pNorth.add(tfPass);
       	pSouth.add(btn1);
        pSouth.add(btn2);
        TutorPanel.add(area);
          
        add(pNorth, "Center");
        add(pSouth, "South");
        setVisible(true);
        }
        class LoginHandler implements ActionListener
        {
        	private ProjectController controller = null;
    
       		public LoginHandler(ProjectController c){
            
            controller = c;
       		}
        public void actionPerformed(ActionEvent evt)
        {
        	
         String User = tfUser.getText();
         String pass = "";
        
         try{ pass = tfPass.getText();}
         catch(Exception ex){
       
         }
         if (checkPassword(User,pass)){
    
         Date date = new Date();
         String datetime = dateFormat.format(date);  
         String[] info = controller.getProjectInfo(User);//check the type
         String loginShow = "Student ID: "+User +" Login at "+datetime;
         JOptionPane.showMessageDialog(null, loginShow , "Message", JOptionPane.PLAIN_MESSAGE);
         	
         if (info[1].equals("Student")){
         
         controller.createProjectRec(User, pass, "Student");//insert data into controller
         
         }  else if (info[1].equals("Tutor")) {
    		String[] abc = controller.getProjectInfo(User);
    		
    		
    		area.append(abc[0] + " " + abc[2]);
    		JFrame jf = new JFrame();
    		jf.add(TutorPanel);
    		jf.setSize(300,150);
    		jf.setVisible(true);
    	
         }
    	} 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();
        }  
    }
    Hi, May i know what this sentence means.=>
    private ProjectController controller = null;

  2. #2
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    1. Use an appropriate title please, urgent help will make people less inclined to help, not more.
    2. Only post the code that is giving an error, or atleast isolate it so we don't have to look through it all.
    3. Be more specific with what you want. No specific question asked, no specific answers given.

    What do you mean? I mean you wrote it didn't you? It means your declaring a new ProjectController and initialising it as null, so basically not initializing it. It would be the exact same thing if you just declared it, and left out the ' = null', so like masijade posted, assigning null is redundant and not necessary.
    I really don't see how this is urgent..
    Last edited by MK12; 02-16-2009 at 02:52 PM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  3. #3
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    It is a declaration, of course.

    The " = null" is redundant, as any class/instance variable that is not explicitly defined at declaration will get a default value, which for non-primitives, is null.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    I wonder that, if our thread starter don't know what that line means, how did he/she write that code. ;)

  5. #5
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Yeah that was what I was thinking too.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Urgent help
    By tiger100plus in forum New To Java
    Replies: 3
    Last Post: 12-09-2008, 05:10 AM
  2. Very urgent, do the help.
    By jyotigupta6 in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-18-2008, 12:30 AM
  3. Help. It's urgent
    By monir6464 in forum AWT / Swing
    Replies: 2
    Last Post: 08-24-2008, 05:57 PM
  4. Hi, need some urgent help!
    By jdark in forum New To Java
    Replies: 2
    Last Post: 04-18-2008, 06:50 AM
  5. Help me ...urgent!
    By googgoo in forum New To Java
    Replies: 7
    Last Post: 04-05-2008, 08:46 AM

Posting Permissions

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