Browse Source

api finish?

Kevin Trometer 7 years ago
parent
commit
2ea5ae55f5
1 changed files with 16 additions and 7 deletions
  1. 16 7
      src/ui/view/SimulationMenu.java

+ 16 - 7
src/ui/view/SimulationMenu.java

@@ -178,7 +178,7 @@ public class SimulationMenu extends JMenuBar {
 		gbcAlgoCombo.gridx = 4;
 		gbcAlgoCombo.gridy = 0;
 		menuPanel.add(algoCombo, gbcAlgoCombo);
-		// algoCombo.addItem(Languages.getLanguage()[86]);
+		algoCombo.addItem(Languages.getLanguage()[86]);
 
 		// Add Panel to SimulationMenu
 		this.add(menuPanel);
@@ -194,13 +194,18 @@ public class SimulationMenu extends JMenuBar {
 			while (line != null) {
 				line = line.trim();
 				if (!line.isEmpty()) {
-					controller.addTextToConsole(line);
+					if (line.length() >= 7 &&line.substring(0, 7).equals("package")) {
+						packageName = line.substring(8, line.length() - 1);
+					}
+				}
+				if (packageName.isEmpty()) {
+					line = br.readLine();
+				} else {
+					line = null;
 				}
 
-				line = br.readLine();
 			}
 
-			controller.addTextToConsole("name" + packageName);
 
 			// Compile source file.
 			JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
@@ -210,15 +215,19 @@ public class SimulationMenu extends JMenuBar {
 			// Load and instantiate compiled class.
 			URLClassLoader classLoader = URLClassLoader.newInstance(new URL[] { root.toURI().toURL() });
 
-			Class<?> cls = Class.forName("projectPackage." + name, true, classLoader);
+			Class<?> cls;
+			if (packageName.isEmpty()) {
+				cls = Class.forName(name, true, classLoader);
+			} else {
+				cls = Class.forName(packageName+"."+ name, true, classLoader);
+			}
 
 			Object t = cls.newInstance();
 
 			controller.setAlgorithm(t);
 
 		} catch (Exception e) {
-			e.printStackTrace();
-
+			controller.addTextToConsole(e.toString());
 		}
 	}
 }