Source of Main.java


  1: 
  2: package adapter;
  3: 
  4: import java.awt.Dimension;
  5: import java.awt.Toolkit;
  6: import java.util.*;
  7: import javax.swing.*; 
  8: 
  9: public class Main {
 10: 
 11:   static Student[] students = {
 12:     new Student("1001", "Bill", "Gates", 
 13:                 "1 Microsoft Way", "WA", "Redmond", "USA", "65432", 
 14:                 "555-123-4567", 3.9f, 32),
 15:     new Student("1002", "Steve", "Jobs", 
 16:                 "100 Next Drive", "CA", "Orchidville", "USA", "79910", 
 17:                 "321-654-4567", 3.7f, 24),
 18:     new Student("1003", "Scott", "McNealy", 
 19:                 "123 Main Street", "CA", "Sunnyville", "USA", "90715", 
 20:                 "590-298-4262", 3.5f, 48),
 21:     new Student("1004", "Larry", "Ellison", 
 22:                 "321 North Blvd.", "CA", "Sea Side", "USA", "23456", 
 23:                 "808-750-8955", 3.2f, 88),
 24:     new Student("1005", "Paul", "Allen", 
 25:                 "51 Garden Street", "OR", "Protland", "USA", "36845", 
 26:                 "455-757-7311", 3.9f, 144),
 27:     new Student("1006", "Thomas", "Jackson", 
 28:                 "543 Lake Ave.", "IL", "Plainville", "USA", "80108", 
 29:                 "103-367-4105", 2.1f, 72),
 30:     new Student("1007", "Jim", "Barksdale", 
 31:                 "789 Bay Street", "CA", "Any Town", "USA", "34191", 
 32:                 "156-303-8166", 2.5f, 84),
 33:     new Student("1008", "Marc", "Andreesen", 
 34:                 "333 Westgate Ave.", "IL", "Old Town", "USA", "33081", 
 35:                 "430-488-0931", 3.7f, 24),
 36:     new Student("1009", "David", "Boise", 
 37:                 "433 K Street", "DC", "Washington", "USA", "90324", 
 38:                 "981-981-8493", 3.5f, 32),
 39:     new Student("1010", "James", "Gosling", 
 40:                 "1 Oak Street", "CA", "Java Island", "USA", "98650", 
 41:                 "516-192-9406", 4.0f, 64),
 42:     new Student("1011", "Chris", "Galvin", 
 43:                 "768 My Street", "IL", "Northfield", "USA", "37857", 
 44:                 "272-666-5555", 2.9f, 32),
 45:     new Student("1012", "Linus", "Torvalds", 
 46:                 "53884 Norht Sea Drive", "CA", "Bay Side", "USA", "98260", 
 47:                 "815-150-3179", 3.9f, 20),
 48:     new Student("1013", "Gordon", "Moore", 
 49:                 "654 Moore Street", "FL", "Any Town", "USA", "71333", 
 50:                 "880-310-0516", 3.8f, 12),
 51:     new Student("1014", "Jerry", "Young", 
 52:                 "748 Hillside Blvd.", "CA", "Yahooville", "USA", "91578", 
 53:                 "397-716-6169", 3.5f, 104),
 54:     new Student("1015", "Eric", "Gamma", 
 55:                 "897 Central Street", "NM", "Any Town", "USA", "27351", 
 56:                 "431-878-7706", 3.6f, 136),
 57:     new Student("1016", "Richard", "Helm", 
 58:                 "567 Long Blvd.", "NY", "My Town", "USA", "27150", 
 59:                 "640-597-8608", 3.3f, 56),
 60:     new Student("1017", "Ralph", "Johnson", 
 61:                 "446 Main Street", "IL", "Middle Town", "USA", "93686", 
 62:                 "252-438-9179", 3.8f, 64),
 63:     new Student("1018", "John", "Valissides", 
 64:                 "775 North Blvd.", "NY", "My City", "USA", "33595", 
 65:                 "864-969-7578", 2.7f, 28),
 66:     new Student("1019", "James", "Coplien", 
 67:                 "387 South Street", "IL", "Any Town", "USA", "49432", 
 68:                 "741-968-7355", 3.9f, 100),
 69:     new Student("1020", "Mitchell", "Kapor", 
 70:                 "4328 Central Blvd.", "MA", "Sea Side", "USA", "71126", 
 71:                 "230-525-1849", 3.1f, 44),
 72:     new Student("1021", "Donald", "Knuth", 
 73:                 "723 Long Blvd.", "CA", "See City", "USA", "74646", 
 74:                 "719-915-6393", 4.0f, 172),
 75:   };
 76: 
 77:   public static final int INITIAL_FRAME_WIDTH = 800;
 78:   public static final int INITIAL_FRAME_HEIGHT = 400;
 79: 
 80:   public static void main(String[] args) { 
 81:     boolean useDelegation = false; 
 82:     if (args.length > 0 &&
 83:         "Delegation".equals(args[0])) { 
 84:       useDelegation = true;
 85:     }
 86: 
 87:     List entries = new ArrayList(students.length); 
 88:     for (int i = 0; i < students.length; i++) { 
 89:       if (useDelegation) {
 90:         entries.add(new StudentEntry2(students[i])); 
 91:       } else { 
 92:         entries.add(new StudentEntry(students[i])); 
 93:       }
 94:     }
 95: 
 96:     Table table = new Table(entries); 
 97: 
 98:     JFrame frame = new JFrame("Students");
 99:     frame.setContentPane(new JScrollPane(table)); 
100:     frame.setSize(INITIAL_FRAME_WIDTH, INITIAL_FRAME_HEIGHT);
101:     Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
102:     frame.setLocation(screenSize.width / 2 - INITIAL_FRAME_WIDTH / 2, 
103:                       screenSize.height / 2 - INITIAL_FRAME_HEIGHT / 2);    
104:     frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
105:     frame.setVisible(true); 
106:   }
107: 
108: }