package boundary;

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

/**
 * The builder application boundary class.
 *
 * @author Cem Unsal, Eli Skeggs, and Maurizio Vitale
 */
public class BuilderApplication extends JFrame {
  public static final String title = "Level Builder";

  protected BuilderModel model;
  protected JPanel view = null;

  public ResourceLoader loader;

  /**
   * Create a builder application from the given model and resource loader.
   *
   * @param model
   * @param loader
   */
  public BuilderApplication(BuilderModel model, ResourceLoader loader) {
    this.model = model;
    this.loader = loader;

    // always exit the JVM when the user closes the window
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }

  /**
   * Set the currently displayed JPanel. Makes the application visible if it's
   * not already.
   *
   * @param panel
   */
  public void setView(JPanel panel) {
    boolean wasHidden = view == null;
    view = panel;
    setContentPane(panel);
    pack();
    if (wasHidden) {
      setVisible(true);
    }
  }

  /**
   * Get the currently displayed JPanel.
   *
   * @return The currently visible JPanel.
   */
  public JPanel getView() {
    return view;
  }

  /**
   * Creates the splash screen, loads resources, then initializes the main
   * window (BuilderApplication).
   *
   * @param args The command-line parameters for the application.
   */
  public static void main(String[] args) {
    ResourceLoader loader = new ResourceLoader();;
        

    // start splash screen
    SplashScreen splash;
    try {
      splash = new SplashScreen("splash1levelbuilder.png");
    } catch (IOException err) {
      System.err.println(err.getMessage());
      err.printStackTrace();
      return;
    }
    

    long loadStart = System.currentTimeMillis();
    BuilderModel model = new BuilderModel();


    load (loader);
    
    // initialize main app
    BuilderApplication app = new BuilderApplication(model, loader);
    JPanel initialView = new BuilderMainMenuView(app, model);

    // extend time if necessary
    long loadElapsed = System.currentTimeMillis() - loadStart;
    if (loadElapsed < 2000) {
      try {
        Thread.sleep(2000 - loadElapsed);
      } catch (InterruptedException err) {
        // if we've been interrupted, just close the splash screen
      } finally {
        // close splash screen
        splash.close();
      }
    }

    // start main app
    app.setView(initialView);
  }
  
  public static void load (ResourceLoader loader){

	    loader.addResource("playable.png");
	    for (int i = 1; i <= 6; i++) {
	      loader.addResource(i + ".png");
	    }

	    // load resources
	    try {
	      loader.loadResources();
	    } catch (IOException err) {
	      System.err.println(err.getMessage());
	      err.printStackTrace();
	      return;
	    }

  }
  
}

@@ -1513,69 +1513,8 @@
 ) %7B%0A
-    ResourceLoader loader = new ResourceLoader();;%0A        %0A%0A
     
@@ -1610,17 +1610,17 @@
 (%22splash
-1
+2
 levelbui
@@ -1755,21 +1755,16 @@
 n;%0A    %7D
-%0A    
 %0A%0A    lo
@@ -1856,32 +1856,91 @@
 );%0A%0A
-%0A    load (loader)
+    ResourceLoader loader = load();%0A%0A    if (loader == null) %7B%0A      return
 ;%0A    
+%7D%0A
 %0A   
@@ -2236,16 +2236,19 @@
  %7B%0A     
+ //
    Threa
@@ -2281,16 +2281,19 @@
 );%0A     
+ //
  %7D catch
@@ -2533,18 +2533,16 @@
 w);%0A  %7D%0A
-  
 %0A  publi
@@ -2554,45 +2554,120 @@
 tic 
-void load (ResourceLoader loader)%7B%0A%0A%09
+ResourceLoader load() %7B%0A    ResourceLoader loader = new ResourceLoader();%0A%0A    for (int i = 1; i %3C= 6; i++) %7B%0A  
     
@@ -2689,25 +2689,21 @@
 rce(
-%22playable
+i + %22
 .png%22);%0A
 %09   
@@ -2694,25 +2694,30 @@
  + %22.png%22);%0A
-%09
+    %7D%0A
     for (int
@@ -2717,33 +2717,33 @@
 or (int i = 
-1
+2
 ; i %3C= 
-6
+3
 ; i++) %7B%0A%09  
@@ -2735,25 +2735,24 @@
 = 3; i++) %7B%0A
-%09
       loader
@@ -2756,32 +2756,38 @@
 der.addResource(
+%22x%22 + 
 i + %22.png%22);%0A%09  
@@ -2787,17 +2787,134 @@
 %22);%0A
-%09
     %7D%0A%0A
-%09
+    loader.addResource(%22playable.png%22);%0A    loader.addResource(%22selected.png%22);%0A    loader.addResource(%22marked.png%22);%0A%0A
     
@@ -2931,17 +2931,16 @@
 sources%0A
-%09
     try 
@@ -2941,17 +2941,16 @@
   try %7B%0A
-%09
       lo
@@ -2967,25 +2967,24 @@
 esources();%0A
-%09
     %7D catch 
@@ -3003,17 +3003,16 @@
  err) %7B%0A
-%09
       Sy
@@ -3047,17 +3047,16 @@
 age());%0A
-%09
       er
@@ -3076,17 +3076,16 @@
 race();%0A
-%09
       re
@@ -3092,11 +3092,15 @@
 turn
+ null
 ;%0A
-%09
     
@@ -3104,15 +3104,31 @@
    %7D%0A%0A  
-%7D
+  return loader;
 %0A  
+%7D
 %0A%7D%0A

Fix Builder resource loader