Results 1 to 6 of 6
Thread: Urgent Help!!
- 02-16-2009, 02:33 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 19
- Rep Power
- 0
Urgent Help!!
Hi, May i know what this sentence means.=>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(); } }
private ProjectController controller = null;
- 02-16-2009, 02:42 PM #2
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.
- 02-16-2009, 02:44 PM #3
Senior Member
- Join Date
- Jun 2008
- Posts
- 2,366
- Rep Power
- 7
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.
- 02-16-2009, 04:37 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I wonder that, if our thread starter don't know what that line means, how did he/she write that code. ;)
- 02-16-2009, 05:03 PM #5
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.
- 02-17-2009, 03:32 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
May be he's try to have an idea about the code. But this is not the way, and still no any comments too.
Similar Threads
-
Urgent help
By tiger100plus in forum New To JavaReplies: 3Last Post: 12-09-2008, 05:10 AM -
Very urgent, do the help.
By jyotigupta6 in forum Threads and SynchronizationReplies: 1Last Post: 11-18-2008, 12:30 AM -
Help. It's urgent
By monir6464 in forum AWT / SwingReplies: 2Last Post: 08-24-2008, 05:57 PM -
Hi, need some urgent help!
By jdark in forum New To JavaReplies: 2Last Post: 04-18-2008, 06:50 AM -
Help me ...urgent!
By googgoo in forum New To JavaReplies: 7Last Post: 04-05-2008, 08:46 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks