| DESC 391 Assignments Fall 2009 - Assignment 4: GUI programming |
|
|
| Written by Chitu Okoli and Bilal Abdul Kader | |||||||
| Friday, 19 September 2008 11:35 | |||||||
Page 5 of 5
Assignment 4: GUI programmingDue: Early submission is 11:59 pm on Monday December 7 (if you submit on this date, you will receive your results before the final exam) The purpose of this assignment is for you to begin developping GUI applications in Java. You must use a text editor to do this assignment; you must hand-code everything. You are NOT permitted to use a GUI generator that automatically creates windows for you. There are two exercises.
1. Accumulate test scores (4%)
Operation· The user enters test scores one at a time and then clicks the Enter Score button. · For each entered score, the application adds one to the number of scores, calculates the average score, and determines what the best score is so far. Then, it displays the number of scores, average score, and best score in the three disabled text fields. Note that although the screen does not show the total score, your application will need to store the running total in order to calculate the average properly. · The user can click the Clear button to reset everything to zero. · When the user closes the frame or clicks the Close button, the application exits. Specifications· The average score is the sum of all scores divided by the number of scores. · Assume valid data is entered. However, you may validate the data for extra credit (see below). · If you have trouble getting the labels and text fields to line up properly, try adjusting the frame size. When you use the FlowLayout manager, the width of the frame affects how components you add to the frame are lined up. Extra credit· Make sure that you have the application fully working before you try for extra credit! · For 0.5% extra credit, validate the test score to permit only a valid double value from 0 to 100. You may use the validation classes from chapter 17 (remember to cite your sources properly). 2. Enter a team lineup (8%)
Console outputRage 12U (home team) H. Perkins, Center Field C. Cousins, Pitcher J. Johnson, Catcher B. Lowe, First Base A. Licouris, Left Field N. Shrey, Short Stop S. Palmore, Third Base C. Giess, Second Base A. Nieto, Right Field Operation· This application lets the user enter the batting lineup for a baseball or softball team. · The user can enter a team name and use the radio buttons to select whether the team is the home team or the visiting team. · For each player, the user enters the player’s name in the text field and selects the player’s position from the combo box. · When the user clicks OK, the application displays the team roster on the console as shown in the console output. The order is the same order as entered by the user. Specifications· The team positions in the combo boxes should offer the following choices: Choose a selection · Don’t worry about validating the user’s input--even a blank field is OK. However, you may validate the data for extra credit (see below). · You may use the BorderLayout and/or the FlowLayout to control the positioning of the labels, text fields, combo boxes, and buttons. However, for extra credit, you may use the GridBagLayout (see below). · Hint: Consider simplifying the solution by creating a private method that adds a label, text field, and combo box to the panel. Another option is to declare an array of text fields and an array of combo boxes rather than declaring separate controls for each player. Extra credit· Make sure that you have the application fully working before you try for extra credit! · For 1% extra credit, use the Grid Bag layout to control the positioning of the labels, text fields, combo boxes, and buttons. However, you probably need to decide from the beginning whether to use the BorderLayout and/or FlowLayout, or whether to use the GridBagLayout. While you would get extra credit for GridBagLayout, it is harder to use, and more risky. If you're not sure you're up to the challenge, then complete the application using the simplyer layout options, and then try one of the other extra credit opportunities. · For 0.5% extra credit, validate the combo box selections so that the user can’t select the same position for two or more players. If the user attempts to set a combo box to a selection that’s already been assigned to a player, the combo box should immediately revert to “Choose a position.” Refer to chapter 17 for validation techniques for GUI programming. · For 1% extra credit, instead of printing results to a console, print results to a new frame which displays the results in a text area, and that has only one button "Close" to close the frame. However, for this output frame, the close button only closes that frame; it does not exit the entire application.
SubmissionTo submit the assignment, do the following:
|
|||||||
| Last Updated on Tuesday, 08 December 2009 11:16 |