This program is meant to give you practice with a Java Swing graphical user interface (GUI), in the form of a university student database/registrar program. You will load a file with student information and meet the following requirements:
• the GUI look and feel is up to you
• student information will be loaded into a List of Student objects (displayed however you wish)
• the student List must be sorted after it is loaded
• provide a way to traverse through the List of students displaying each student’s information
• support the ability to find/search a particular student by ID using a HashMap
• keep track of the previously searched or selected students with a Stack
• support the ability to step through those previous selections
See the Example Output for our implementation of this assignment including a video. Your implementation does not have to look like this at all; it only needs to support the functionality requested in this assignment.
Here is the link to the GitHub Classroom assignment: https://classroom.github.com/a/uwFg1zPT
(a) JFrame, Main, Utility
Your main class should extend JFrame so that your program is inherently a Java Swing window. A Main.java source file has been provided that you are welcome to use as a starting point (though not required). The file already contains variables for the default location of a res/students.csv input file (also provided). It also has variables for loading some avatar images, if interested (not required). The minimum student information is already provided in the student test file. You must support the information provided, however you can add more student information if you desire. A Utility.java file has been provided that you may use. It can be executed (it has a main() function) to produce another students.csv file if desired. You may edit the generation function if you would like to provide more information per student.
(b) Swing GUI
Use your knowledge of Swing, examples from class or a previous class, or tutorials online, to help you create a GUI that you are happy with and that supports the requested functionality. Start simple and build up. First test the basic functionality of the window/frame itself. Then add more components to any layout you prefer and test them individually. It is possible to test all visual components of this program without even loading the student information. There are many step-by-step tutorials on the Internet on how to build a GUI with Swing. Please use some of them if you have no idea how to build a Java Swing GUI program.
Rely on your knowledge of text file reading to load a student test file. We have loaded text files in this class so there are examples you can draw on. This video also explains how to do so. In addition to reading each line of the file, you should use a StringTokenizer to separate each token of each line using a comma (“,”) as a delimiter. You may use the res/students.csv input file we have provided, or generate your own. You will notice that the first line contains the number of students in the file. This is useful if you want to implement a JProgressBar to indicate how far along your program is when loading the file. We will test your program with various files of the same format. All information already provided per student must be supported (in the provided order), however, you may add additional information at the end of each student line if desired.
When loading the student data, you will notice one of the fields is a date. You can (and should) use the java.time.LocalDate class to work with dates, both parsing and creating them. You can parse the date string provided in the students.csv like so:
LocalDate date = LocalDate.parse("2020-09-15"); // loading a date JLabel lblExample = new JLabel(date.toString()); // date as string
Loading a file of 1-20,000 students may not take long at all, depending on the speed of your computer. Nevertheless, modern programs utilize separate threads of execution to keep GUI responsive. If interested, we suggest using a SwingWorker class and the example provided in the documentation. We have also provided you with a working example through class. This class helps marshall information back and forth between the Swing GUI thread (where all your components are), and a “worker” background thread (where time intensive code can be executed). Although there is a learning curve associated with using SwingWorker for the first time, you will see that it is very powerful and useful. Any type or amount of data can be passed to it and it can report back progress to any class that listens for its events. If after implementing a SwingWorker task on a separate thread, your loading routine is still too fast even with large student files, you can artificially slow your loading routine down with a call to Thread.sleep() somewhere in the loading loop. This is not something you would ever want to do on a professional program, but you could do it in this circumstance if you wanted to demonstrate that your JProgressBar actually works properly.
(d) Previous Stack
Your final requirement involves keeping track of the previously selected and searched Student objects. You are required to use the java.util.Stack class to do this. As the user visits each Student, either by selecting them within a JList or using a search JTextField or any other method you provide, that Student object should be pushed onto a Stack object. And then you must support some way of traversing backwards through those Student objects and popping them from the Stack one by one. When the Stack is empty, the user shouldn’t be able to go back any further. This functionality is very relevant to modern software programs in the form of an undo history.
Your program may look different than this.
Here is a screenshot during threaded loading (w/ progress bar).
Here is an example of using the Utility class to generate a new student test file.
This shows a particular student’s information selected in the GUI.
This assignment has been answered 4 times in private sessions.
© 2023 Codify Tutor. All rights reserved