Wednesday 24 April 2013

Create GUI from Eclipse




As i have told you in my earlier post, how to install WindowBuilder Pro for GUI in eclipse. In this post i am going to explain how to use it.

Steps to do it:

 1. go to File menu and select new project, in this wizard select Window Builder---->SWT Designer---->SWT/JFACE java project and click next and so on...................




2. select src folder and package and click on icon on top-left side of window i.e. create new visual classes. It will display the following window(here you will have list and you need to select any one of them). Given below is for Swing.




3. Now you can see in the above figure that there are two modes i.e. Source and Design where you can do coding and design of your GUI respectively.


4. At last run this as a java application as you do it for normal java application.





Installing WindowBuilder Pro in Eclipse

Installation Steps:

1.  download its jar file from  http://www.eclipse.org/windowbuilder/download.php  and select correct link     as compatible with the eclipse version
2.  go to help--->install new software---->  click on add button.
3. click on archive button and add downloaded file to the list of sites and give any name to it like WindowBuilder Pro .
4. select all the packages that are going to appear and click next and so on...................

Tuesday 23 April 2013

Run php script from java code

below program shows how to run php script from a java code
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;


public class Check
    {
        public static void main(String[] args) throws Exception
            {
                URL yahoo = new URL("http://localhost/base.php");
                URLConnection yc = yahoo.openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
                String inputLine;
                while ((inputLine = in.readLine()) != null)
                    System.out.println(inputLine);
                in.close();
            }
    }

For more information click here 

Integrate Rapidminer wtih java application

The easiest way is to create a process in Rapidminer and use this created process in your java appilcation.
You can run this process by simply creating a instance of Process class and pass the instance of class File containing name of file as argument to the constructor of Process.


Below is the java code to run process from rapidminer to perform the clustering (K-means).

Input:-----     Excel file containing dataset(numerical).

Output----- Clustered Output labelled with cluster_0, cluster_1, cluster_2.............




import com.rapidminer.RapidMiner;
import com.rapidminer.Process;
import com.rapidminer.example.Attribute;
import com.rapidminer.example.Example;
import com.rapidminer.example.ExampleSet;
import com.rapidminer.operator.IOContainer;
import com.rapidminer.operator.IOObject;
import com.rapidminer.operator.Operator;
import com.rapidminer.operator.OperatorException;



import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import com.rapidminer.operator.io.ExcelExampleSource;
import com.rapidminer.repository.IOObjectEntry;
import com.rapidminer.repository.ProcessEntry;
import com.rapidminer.repository.RepositoryLocation;
import com.rapidminer.tools.XMLException;

public class Model {

     public static void main(String args[]) throws Exception {
        
    // this initializes RapidMiner with your repositories available
        
    RapidMiner.setExecutionMode(RapidMiner.ExecutionMode.COMMAND_LINE);
  
    RapidMiner.init();
  
    // loads the process from the repository
    Process location = new Process(new File("C:\\Documents and Settings\\MNNIT\\.RapidMiner5\\repositories\\Local Repository\\processes\\cluster.rmp"));
    //Entry entry = location.locateEntry();
    //if (entry instanceof ProcessEntry) {
        //Process process = new RepositoryProcessLocation(location).load(null);
    Operator op = location.getOperator("Read Excel");
    op.setParameter(ExcelExampleSource.PARAMETER_EXCEL_FILE, "E:\\Amit_Agrawal\\thesis\\paper\\anomaly in text\\blog\\data\\component.xls");
    //Operator outp = location.getOperator("Write Excel");
   //outp.setParameter(ExcelExampleSource.PARAMETER_EXCEL_FILE, "E:\\Amit_Agrawal\\thesis\\paper\\anomaly in text\\blog\\data\\abcd.xls");
  
    IOContainer ioResult = location.run();
        IOObject result = ioResult.getElementAt(0);
    // use the result(s) as needed, for example if your process just returns one ExampleSet, use this:
    if (ioResult.getElementAt(0) instanceof ExampleSet) {
        ExampleSet resultSet = (ExampleSet)ioResult.getElementAt(0);
        System.out.println(result);
        int i=0;
        for (Example example : resultSet) {
             Iterator<Attribute> allAtts = example.getAttributes().allAttributes();
           
           
             while(allAtts.hasNext()) {
                 Attribute a = allAtts.next();
               if(i<=3)
                 System.out.print(a.getName()+ "  ");
              
                 i++;
             }
        }
        System.out.println("\n");
     for (Example example : resultSet) {
         Iterator<Attribute> allAtts = example.getAttributes().allAttributes();
       
       
         while(allAtts.hasNext()) {
             Attribute a = allAtts.next();
           
                     if (a.isNumerical()) {
                             double value = example.getValue(a);
                             System.out.print(value+ " " );
                             //System.out.println("\n");

                     } else {
                             String value = example.getValueAsString(a);
                             System.out.print(value+ " ");
                             //System.out.println("\n");
                     }
              }
         System.out.println("\n");
  

  
   }
    
}
  
  
     }
}

for more information click here