Java Reference
In-Depth Information
FIGURE 9.1:
The Breakout game.
On a side note, our initial code does not follow best practices. The Java manual recom-
mends that the code be rewritten as follows.
public class
Breakout
{
public static void
main(String [] args)
{
EventQueue . invokeLater (
new
Runnable ()
{
public void
run()
{
BreakoutFrame frame =
new
BreakoutFrame () ;
frame. setVisible(
true
);
}
}
);
}
}
The new code moves the creation of the window into the event dispatch thread. This
guarantees that the program will not stall because a component is slow to be displayed.
Although this code is recommended when writing commercial applications, it brings unnec-
essary complications for the novice programmer. For this reason, we will stick to the first