|(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"
h05: HFJ 12: Intro to Java GUIs
|true||Mon 10/03 12:30PM||Mon 10/10 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: Read along with the online reading notes that go with those chapters. Then, do the problems below. Refer back to previous chapters as needed.
- (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.
(5 pts) What is the name of the Java class for an object that represents a window on the screen?
- (10 pts) What are two examples of Java classes that are considered "widgets"?
- What is the "job" of each of these objects in terms of handling an event in Java GUI programming?
(5 pts) listener object (the one that
(5 pts) event source object
(5 pts) The author explains that each specific instance of an inner class instance has a “special bond” with a specific instance of an outer class instance.’
Explain what this author means by this “special bond”. (What I’m looking for is: what does the special bond allow the the inner class instance to do that other objects lacking this bond ‘‘cannot’’ do?)
(5 pts) Briefly explain: how does this “Special Bond” property of inner class objects make them particularly useful for implementing an ActionListener for a Widget?
(10 pts) The text says: “If you want to put your own graphics on the screen, your best bet is to make your own paintable widget.” The book recommends that to do this, you should: (fill in the blanks):
Make a of
JPanel, and override one method:
- Now, several questions about this "mysterious method", i.e. the answer to the 2nd blank in the previous question. (The method you override.)
(10 pts) The book says that you write code to go inside this mysterious method when you override it. What kind of code do you write inside this mystery method? (Note: pp. 363-368 have lots of examples.)
(5 pts) The book says that you never call this mysterious method yourself—and the reason is that the parameter to that method is something you don’t have direct access to. What kind of
Objectthat is the parameter to the mysterious method, that the System has access to, but you as a programmer don’t?
(5 pts) Though you can’t call the mysterious method directly, there is a method that you can call that asks the system to call that method for you. What is the name of this method that you can call?
(10 pts) Inside this mysterious method, one often finds this mysterious line of code. Explain WHAT this line of code is doing, and more importantly, why that may be needed or helpful (must explain both what it does, and why that is needed/helpful for full credit.)
Graphics2D g2d = (Graphics2D) g;
(10 pts) Write the code for a
paintComponentmethod that fills a square of a random color on the screen, with side length 100, and CENTERED at 50,200. (Hint: You’ll need to look up the parameters to
fillRectin the Java API online.)