943,926 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 6733
  • Java RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Mar 27th, 2007
0

Re: Creating Login

I understand I somehow have to store Username and Picture to a file? But then how will I be able to call the file in the login screen?

Do I need 3 Arraylists? One for user one for picture one for ID or can I just have one for ID that stores the relation with the picture and username
Reputation Points: 10
Solved Threads: 0
Light Poster
eeeman is offline Offline
27 posts
since Mar 2007
Mar 27th, 2007
0

Re: Creating Login

java Syntax (Toggle Plain Text)
  1.  
  2. public class AccountInfo {
  3. //private String userName;
  4. private int pictureInput;
  5. private int userID;
  6. private GUI gui;
  7. private ArrayList userName;
  8. private ArrayList password;
  9.  
  10. public AccountInfo()
  11. {
  12. gui = new GUI();
  13. userName = new ArrayList();
  14. password = new ArrayList();
  15. }
  16. public void setUsername()
  17. {
  18. userName.add(gui.getName());
  19. }
  20. public void setPassword()
  21. {
  22. password.add(gui.getName());
  23. }
  24. }

Heres my AccountInfo class
Reputation Points: 10
Solved Threads: 0
Light Poster
eeeman is offline Offline
27 posts
since Mar 2007
Mar 27th, 2007
0

Re: Creating Login

Heres some more of my improved Gui.
'
I still am struggling to do this all I gave picture id though.

java Syntax (Toggle Plain Text)
  1.  
  2. //createAccountBtn pressed
  3. createAccountBtn.addActionListener(new ActionListener(){
  4. public void actionPerformed(ActionEvent e) {
  5. userName = userNameInput.getText();
  6. userID = userName + passWord;
  7. userBox.addItem(userName);
  8. }
  9. });
  10.  
  11. //accountPicture1 pressed
  12. accountPicture1.addActionListener(new ActionListener(){
  13. public void actionPerformed(ActionEvent e) {
  14. passWord = "1";
  15. }
  16. });
  17.  
  18. //accountPicture2 pressed
  19. accountPicture2.addActionListener(new ActionListener(){
  20. public void actionPerformed(ActionEvent e) {
  21. passWord = "2";
  22. }
  23. });
  24. //accountPicture3 pressed
  25. accountPicture3.addActionListener(new ActionListener(){
  26. public void actionPerformed(ActionEvent e) {
  27. passWord = "3";
  28. }
  29. });
  30. //accountPicture4 pressed
  31. accountPicture4.addActionListener(new ActionListener(){
  32. public void actionPerformed(ActionEvent e) {
  33. passWord = "4";
  34. }
  35. });
  36. //accountPicture5 pressed
  37. accountPicture5.addActionListener(new ActionListener(){
  38. public void actionPerformed(ActionEvent e) {
  39. passWord = "5";
  40. }
  41. });
  42.  
  43. //loginBtn pressed
  44. loginBtn.addActionListener(new ActionListener(){
  45. public void actionPerformed(ActionEvent e) {
  46. loginPanel.setVisible(false);
  47. workSpacePanel.setVisible(true);
  48. }
  49. });
Reputation Points: 10
Solved Threads: 0
Light Poster
eeeman is offline Offline
27 posts
since Mar 2007
Mar 27th, 2007
0

Re: Creating Login

Click to Expand / Collapse  Quote originally posted by eeeman ...
Wow is that coencidence that you both have avatars created by matt groening.

Ok, thnx for the replies aye. To be honest this doesnt even need security, all it really needs is different files stored for different userz.

I don't want to create a database so I like the flat txt file idea:-| .

Ill read through your comments and see if I can code this.
1. Great, just use java.util.Properties class and things would be even easier than C++. Store the data as "username=pictID" in file.
2. For storing the username vs. ID mapping use HashTable/Map.
3. The pictures: I don't know why you need to store any information abt them at all. See my previous posts. They're static info and can be just kept to the UI component. Don't de/serialize them.
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Mar 27th, 2007
0

Re: Creating Login

I really appreciate you helping me. I really got to research how to store stuff in files. Im reading documentation on properties at the moment.

So I should use store?

and then load to login?
Reputation Points: 10
Solved Threads: 0
Light Poster
eeeman is offline Offline
27 posts
since Mar 2007
Mar 27th, 2007
0

Re: Creating Login

Once your login page comes, the user would type a username in the control u're using for username, also he'll select/click the picture he wants, on this click you set passWord (as you've coded).
On click of the create account button you just add this username password combination to your HashMap object.
When you're exiting from the process, you serialize (write) the HashMap to a flat file using Properties class (just copy all data from HashMap to Properties class and use it's method to write to file).
At next startup of your process you'll have this process so in main() or somewhere during initialization you create Properties object using name of the the file to which you had serialized, Properties class will read all data.
Now you copy this data from Properties file to HashMap and you're back in business.
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Mar 27th, 2007
0

Re: Creating Login

Your AccountInfo class would not be required. HashMap that I refer to in my previous post is the one that'll hold username-password combination instead of AccountInfo.
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Mar 27th, 2007
0

Re: Creating Login

Wow you make it seem so easy. Just add Username and Password to hashmap aye.


java Syntax (Toggle Plain Text)
  1.  
  2. private HashMap userInformation;
  3.  
  4.  
  5. //createAccountBtn pressed
  6. createAccountBtn.addActionListener(new ActionListener(){
  7. public void actionPerformed(ActionEvent e) {
  8. userName = userNameInput.getText();
  9.  
  10.  
  11. //userNameInput.setText(userName);
  12.  
  13. userBox.addItem(userName);
  14.  
  15.  
  16. //AccountInfo.aUserID.add(UserID);
  17.  
  18. //userID = userName + passWord;
  19. //userIDs.add(userID);
  20.  
  21. userInformation.put(userName,passWord);
  22. //userName = null;
  23. //passWord = null;
  24.  
  25. }
  26. });

Thanks for you help once again. I don't thing you can explain it any simpler. I will make sure to listen to what you said but I right now I really gotta understand hashmaps better .
Reputation Points: 10
Solved Threads: 0
Light Poster
eeeman is offline Offline
27 posts
since Mar 2007
Mar 28th, 2007
0

Re: Creating Login

>> So I should use store?
>> and then load to login?
Yes.
Overall flow would be:
  • From main() you create your UI elements.
  • Add all actionListners().
  • Create the Properties object and call load() with name of the file that you used for storing the data (in last run).
  • Copy all data from this Properties object to a HashMap.
  • On click of one of the pictures you set the password variable (as you're doing).
  • On click of create account button, pickup the username/password and see if it's already existing in the HashMap. If yes, it's an error.
  • On click of Login button pickup the username/password and see if user name is already existing in the HashMap. If not it's an error, if yes see that password (ID) matches.
  • At the end before exiting from main(), copy all data from HashMap to a new Properties object and call store() with the file name.
Reputation Points: 254
Solved Threads: 74
Practically a Posting Shark
thekashyap is offline Offline
804 posts
since Feb 2007
Apr 3rd, 2007
0

Re: Creating Login

Java Syntax (Toggle Plain Text)
  1. public class User {
  2. private String userName;
  3. private String password;
  4. private String accountInfo;
  5.  
  6. public User()
  7. {
  8. //accountInfo = new ArrayList();
  9. }
  10. public void setPassword(String pass)
  11. {
  12. password = pass;
  13. }
  14. public void setUsername(String user)
  15. {
  16. userName = user;
  17. }
  18. public void setAccountInfo()
  19. {
  20. accountInfo = password + userName;
  21. }
  22.  
  23. public void saveAccountInfo()
  24. {
  25. try
  26. {
  27. File dir = new File("H:/SDI/MileStone3/" + userName);
  28. dir.mkdir();
  29. FileOutputStream fOut = new FileOutputStream("H:/SDI/MileStone3/" + userName + "/accountInfo.dat");
  30. ObjectOutputStream oOut = new ObjectOutputStream(fOut);
  31. oOut.writeObject(accountInfo);
  32. oOut.close();
  33. System.out.println("Account info saved");
  34. }
  35. catch(Exception e)
  36. {
  37. System.out.println("Error! High Scores not saved");
  38. e.printStackTrace();
  39. }
  40. }
  41. public void checkInfo()
  42. {
  43. /**
  44.   //attempt to restore the high scores
  45.   try
  46.   {
  47.   FileInputStream fIn = new FileInputStream("accountInfo.dat");
  48.   ObjectInputStream oIn = new ObjectInputStream(fIn);
  49.   accountInfo = (String) oIn.readObject();
  50.   System.out.println("High Scores restored successfully!");
  51.   oIn.close();
  52.   userName.compareTo(password);
  53.   }
  54.   catch(FileNotFoundException e)
  55.   {
  56.   System.out.println("No file found");
  57.   }
  58.   catch(ClassNotFoundException e)
  59.   {
  60.   System.out.println("Class not found!");
  61.   e.printStackTrace();
  62.   }
  63.   catch(IOException e)
  64.   {
  65.   System.out.println("IO Error!");
  66.   e.printStackTrace();
  67.   }
  68.  }
  69.  **/
  70. userName.compareTo(password);
  71.  
  72. }
  73.  
  74. }

Java Syntax (Toggle Plain Text)
  1. //GoCreateAccount button pressed
  2. goCreateAccount.addActionListener(new ActionListener(){
  3. public void actionPerformed(ActionEvent e) {
  4. createAccountPanel.setVisible(true);
  5. loginPanel.setVisible(false);
  6. }
  7. });
  8. //GoLogin button pressed
  9. goLogin.addActionListener(new ActionListener(){
  10. public void actionPerformed(ActionEvent e) {
  11. createAccountPanel.setVisible(false);
  12. loginPanel.setVisible(true);
  13. }
  14. });
  15.  
  16. //accountPicture1 pressed
  17. accountPicture1.addActionListener(new ActionListener(){
  18. public void actionPerformed(ActionEvent e) {
  19. info.setPassword("1");
  20.  
  21. }
  22. });
  23. //accountPicture2 pressed
  24. accountPicture2.addActionListener(new ActionListener(){
  25. public void actionPerformed(ActionEvent e) {
  26. info.setPassword("2");
  27. }
  28. });
  29. //accountPicture3 pressed
  30. accountPicture3.addActionListener(new ActionListener(){
  31. public void actionPerformed(ActionEvent e) {
  32. info.setPassword("3");
  33. }
  34. });
  35. //accountPicture4 pressed
  36. accountPicture4.addActionListener(new ActionListener(){
  37. public void actionPerformed(ActionEvent e) {
  38. info.setPassword("4");
  39. }
  40. });
  41. //accountPicture5 pressed
  42. accountPicture5.addActionListener(new ActionListener(){
  43. public void actionPerformed(ActionEvent e) {
  44. info.setPassword("5");
  45.  
  46. }
  47. });
  48. //loginBtn pressed
  49. loginBtn.addActionListener(new ActionListener(){
  50. public void actionPerformed(ActionEvent e) {
  51.  
  52. loginPanel.setVisible(false);
  53. workSpacePanel.setVisible(true);
  54. }
  55. });
  56.  
  57. //loginPicture1 pressed
  58. loginPicture1.addActionListener(new ActionListener(){
  59. public void actionPerformed(ActionEvent e) {
  60. info.setPassword("1");
  61.  
  62. }
  63. });
  64.  
  65. //loginPicture2 pressed
  66. loginPicture2.addActionListener(new ActionListener(){
  67. public void actionPerformed(ActionEvent e) {
  68. info.setPassword("2");
  69. }
  70. });
  71. //loginPicture3 pressed
  72. loginPicture3.addActionListener(new ActionListener(){
  73. public void actionPerformed(ActionEvent e) {
  74. info.setPassword("3");
  75. }
  76. });
  77. //loginPicture4 pressed
  78. loginPicture4.addActionListener(new ActionListener(){
  79. public void actionPerformed(ActionEvent e) {
  80. info.setPassword("4");
  81. }
  82. });
  83. //loginPicture5 pressed
  84. loginPicture5.addActionListener(new ActionListener(){
  85. public void actionPerformed(ActionEvent e)
  86. {
  87. info.setPassword("5");
  88. }
  89. });
  90.  
  91. //createAccountBtn pressed
  92. createAccountBtn.addActionListener(new ActionListener(){
  93. public void actionPerformed(ActionEvent e) {
  94. info.setUsername(userNameInput.getText());
  95. userBox.addItem(userNameInput.getText());
  96. info.setPassword(pass);
  97. info.setAccountInfo();
  98. info.saveAccountInfo();
  99. createAccountPanel.setVisible(false);
  100. loginPanel.setVisible(true);
  101. }
  102. });
  103.  
  104.  
  105. //loginBtn pressed
  106. loginBtn.addActionListener(new ActionListener(){
  107. public void actionPerformed(ActionEvent e) {
  108. pass = (String) userBox.getSelectedItem();
  109. info.setUsername(pass);
  110. info.checkInfo();
  111.  
  112. }
  113. });
  114.  
  115. //logoutBtn pressed
  116. logoutBtn.addActionListener(new ActionListener(){
  117. public void actionPerformed(ActionEvent e) {
  118.  
  119. loginPanel.setVisible(true);
  120. workSpacePanel.setVisible(false);
  121. }
  122. });
  123.  
  124.  
  125. }
  126. }
Reputation Points: 10
Solved Threads: 0
Light Poster
eeeman is offline Offline
27 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: help me please...............
Next Thread in Java Forum Timeline: creat a GUI solution





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC