CS 1713 Week 10:
- Using Wrapper Classes
- More practice with the ArrayList
- Learning to use Layouts
- Learning to use Listeners
Reading: 3.8, 4.8 - 4.9, 7.10 - 7.11
- Graphics Case Study 5: Using an ArrayList.
- Graphics Case Study 6: Designing with layouts
You can practice tracing selection and insertion sorts
using the sorttrace project
Find the notes on wrapper classes
Find the notes on ArrayLists
Graphics Case Study 5: Using an ArrayList
In this case study we will convert Graphics Case Study 4 to one using an
ArrayList instead of an array.
Start with a copy of Graphics Case Study 4.
Change the project to gcs05 and change the package name to
In this case student we used an array to hold the list of shapes.
As new shapes were added, we kept track of how many shapes were stored
in the array, and made the array bigger as needed.
In this case study we will use an ArrayList instead.
We no longer need to keep track of the number of shapes since the
ArrayList does this for us.
Find the notes on layouts
Graphics Case Study 6
In Graphics Case Study 5, the buttons were contained in the main panel
using a FlowLayout. We would like to isolate the buttons so
that they are in their own panel, distinct from the panel that we draw into.
Copy Graphics Case Study 5 into gcs06 and change the package name
Modify this so that the buttons are on a separate panel that does
not overlap with the drawn shapes.
- The simplest solution is to make a panel inside of the drawing panel
that contains the buttons.
- Alternatively the buttons and the drawing panel can be separate objects.
- In this latter case, we need to have a way for the two panels to
3 ways to implement an ActionListener:
- Have the class continaing the Widget implement ActionListener
- Make a separate public class that extends ActionListener
- Make an inner class that extends ActionListener