Homework 4

This homework is meant to give you practice with selecting appropriate widgets for a problem and with selecting and using Java layout managers.


  1. For each of the following questions answer true or false:

    1. __________ Experts tend to rely more heavily on recognition memory.

    2. __________ Menus should be designed so that they contain many items, thus minimizing the number of required levels in a menu hierarchy

    3. __________ You can use a flow layout manager to vertically stack widgets.

    4. __________ In a grid layout manager, all columns will have the same width and all rows will have the same height.

    5. __________ Sliders are useful for entering bounded, continuous data, such as real numbers.

    6. __________ Check boxes allow you to enter a set of mutually exclusive choices.

  2. Each of the following questions asks 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. You should select each answer from the following list of widgets:

    1. ________________ You want the user to enter a credit card number

    2. ________________ You want the user to select a university status from the choices of Professor, Student, Administrator, and Secretary. A user is allowed to selecct multiple status's.

    3. ________________ You want the user to select an FM radio station in an internet radio application.

    4. ________________ You want the user to select their county of residence in Tennessee

    5. ________________ You want the user to enter the volume of a speaker that should ranger between 0 and 20.

  3. The following code uses the Box component, which is a Java container that implements the Box layout manager. Sketch a picture of the window layout that will be created by this code. You may assume that the buttons are JButtons whose labels are the same as the variable names representing the buttons. You may draw the buttons as rectangles with their respective labels.

    	Box b1 = Box.createVerticalBox();
    	Box b2 = Box.createHorizontalBox();
    
    	b1.add(button1);
    	b1.add(Box.createRigidArea(new Dimension(0,5));
    	b1.add(button2);
    	b1.add(Box.createRigidArea(new Dimension(0,5));
    	b1.add(button3);
    
    	b2.add(b1);
    	b2.add(Box.createHorizontalGlue());
    	b2.add(button4);
    
    	getContentPane().add(b2);
    	

  4. I have created a layout program that mimics part of the flight dialog box used by Travelocity's search engine. Try copying /home/bvz/gui/hw/hw4/travelocity.class to your directory and then typing:
      java travelocity
      
    Play with the application by resizing the window to see how the layout changes.

    Your assignment for this problem is to complete the file named travelocity.java so that it mimics my layout. travelocity.java already declares and allocates all the widgets that you need. You simply need to add panels, boxes, and layout managers. You can find travelocity.java in /home/bvz/gui/hw/hw4.

    Hints:

    1. I used the GridBagLayout manager to group and handle the six items associated with Departure and Return (the two labels, the two textfields, and the two combo boxes). There is a 20 pixel separation between the combo boxes and the text fields.
    2. I used the GridLayout manager to handle the four items associated with the From and To textboxes (the two labels and the two textfields).
    3. I used a BorderLayout to position the Departure/Return and "Exact dates" groups with respect to one another.
    4. I used BoxLayouts everywhere else.