![]() |
![]() |
![]() |
![]() |
![]() |
|
Now, you add a movie instance variable to the
definition of the application class, thus installing a model. The
definition includes a wired-in Movie instance based on
On To Java!, the forthcoming movie version of this book.
import javax.swing.*;
import java.awt.event.*;
public class MovieApplication extends JFrame {
public static void main (String argv []) {
new MovieApplication("Movie Application");
}
// Declare instance variables:
private Meter meter;
private Movie movie;
// Define constructor
public MovieApplication(String title) {
super(title);
// Construct view instances:
meter = new Meter(0, 30);
// Construct model instances:
movie = new Movie (5, 5, 5, "On to Java");
// Connect views visually
getContentPane().add("Center", meter);
// Connect window listener, size and show
addWindowListener(new LocalWindowListener());
setSize(300, 100);
show();
}
// Define window adapter
private class LocalWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
System.exit(0); return;
}}}