GUI Midterm

  1. This exam is open-note, open book. You may not use a computer or any electronic devices.
  2. You must answer all of the questions.
  3. Use the exam pages to answer the questions
  4. You must use Java to implement the coding questions.
  5. Good luck!

  1. (20 points) Answer true or false for the following questions:

    1. __________ A JPanel is what you would typically create if you want to create a canvas for drawing custom graphics.

    2. __________ The (x,y) point at which Java starts drawing a text string is called the baseline.

    3. __________ The RGB model is a subtractive/reflective color model.

    4. __________ If your class implements a listener interface it only has to implement those methods which it cares about (i.e., are not empty).

    5. __________ You can cause a box layout manager to put different sized horizontal gaps between its elements.

    6. __________ A grid layout manager does not respect an object's preferred size.

    7. __________ Sans-serif fonts do not have decorations or curls.

    8. __________ Dark objects are more effective at drawing the user's attention than light objects.

    9. __________ The human eye is an order of magnitude better at perceiving the contrast between the hues of two objects, than the brightness of two objects

    10. __________ Menus should be used to list the set of available commands when screen space is at a premium.

  2. (20 points) Each of the following questions will ask you to collect some type of data or provide some type of operation to the user. For each question, select the most appropriate widget to use for that question. You may justify your answer if you wish but it is not necessary. If you do so limit yourself to no more than 2 sentences. You should select each answer from the following list of widgets:

    1. ________________ You want to put a sequence of possible actions at the bottom of a dialog box, such as "Save", "Cancel", "Delete". These actions will be immediately executed when selected by the user.

    2. ________________ You want to assign a grade of 0-20 to a student's solution.

    3. ________________ You want the user to select the items they want included in a cable package, which can include internet, video, and telephone service. The choices are not mutually exclusive.

    4. ________________ You want to allow the user to select a tool from a tool pallette. Nothing executes when the tool is selected. Instead, you may now use the tool in an editor window.

    5. ________________ You want the user to select a city from a list of cities for the state in which they live. The number of cities from which to select will typically exceed 10.

  3. (12 points) Which Java layout manager is the best and simplest choice for each of the following situations. Please limit yourself to the following five layout managers:

    1. _________________ You want to create a tool pallette with equal sized chips for each of the tools.

    2. _________________ You want to lay out a set of command buttons horizontally at their natural size, with a gap of 10 pixels between buttons. There are no other alignment or justification conditions.

    3. _________________ You want to lay out the elements of a form

    4. _________________ You want to lay out 5 check boxes by vertically stacking them. They should maintain their preferred size, no matter how big the window gets.

  4. (18 points) Fill in the blanks for each of the following questions:

    1. ________________ pattern. This design pattern is being used when 1) views register with a model and the model notifies views of changes to its state information, 2) listeners register with an event generator and the event generator notifies the listeners as it produces events:

    2. _________________ updates. If the user wants to drag an object across the screen, experiments have shown that this number of updates per second is the lower bound for acceptable interaction.

    3. __________________. You would use this type of object in a box layout manager to create elastic space between two objects.

    4. If you want a Java component to listen for key presses you must 1) add a

      ________________ listener to the component, and 2) you must use the

      _________________ method in a mouse listener to request the focus.

    5. ___________________ This portion of a graphical application handles the graphical presentation of the model's data.

    6. ____________________ This element of a border layout manager gets all the space not assigned to the other elements.

    7. _________________ This type of font should be used to display text items on a computer display.

    8. _________________ objects. In object-oriented languages that do not have function pointers, such as Java, these types of objects are created explicitly to encapsulate callback functions.

    9. ________________ to _______________ items is ideally the upper limit on the number of choices you would want to provide for button groups or sections of a menu, since if you observe this limit, most users can spot the choices they want instantly (i.e., in O(1) time). If your button groups have more than this number of choices, users will be forced to scan the list of choices and their reaction time will degrade to O(n), where n is the number of items in your button group.

  5. (15 points) You are given the following declarations for the properties of a rectangle and its label:
    	Rectangle rect;
    	String label;
    	
    Write a paintComponent method that accomplishes the following tasks:
    1. Draws the rectangle as a blue rectangle with a black boundary.
    2. Draws the label 10 pixels beneath the rectangle and horizontally centered with respect to the rectangle. The top of the text string should be 10 pixels beneath the rectangle.

  6. (15 points): Write a piece of code to:

    1. count the number of times a mouse enters the above rectangle. The mouse must leave the rectangle and then re-enter it for it to be counted as another entry (hint: you will need to write a listener object that listens for MouseMotion events).
    2. adds the listener object you just created to the JPanel that contains the rectangle.

    Here is some code to provide you context:

    	class Counter extends JPanel {
    	    Rectangle rect;
    	    String label;
    	    // you may need to declare additional instance variables here
    
    
    
    
    
                public Counter(Rectangle r, String l) {
    	       rect = r;
    	       label = l;
    	       // put your counting code here