package boundary;

import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import model.BuilderModel;

public class BuilderApplication {
  public static final String title = "Level Builder";

  protected BuilderModel model;
  protected JFrame frame;
  protected JPanel view = null;

  public BuilderApplication(BuilderModel model) {
    this.model = model;

    frame = new JFrame(title);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  public void setView(JPanel panel) {
    boolean wasHidden = view == null;
    view = panel;
    frame.setContentPane(panel);
    frame.pack();
    if (wasHidden) {
      frame.setVisible(true);
    }
  }

  public JPanel getView() {
    return view;
  }

  public static void main(String[] args) {
    // start splash screen
    SplashScreen splash;
    try {
      splash = new SplashScreen("splash1levelbuilder.png");
    } catch (IOException err) {
      System.err.println(err.getMessage());
      err.printStackTrace();
      return;
    }

    // load resources
    BuilderModel model = new BuilderModel();
    try {
      Thread.sleep(4000);
    } catch (InterruptedException err) {
      return;
    } finally {
      // close splash screen
      splash.close();
    }

    // start main app
    BuilderApplication app = new BuilderApplication(model);
    app.setView(new BuilderMainMenuView(app, model));
  }
}

@@ -302,16 +302,42 @@
  null;%0A%0A
+  ResourceLoader loader;%0A%0A
   public
@@ -374,16 +374,39 @@
 el model
+, ResourceLoader loader
 ) %7B%0A    
@@ -424,16 +424,42 @@
 = model;
+%0A    this.loader = loader;
 %0A%0A    fr
@@ -842,24 +842,155 @@
 g%5B%5D args) %7B%0A
+    ResourceLoader loader = new ResourceLoader();%0A%0A    for (int i = 1; i %3C= 6; i++) %7B%0A      loader.addResource(i + %22.png%22);%0A    %7D%0A%0A
     // start
@@ -1247,16 +1247,65 @@
 sources%0A
+    long loadStart = System.currentTimeMillis();%0A
     Buil
@@ -1361,25 +1361,29 @@
     
-Thread.sleep(4000
+loader.loadResources(
 );%0A 
@@ -1399,18 +1399,9 @@
 h (I
-nterrupted
+O
 Exce
@@ -1423,81 +1423,87 @@
     
-return;%0A    %7D finally %7B%0A      // close splash screen%0A      splash.close()
+System.err.println(err.getMessage());%0A      err.printStackTrace();%0A      return
 ;%0A  
@@ -1514,21 +1514,26 @@
 %0A    // 
-start
+initialize
  main ap
@@ -1595,27 +1595,44 @@
 odel
-);%0A    app.set
+, loader);%0A    JPanel initial
 View
-(
+ = 
 new 
@@ -1662,16 +1662,431 @@
 , model)
+;%0A%0A    // extend time if necessary%0A    long loadElapsed = System.currentTimeMillis() - loadStart;%0A    if (loadElapsed %3C 2000) %7B%0A      try %7B%0A        Thread.sleep(4000);%0A      %7D catch (InterruptedException err) %7B%0A        // if we've been interrupted, just close the splash screen%0A      %7D finally %7B%0A        // close splash screen%0A        splash.close();%0A      %7D%0A    %7D%0A%0A    // start main app%0A    app.setView(initialView
 );%0A  %7D%0A%7D

Add resource loader to BuilderApplication