Java Reference
In-Depth Information
￿ for(int el: a) {
Will generate
ConcurrentModificationException because it is illegal to modify an array or an
ArrayList while there is an iterator (i.e., a for-each for loop) active on it.
... a.remove( ... ) ...
}⇒
11.10 Important Points
1. Before starting to write a big software system, we should always create a preliminary
design of our classes.
2. This design will change with time. New features will be added and existing features
will change. This is part of the development process.
3. Start by creating a small program and test it. Next, add new features incrementally
and always make sure that the current code is working before extending it.
4. When creating a class, start with the data. Build the methods around the data.
Remember that every class has the responsibility to provide public interface to its
data. The methods in every class should be simple and provide a single function. Break
down long methods by creating private methods that perform part of the required
work. Creating private constructors can be part of this process.
11.11 Exercises
1. The JColorChooser class can be used to get a color from the user. Change the game
Breakout and add a menu item option that allows the user to enter his or her own
color. Read the JavaDoc for the class to find more information on how to use it.
2. Create a simple program with a menu that can be used to change the background
color of the panel. Use the setBackground method to change the color of the panel.
Allow the color of the panel to also be changed using accelerator keys. For example,
Ctrl+B should change the color to blue.
3. Modify the game so that the ball changes trajectory more randomly after hitting an
object. You can achieve this by allowing the variables dx and dy of the Ball class
to take values other than 1 and
1. You may even define them as doubles and use a
function of the value that is returned by Math.random to set their new values.
4. Modify the game so the bricks fill the whole top of the window and the small gap in
the right part of the window is removed.
5. Add code that allows the player to start/pause the game by pressing the right mouse
button.
 
Search WWH ::




Custom Search