• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to make a new GUI window display user details after that user has logged in the system?  RSS feed

 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a login window which asks for the user's username and password. The user can either be a student or an admin for each there is a table in the database. After the student has logged in the system, a new GUI window should open displaying his account details.

Attached are the 3 tables I have in my database and the GUI that opens when a student has logged in(though this is faulty).

For the login, I did the following and it works:




I can't figure out how to make the subsequent GUI window display the details specific to that user after the user authentication. When a student has logged in successfully, a GUI window displays details of the student (from the database) but it does not show the details of the student who has logged in but the last student entered in the database. I have attached a screenshot of the GUI window.

Here are the codes for it:



 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to attach images here :/

Can anyone please tell how I can attach the images?
Screenshot-(82).png
[Thumbnail for Screenshot-(82).png]
Student Details table
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Attached are the corresponding tables and GUI after the student has logged in.
Screenshot-(83).png
[Thumbnail for Screenshot-(83).png]
admin table
Screenshot-(84).png
[Thumbnail for Screenshot-(84).png]
student table
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GUI after student has logged in successfully:
Screenshot-(85).png
[Thumbnail for Screenshot-(85).png]
 
Campbell Ritchie
Sheriff
Posts: 54065
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am moving you to our databases and GUIs fora.

Don't put GUI code and database connectivity in the same place; they shou‍ld be in different classes. Separate the two components: make a GUI without any database connections and later connect the database to the GUI. For a popup, don't use a frame, and don't use EXIT_ON_CLOSE. Use a dialogue instead. Find about Ca Horstmann's GBC class instead of GridBagConstraints. Much easier to use. Don't try adding things to a frame from an action listener. Make the display with all its components, and change their state later on.

Get your database connectivity working at the command line before you try creating a GUI. Get it to print all the results before you try displaying them.
 
Campbell Ritchie
Sheriff
Posts: 54065
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am surprised you can't add images; there is an “Img” button which embeds images, but only if the have a URL to go with them. There is an attachments tag below. Beware of images; text is often more useful.
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@CampbellRitchie Yes, I used the "img" button but it requires a URL. I used the attachments for the post but the images did not appear.
 
Campbell Ritchie
Sheriff
Posts: 54065
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can see the images. Don't know whether that has to do with different browsers, different access levels or what.
But, more important, what progress have you made with your programming?
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the images appeared when I posted them as a reply to the post but not when I posted them in the post. I am still learning Java, so I am trying to figure out how to make this work.
 
Dave Tolls
Ranch Hand
Posts: 2560
27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First a comment.
Don't check login details by reading out all the data from the user table and then comparing username and password.
Use a single query that filters on the given username and password.


Then, using a PreparedStatement, you can bind the given username and password to the '?' placeholders.

The use of two tables for logins is not the usual way for doing roles.  It's prone to errors.  Are you stuck with the table structure?  If not, you might want to consider a simple 'role' table instead, with 'Administrator' and 'Student', then just give your user a role.

Now, I see currently that you create a Student object (good move to have a proper model) in the Login action listener, but it doesn't seem to go anywhere.
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved it. The prob was not related to my SQL query codes but in the way in my GUI navigation codes.

Thanks for all the help!
 
Campbell Ritchie
Sheriff
Posts: 54065
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us your solution, and
...Well done correcting it
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would be pleased to share the answer but I just realized I have posted too much  unnecessary of codes here. It's pretty much of a "copy and paste" job that anyone can do if a similar school project is given. Can you please edit the second part of the codes to this one:

 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* This can lead to a "copy and paste" job that anyone can do if a similar school project is given.
 
Campbell Ritchie
Sheriff
Posts: 54065
130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am afraid it is too late to do any such editing; if there is a copy and paste job the plagiarism software will pick up the copying and your work will be visible as existing before the plagiarism and the person copying will get a nice 0.
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Coderanch should consider adding an edit or delete option for a post. I understand this is to preserve the integrity of a post but the solution for that could be the edit or delete can be verified or checked by moderators.
 
Sophia Green
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides, not all project works are run into a plagiarism software to verify its authenticity. At least not mine is.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!