Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS401 Lab 10: Using Simple Graphical Components Note 1: If you do not finish this in the first week, you can finish it between labs and demonstrate it to your TA at the beginning of your next lab (which will be the week AFTER Thanksgiving). Note 2: Quiz 2 will be given during this lab session Introduction and Background We have just started discussing Java graphical applications and event-driven programming.  In these applications the user interacts with the program via the use of a graphical interface -- for example a window with buttons and textfields and dialog boxes.  Most consumer-oriented computer applications have graphical interfaces, so it is a good idea to get some practice in designing and implementing these applications. The newest version of the Gaddis text (7th edition) focuses on JavaFX for developing GUIs.  Although there are merits to this approach, the previous approach (using Swing, in the text editions 1-6) fits better with our discussions of inheritance, polymorphism and interfaces, and thus we will focus on this approach.  If you have the latest version of the text you can get some more information on Swing at the link below: https://docs.oracle.com/javase/tutorial/uiswing/ There is also extensive information about Swing in the course notes and handouts. In Lab 7 you completed the implementation of a simple Movie DB program, which allowed the user to list movies, search for a movie and add a new movie to the DB.  The movies were loaded from a file and saved back to the file when the program terminated.  You will now convert this program into one with a graphical interface.  However the Movie class and MovieDB class will be IDENTICAL to those from Lab 7 (see files Movie.java and MovieDB.java). We are not changing the functionality of the DB, just the interface with the user. To make the lab more feasible and more consistent, I have already written all but the event handlers for the main functionality of the program.  Download this code and read it thoroughly (Lab10.java).  For this lab you must implement the ControlListener class (which is the ActionListener for the JButtons) so that the program functions in a good, reasonable way. Program The Lab10.java program that you download should compile and run as given to you (as long as you also downloaded the Movie.java and MovieDB.java files).  However, as given the buttons do nothing when clicked, because the actionPerformed() method of the ControlListener class contains no actual code.  Run the program and look at the interface, then implement the ControlListener class as specified below:  The functional aspects of the program should be as follows: The List Movies button.  This button should call the toString() method of the MoviesDB object (movies) and append the result to the JTextArea. The Add Movie button.  This button should prompt the user (via JOptionPane.showInputDialog() boxes) for all of the components of the new movie, then create the Movie object and add it to the MovieDB (movies) variable.  Finally, the new movie should be printed to the JTextArea to show the user that it has been added. The Find Movie button.  This button should prompt the user (via a JOptionPane.showInputDialg() box) for the name of the movie to be found.  It should then call the appropriate method in the MovieDB (movies) variable to search for the movie.  If the movie name is found, it should print out the movie info to the JTextArea; otherwise it should print out that it is not found. The Quit Program button.  The user should be asked to confirm the quit using a JOptionPane.showConfirmDialog() box.  If the confirmation is given, the MovieDB should be saved back to the file and the program will be terminated.   To terminate a Java graphical application, you can issue the statement System.exit(0);. For options 1-3 above you must update the JTextArea in your program.  This should be done in a nice way, so that only the data that is needed is shown and so that the JFrame is sized just enough to hold the data in the JTextArea (hint: pack()).  See the demonstration by the TA for how your program should work. Grading Demonstrate that your program works correctly to your TA by running it for him / her. There will be 4 raw points for this lab, broken down in the following way: List Movies – 1 point Add Movie – 1 point Find Movie – 1 point Quit – 1 point   Note that your program must work with the provided driver program in order to receive credit for these items.  The 4 raw points will be normalized to give this lab equal weight to the other labs in the CS 401 course.   Notes and Hints Read the Lab10.java code given to you VERY carefully before starting your own code.  Also read over the various handouts that were given on graphics and graphical components.  You should also look up some of the needed classes in the Java API (ex: JTextArea, JOptionPane) so you know what methods to call and what arguments they require.  JOptionPanes are also demonstrated in the handout Stringy.java (see Handouts page).  Think logically about what is supposed to happen in each situation and write the handler appropriately.