DARK_BYTE 0 Junior Poster in Training

HI I am currently doing my final year project and I need to build an algorithm visualization tool(with user defined algorithm animation). The user defined animation takes place as follows:

1. The user can open a text editor in the GUI and type his/her user-defined algo in java
2. When the user clicks the run menu item, I am using the Java Compiler API to compile the file the user saved.

I successfully animated more than one user-defined algorithm.


public class userDefined
public static void main(String [] args)
		int [] numArr  = {1,3,1,-1,5,-5,0,7,12,-30};
		myArray myArray = new myArray(numArr);
            int min;      

	    for (int pos=0; pos<myArray.length()-1; pos++)
                min = pos;

	    	for (int i=pos+1; i<myArray.length(); i++)
	    		if (myArray.get(i) < myArray.get(min))
	    			min = i;


myArray is a class that the tool provides for the user to use in the algo he/she types.

This is a portion of the GUI code:

private void jMenuItem10ActionPerformed(java.awt.event.ActionEvent evt) {                                            
        // TODO add your handling code here:
            JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
        if(compiler.run(null, null, null, "userDefined.java") != 0) {
            System.err.println("Could not compile.");
        try {
            Runtime rt = Runtime.getRuntime();
            Process pr = rt.exec("java "+"userDefined");
            BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
            String line=null;
            while((line=input.readLine()) != null) {
        } catch(Exception e) {

The problem I am having is that if I run the project in Netbeans and then use the tool to compile and run the user-defined algo it doesn't work unless I stop the run and then copy paste the Tool and myArray classes at the same level as "userDefined.java".
i.e userDefined.java is in C:\Users\user\Documents\NetBeansProjects\My_Final_Year_Project

I am having to copy myArray and Tool from C:\Users\user\Documents\NetBeansProjects\My_Final_Year_Project\build\classes and paste them in C:\Users\user\Documents\NetBeansProjects\My_Final_Year_Project to get it to work properly.

I try saving userDefined in C:\Users\user\Documents\NetBeansProjects\My_Final_Year_Project\src but agian its not working.

Its only working when I run the project once then close the tool and move myArray and Tool classes to C:\Users\user\Documents\NetBeansProjects\My_Final_Year_Project and then rerun the project.

Please I really need help with this...Thanks!

p.s also the tool(algorithm visualization tool)is represented by my GUI class not Tool class; Tool class is just a class that contains a static frame/panel for use in the user-defined algo.
Again it works but only if I move the classes and make a second run of the project.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.