import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
/**
* Main program for MVC Account example,
* based on example in chapter 3 of Deitel, Deitel, and Santry
*
* Ignore compiler message "Some input files use or override a deprecated API."
* (will discuss in class)
*/
public class Main {
public static void main (String [] args) {
java.awt.EventQueue.invokeLater (new Runnable() {
public void run() {
new Main ();
}
});
}
public Main () {
// Window setup
JFrame frame = new JFrame();
frame.setSize (465, 500);
frame.setLayout (new GridLayout (0, 1, 30, 30));
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
/*
* Create M, V, C for first account
* all in their own JPanel
*/
String acctname = "Checking";
JPanel p1 = new JPanel (); //*2 Create controllers
p1.setBorder (new TitledBorder (acctname));
Model m1 = new Model (acctname, 100); //*1 Create model
p1.add (new Controller (m1)); //*2
// Put the 2 Views in their own JPanel
JPanel vp1 = new JPanel (); //*3 Create two views and put in a panel
vp1.setLayout (new GridLayout (0, 1, 10, 10)); //*3
vp1.add (new TextView (m1)); //*3
vp1.add (new GraphView (m1)); //*3
p1.add (vp1);
frame.add (p1);
/*
* Ditto, second account
*/
acctname = "Savings";
JPanel p2 = new JPanel ();
p2.setBorder (new TitledBorder (acctname));
Model m2 = new Model (acctname, 1000); //*1
p2.add (new Controller (m2)); //*2
// Put the 2 Views in their own JPanel
JPanel vp2 = new JPanel ();
vp2.setLayout (new GridLayout (0, 1, 10, 10));
vp2.add (new TextView (m2)); //*3
vp2.add (new GraphView (m2)); //*3
p2.add (vp2);
frame.add (p2);
frame.setVisible (true);
}
}