|(as it would appear on official course roster)|
|Umail address:||@umail.ucsb.edu|| section
4pm, 5pm or 6pm
| Optional: name you wish to be called|
if different from name above.
| Optional: name of "homework buddy"|
(leaving this blank signifies "I worked alone"
h06: HFJ 12, 13: More on GUIs
|true||Mon 10/03 12:30PM||Wed 10/12 12:30PM|
You may collaborate on this homework with AT MOST one person, an optional "homework buddy".
MAY ONLY BE TURNED IN IN THE LECTURE/LAB LISTED ABOVE AS THE DUE DATE,
OR IF APPLICABLE, SUBMITTED ON GRADESCOPE. There is NO MAKEUP for missed assignments;
in place of that, we drop the three lowest scores (if you have zeros, those are the three lowest scores.)
Reading Assignment: Review and Read along with the online reading notes that go with those chapters. Then, do the problems below. Refer back to previous chapters as needed.
As you work through the exercises below, you might also need to consult the Javadoc for the Swing classes: http://docs.oracle.com/javase/8/docs/api/
During S11, the CS56 students were assigned to create homework questions from Chapter 13. All questions (except 1 and 2) on this assignment are based on questions they came up with. Later in the course, you may have an opportunity to do the same thing with one or more of the chapters in the book this quarter.
- (10 pts) Please fill in the information at the top of this homework sheet, including your name and umail address. Put the time your discussion section starts (4pm, 5pm or 6pm) in the space indicated (the one you are registered for—even if you usually attend a different one.) If the other two items apply, please fill them in as well. Please do this every single time you submit homework for this class.
(10 pts) Briefly explain one way to do animation (as explained in Chapter 12). Include a brief explanation of what you have to do to avoid “smearing”.
(10 pts) (Thanks to Mark O.) A student makes a JFrame with the code below. When the student runs the program, no GUI comes up. What line of code is missing?
JFrame frame = new JFrame(); frame.setSize(400, 400);
(10 pts) (Thanks to Steven L.) Briefly describe the most significant difference between a
JPanel. (Note: the words most signficant are important here. Focus on the fundamentals: what the objects are an abstraction of? Don’t focus on superficial differences in the API.)
(5 pts) Would you use a
JTextArea? Explain why.
(5 pts) To get the scrolling to work, what additional widgets would you need?
- (Thanks to Ethan V.) Suppose we want to create a new check box with the label "Show Instructions".
(5 pts) What code would you write to make a new check box with the label
Show Instructions(i.e. declare the variable and invoke the constructor).
(5 pts) Write code to “select” the check box you declared in part a.
(10 pts) Still with the check box declared in part a, write some code that will print a message on
- print `The Box is checked!` if the box is checked
- print `The Box is not checked!` if the box is unchecked.
(Thanks to Pedro L. and Ted R.) Read about the Border Layout Manager in Chapter 13, including all of the fine print on all of the pages! Note that there are two cases for the Border Layout Manager: the normal case and the special case when pack() is used—be sure you understand both. Then answer these questions:
(5 pts) In the normal case, which regions get their preferred width?
(5 pts) In the normal case, which regions get their preferred height?
(5 pts) In the normal case, how are the dimensions of the center component determined?
(5 pts) The special case is when the
pack()method is used. Describe what happens when the
pack()method is used.
(10 pts) Find the place in Chapter 13 where there is some sample code that uses the
pack()method (they might be in the part marked “optional”—it isn’t “optional” for this course.) Read through that code and the accompanying descriptions. Then, briefly describe why the pack method is needed in that particular circumstance. That is, why did the developer use the
pack()method, as opposed to not using the