Thursday, October 14, 2010

My Search Tool

This is a program written in java that searches a file in the specific directory or in a Drive....



code::
//Search.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.*;
import java.io.*;
class Search implements ActionListener,Runnable
{
JFrame mainFrame;
JPanel rightPanel,mainPanel;
JPanel leftPanel;
JTextField tf1,tf2;
JButton jb;
int sw;
int sh;
JTable table;
DefaultTableModel model;
JScrollPane sp;
static int count=0;
Vector v=new Vector();
JComboBox cb;
JButton up,down;
JLabel temp;
JButton browse;
JCheckBox specific;
String pathtolook="";
JLabel dynamic;
ImageIcon icon;
JLabel progresslb;
JLabel imglb;
ImageIcon i;
Search()
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
}

Dimension d=Toolkit.getDefaultToolkit().getScreenSize();
sw=d.width;
sh=d.height;

mainFrame=new JFrame("Search");
leftPanel=new BackgroundPanel();
rightPanel=new JPanel();


jb=new JButton("search");
cb=new JComboBox();
File roots[]=File.listRoots();
for(int i=0;icb.addItem(roots[i]);
//cb.getEditor().getEditorComponent().setBackground(Color.gray);

Vector v=new Vector();
v.add("Name");
v.add("Directory");
v.add("Size");
v.add("Type");
v.add("Date Modified");

String col[]={"Name","Directory","Size","Type","DataModified"};





sp=new JScrollPane();
table=new JTable();
model=new DefaultTableModel(col,0);
table.setModel(model);

//table.setShowGrid(false);
//table.setShowHorizontalLines(true);
//table.setShowVerticalLines(false);

sp.setViewportView(table);
model.setColumnIdentifiers(v);


leftPanel.setLayout(null);

JLabel lb1=new JLabel("All or Part Name of the File:");
lb1.setBounds(20,150,140,20);
leftPanel.add(lb1);

tf1=new JTextField();
tf1.setBounds(20,170,140,20);
leftPanel.add(tf1);

JLabel lb2=new JLabel("A word or Phrase in the File:");
lb2.setBounds(20,200,140,20);
leftPanel.add(lb2);

tf2=new JTextField();
tf2.setBounds(20,220,140,20);
leftPanel.add(tf2);


JLabel lb3=new JLabel("Look In:");
lb3.setBounds(20,250,140,20);
leftPanel.add(lb3);

cb.setBounds(20,270,140,20);
leftPanel.add(cb);

jb.setBounds(55,310,80,30);
leftPanel.add(jb);

i=new ImageIcon("sd.gif");
imglb=new JLabel(i);
imglb.setBounds(70,400,71,74);
leftPanel.add(imglb);

browse=new JButton("Specific folder search");
browse.setEnabled(false);
//browse.setContentAreaFilled(false);
browse.setBounds(10,500,150,20);
leftPanel.add(browse);
browse.addActionListener(new BrowseListener());

specific=new JCheckBox("Specific Search");
specific.addActionListener(new BrowseListener());
specific.setBounds(30,350,100,20);
leftPanel.add(specific);
specific.setContentAreaFilled(false);

icon=new ImageIcon("pb1.gif");
progresslb=new JLabel(icon);


leftPanel.setBounds(0,0,180,sh-60);
rightPanel.setBounds(180,0,sw-180,sh-60);
sp.setBounds(0,0,sw-185,sh-60);

//leftPanel.setBackground(Color.gray);
rightPanel.setBackground(Color.white);
rightPanel.setLayout(null);
rightPanel.add(sp);

mainPanel=new JPanel();
mainPanel.setLayout(null);
mainPanel.add(leftPanel);
mainPanel.add(rightPanel);

//mainFrame.setLayout(null);
mainFrame.add(mainPanel);
mainFrame.setSize(sw,sh-30);
mainFrame.setVisible(true);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jb.addActionListener(this);
}


class BrowseListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
JFileChooser jfilechooser = new JFileChooser();
jfilechooser.setFileSelectionMode(1);
if(e.getSource() == browse)
{
int i = jfilechooser.showOpenDialog(null);
if(i == 0)
{
pathtolook=jfilechooser.getSelectedFile().getAbsolutePath();
dynamic=new JLabel("Look In: "+jfilechooser.getSelectedFile().getAbsolutePath());
dynamic.setBounds(5,550,200,20);
leftPanel.add(dynamic);
leftPanel.updateUI();

}
}

if(e.getSource()==specific)
{
if(specific.isSelected())
{
cb.setEnabled(false);
browse.setEnabled(true);
}
else
{
cb.setEnabled(true);
browse.setEnabled(false);
leftPanel.remove(dynamic);
leftPanel.updateUI();
}
}

}

}

public void actionPerformed(ActionEvent e)
{
if(tf1.getText().equals("") && tf2.getText().equals(""))
{
JOptionPane.showMessageDialog(null, "Enter the filename to search", "What to search", 0);
}
else
{
progresslb.setBounds(10,600,160,13);
leftPanel.add(progresslb);
leftPanel.updateUI();
i=new ImageIcon("searchdog.gif");
imglb.setIcon(i);
if(specific.isSelected())
{
new Thread(this).start();
}
else
{
pathtolook=""+cb.getSelectedItem();
new Thread(this).start();
}
}
jb.setEnabled(false);
}

public void run()
{
addDataInTable(tf1.getText().equals("")?tf2.getText():tf1.getText(),pathtolook);
icon =new ImageIcon("pb2.gif");
progresslb.setIcon(icon);

i=new ImageIcon("sd.gif");
//imglb.setBounds(70,400,71,74);
imglb.setIcon(i);
JOptionPane.showMessageDialog(null,"Search Complete\n No. of Files and Directories found:"+count,"Complete",JOptionPane.PLAIN_MESSAGE);
}


public void addDataInTable(String dts,String rts)
{
File f=new File(rts);
File[] list=f.listFiles();
for(int i=0;i{
if(list[i].isDirectory() && !list[i].isHidden())
{
if(list[i].getName().contains(dts))
{
v=new Vector();
v.add(list[i].getName());
v.add(list[i].getParent());
v.add("A Directory");
v.add("directory");
Date date=new Date(list[i].lastModified());
v.add(date.toString());
model.insertRow(count,v);
count++;
}
addDataInTable(dts,list[i].getPath());
}
else
{
if(list[i].getName().contains(dts))
{
v=new Vector();
v.add(list[i].getName());
v.add(list[i].getParent());
v.add(""+(list[i].length()/1024)+"KB");
v.add("file");
Date date=new Date(list[i].lastModified());
v.add(date.toString());
model.insertRow(count,v);
count++;
}
}
}
}
public static void main(String... s)
{
new Search();
}
}

//BackgroundPanel.java
import java.io.*;
import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;

class BackgroundPanel extends JPanel
{
Image image;
public BackgroundPanel()
{
try
{
image = new ImageIcon("back2.PNG").getImage();
}
catch (Exception e) { /*handled in paintComponent()*/ }
}


public void paintComponent(Graphics g)
{
Graphics2D g2=(Graphics2D)g;
super.paintComponent(g);
if (image != null)
g.drawImage(image,0,0,null);

}
}

SearchTool


Tuesday, October 5, 2010

Pointers vs References...

Why java use references not pointers?????
To get the answer of this we have to go the low level that is the memory allocation for the object....

Where the Object is stored???
A quick answer::an Object is stored on the heap??

what is the Heap???
The heap is a large block of memory that Java uses to store objects........

How the things are Happening?????
When a new object is created, the necessary amount of space is set aside for it in the heap. The new operator returns a reference to the block of memory in the heap where the object is stored. The virtual machine is responsible for managing the heap and making sure that the same block of memory is not used for two different objects or arrays at the same time.
The exact size of the heap is system-dependent. However, the heap is finite on all systems. In some Java implementations, the heap can grow if more space is needed. On others the size of the heap is fixed when the virtual machine starts up....

suppose this is a heap actually this is a fragmented heap..
Whenever we starts our program we come with a heap fairly empty,and after running our program for some time some objects are created and some are garbage collected so we leave up with a frangmented heap..
(suppose redblocks are occupied by some object and gray ones are free..and each block represent a word of memory)




and for a while just leave the references and think that you have been provided with the direct pointers to the heap memory as in C ..so our scenario will look like this:
This is the same heap, with object variables shown as ovals. The arrows are pointers into the heap. Each object has at least one pointer (to its own data), and some have multiple pointers if they themselves contain references to other objects.Furthermore, one object may be pointed to from several different places. This interconnected web of pointers makes it very difficult to move objects in the heap, because you have to update all of the different pointers that can exist in hundreds of different objects, methods, and threads...

Now suppose an object is created which requires 4 words of memory ,,now as we can see on the heap there is no free 4 words contiguous memory for the object,So the Heap has to be Defragmented.and this is what a Defragmented Heap looks like::
This is the Frangmented Heap and now there is space for a four-word object. However, many — perhaps most — of the pointers are broken. Some now point to the wrong object. Others point to nowhere in particular. The VM can try to identify every reference to each moved object in the running program and update it with the new address of its data, but there can be thousands of these, and the operation can be extremely time consuming in a large program.

Now How the problem can be solved?????
One way to look at the problem is that references point to areas of different sizes in the heap. If you could somehow arrange it so that every object needed exactly the same amount of space in the heap, then fragmentation would not be a problem. As long as there was any free space at all,it could be used.

References TO the Rescue....
Of course, different objects do take different amounts of space, but references always take same amount of memory. The solution is to insert an extra block of references between the references in your source code and the heap. When an object is moved in the heap,only one link needs to be updated: the one between the offset table and the data in the heap. The many more pointers to the offset table do not need to be updated.
Now our scenario will look like this::

So,we are provided with reference ,,not the direct pointer to the heap,another reason may be the security or platform independence to give the preference to the reference variables over pointers..........

compilation gotcha in java6 vs java7

Compiling all the files in a folder for a java programmer is a routine job ,,so what we do we go to required directory and say javac*.java and all the java files get compiled...
now suppose we are at e:\javapro and we want to compile all the java files present in
f:\javapro so what we will do,,we will go to f:\javapro in the prompt ,and then we will say javac *.java....

this is what what we do when we are using upto java7
now from java7 we can compile all the files in the different folders form the different location....
again suppose we are at e:\javapro and want to compile all the java files present at f:\javapro ,,so in java7 we will just say::

javac "f:\javapro\*.java";
and all the files will get compiled........
caution::quotes are necessary.......

but with java6 it will give the error::
file not found::f:\javapro\*.java

Monday, October 4, 2010

Table Viewer

This is Table viewer by which you can see the records of your table in your dsn with a scrollbar provided at the bottom of the frame....

Enter your DSN::



Now your can see the Name of the tables present in your dsn,select the table and go....



This is how you will see the recordes in your table.....



Your can download this from::
Download

Sunday, October 3, 2010

VirtualDosPrompt

This is the Virtual Dos Prompt created in java,having functionality like compiling the java files,running the class file ,seeing the directory,renaming the file or directory,and some thing more,,you can use help command to see the list of command available......



code::
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import java.awt.*;
import javax.swing.text.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import javax.swing.filechooser.*;
import java.util.*;
class VirtualDosPrompt
{
JFrame f;
MyTextArea ta;
int length;
JScrollPane sp;
String curpath="";
boolean flag=true;
String fileName="";
VirtualDosPrompt()
{
f=new JFrame("Virtual DOS-Prompt");
ta=new MyTextArea();
ta.setBackground(Color.black);
ta.setForeground(Color.white);
ta.setFont(new Font("lucida console",Font.PLAIN,14));
((JTextComponent)ta).setCaretColor(Color.white);
ta.setLineWrap(true);
curpath=System.getProperty("user.dir")+">";

ta.setText(curpath);
length=curpath.length();
ta.setCaretPosition(length);
sp=new JScrollPane(ta);


f.add(sp);
f.setSize(670,340);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setLocation(100,100);
ta.addKeyListener(new MyTextAreaListener());
}
public static void main(String... s)
{
new VirtualDosPrompt();
}

class MyTextArea extends JTextArea
{
MyTextArea()
{
super();
}
MyTextArea(String str)
{
super(str);
}
public boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed)
{
if(ta.getCaretPosition()>length)
return super.processKeyBinding(ks,e,condition,pressed);
else
{
if(e.getKeyCode()==e.VK_BACK_SPACE || e.getKeyCode()==e.VK_LEFT || e.getKeyCode()==e.VK_HOME || e.getKeyCode()==e.VK_DELETE || ta.getCaretPosition()return false;
else
return super.processKeyBinding(ks,e,condition,pressed);
}
}
}//end inner class

class MyTextAreaListener implements KeyListener
{
char c;
String s="";

public void keyPressed(KeyEvent ke)
{
c=ke.getKeyChar();
if(c=='\n' && flag==true)
{
String temp=ta.getText();
int index=temp.lastIndexOf(">");
s=temp.substring(index+1);
performAction(s.trim(),ke);
s="";
}
if(ke.isControlDown() && flag==false)
{
if(ke.getKeyCode()==ke.VK_S)
nowSaveFile(fileName);
else
{}
}
}
public void keyTyped(KeyEvent ke)
{}
public void keyReleased(KeyEvent ke)
{}

public void performAction(String cmd,KeyEvent ke)
{
if(cmd.equals("exit"))
{
System.exit(0);
}
else if(cmd.equals("cls"))
{
ta.setText("");
ta.setText(curpath);
length=curpath.length();
}
else if(cmd.equals("dir"))
{
showDirDetail();
}
else if(cmd.equals("info"))
{
showInfo();
}
else if(cmd.endsWith(":"))
{
changeDrive(cmd);
}
else if(cmd.equals("cd.."))
{
getParentDirectory();
}
else if(cmd.equals("cd\\"))
{
goToRoot();
}
else if(cmd.startsWith("cd"))
{
changeDirectory(cmd);
}
else if(cmd.startsWith("mkdir"))
{
makeDirectory(cmd);
}
else if(cmd.startsWith("del"))
{
deleteDirectory(cmd);
}
else if(cmd.equals("javac *.java"))
{
compileAll(cmd);
}
else if(cmd.startsWith("javac"))
{
compileJavaFile(cmd);
}
else if(cmd.startsWith("java"))
{
runJavaProgram(cmd);
}
else if(cmd.startsWith("bg"))
{
changeBackGroundColor(cmd);
}
else if(cmd.startsWith("fg"))
{
changeForeGroundColor(cmd);
}
else if(cmd.equals("reset"))
{
resetAll();
}
else if(cmd.startsWith("help") || cmd.equals("?"))
{
showHelp();
}
else if(cmd.equalsIgnoreCase("jinfo"))
{
showJavaInfo();
}
else if(cmd.equalsIgnoreCase("osinfo"))
{
showOSInfo();
}
else if(cmd.startsWith("create file"))
{
flag=false;
createFile(cmd,ke);
}
else if(cmd.startsWith("ren"))
{
renameFile(cmd);
}
else if(cmd.equalsIgnoreCase("wv"))
{
ta.setBackground(Color.white);
ta.setForeground(Color.black);
ta.append("\n"+curpath);
((JTextComponent)ta).setCaretColor(Color.black);
length=ta.getText().length();
}
else if(cmd.equalsIgnoreCase("nv"))
{
ta.setBackground(Color.black);
ta.setForeground(Color.white);
ta.append("\n"+curpath);
((JTextComponent)ta).setCaretColor(Color.white);
length=ta.getText().length();
}
else if(cmd.equalsIgnoreCase("ov"))
{
ta.setBackground(Color.black);
ta.setForeground(Color.orange);
ta.append("\n"+curpath);
((JTextComponent)ta).setCaretColor(Color.orange);
length=ta.getText().length();
}
else if(cmd.equalsIgnoreCase("yv"))
{
ta.setBackground(Color.black);
ta.setForeground(Color.yellow);
ta.append("\n"+curpath);
((JTextComponent)ta).setCaretColor(Color.yellow);
length=ta.getText().length();
}
else if(cmd.equalsIgnoreCase("gv"))
{
ta.setBackground(Color.black);
ta.setForeground(Color.green);
ta.append("\n"+curpath);
((JTextComponent)ta).setCaretColor(Color.green);
length=ta.getText().length();
}
else if(cmd.equalsIgnoreCase("rv"))
{
ta.setBackground(Color.black);
ta.setForeground(Color.red);
ta.append("\n"+curpath);
((JTextComponent)ta).setCaretColor(Color.red);
length=ta.getText().length();
}
else if(cmd.equalsIgnoreCase("cv"))
{
ta.setBackground(Color.black);
ta.setForeground(Color.cyan);
ta.append("\n"+curpath);
((JTextComponent)ta).setCaretColor(Color.cyan);
length=ta.getText().length();
}
else if(cmd.equalsIgnoreCase("grv"))
{
ta.setBackground(Color.black);
ta.setForeground(Color.gray);
ta.append("\n"+curpath);
((JTextComponent)ta).setCaretColor(Color.gray);
length=ta.getText().length();
}
else
{
ta.append("\ncommand not found");
ta.append("\nSee help or ? for command list\n");
ta.append(curpath);
length=ta.getText().length();
}
}

public void resetAll()
{
ta.setBackground(Color.black);
ta.setForeground(Color.white);
((JTextComponent)ta).setCaretColor(Color.white);
ta.append("\n"+"DOs-Prompt Resetted");
ta.append("\n"+curpath);
length=ta.getText().length();
}

public void changeBackGroundColor(String cmd)
{
String bg=cmd.substring(3);
Color c=getColor(bg);
ta.setBackground(c);
ta.append("\n"+curpath);
length=ta.getText().length();
}

public void changeForeGroundColor(String cmd)
{
String fg=cmd.substring(3);
Color c=getColor(fg);
ta.setForeground(c);
ta.append("\n"+curpath);
length=ta.getText().length();
}

public Color getColor(String bg)
{
Color c=new Color(0,0,0);
if(bg.equalsIgnoreCase("red"))
c=Color.red;
else if(bg.equalsIgnoreCase("white"))
c=Color.white;
else if(bg.equalsIgnoreCase("gray"))
c=Color.gray;
else if(bg.equalsIgnoreCase("lightgray"))
c=Color.lightGray;
else if(bg.equalsIgnoreCase("darkgray"))
c=Color.darkGray;
else if(bg.equalsIgnoreCase("black"))
c=Color.black;
else if(bg.equalsIgnoreCase("pink"))
c=Color.pink;
else if(bg.equalsIgnoreCase("orange"))
c=Color.orange;
else if(bg.equalsIgnoreCase("yellow"))
c=Color.yellow;
else if(bg.equalsIgnoreCase("green"))
c=Color.green;
else if(bg.equalsIgnoreCase("magenta"))
c=Color.magenta;
else if(bg.equalsIgnoreCase("cyan"))
c=Color.cyan;
else if(bg.equalsIgnoreCase("blue"))
c=Color.blue;
else if(bg.equalsIgnoreCase("default"))
{
ta.setBackground(Color.black);
ta.setForeground(Color.white);
return null;
}
else
{
ta.append("\n"+"This Color is not present,see help for bg");
}
return c;
}

public void renameFile(String cmd)
{
String cp=curpath.substring(0,curpath.length()-1);
String token[]=cmd.split(" ");
if(token.length!=3)
ta.append("\nren takes two arguments,sourcename and desname");
else
{
String sourceName=token[1];
String desName=token[2];

if(sourceName.indexOf(File.separator)==-1)
sourceName=cp+File.separator+sourceName;
if(desName.indexOf(File.separator)==-1)
desName=cp+File.separator+desName;

File f1=new File(sourceName);
File f2=new File(desName);

System.out.println("f1 name:"+f1);
System.out.println("f2 name:"+f2);

if(f1.exists())
{
f1.renameTo(f2);
if(sourceName.charAt(0)==desName.charAt(0))
ta.append("\nFile Renamed");
else
ta.append("\nFile Renamed and moved");
}
else
ta.append("\n source file does not exists");
}
ta.append("\n"+curpath);
length=ta.getText().length();
}

public void nowSaveFile(String fileName)
{
String data=ta.getText().substring(length+System.getProperty("line.separator").toString().length()-1);
String[] a=data.split("\n");
try
{
BufferedWriter bw=new BufferedWriter(new FileWriter(fileName));
for(String str:a)
{
bw.write(str);
bw.newLine();
}
bw.close();
flag=true;
ta.append("\nFile created");
ta.append("\n"+curpath);
length=ta.getText().length();
}
catch(Exception e)
{
System.out.println("file creation exception"+e);
ta.append("\n"+"can not create file");
ta.append("\n"+curpath);
length=ta.getText().length();
}
}

public void createFile(String cmd,KeyEvent ke)
{
flag=false;
String cp=curpath.substring(0,curpath.length()-1);
String tempfileName=cmd.substring(12);
if(tempfileName.indexOf(File.separator)==-1)
{
fileName=cp+File.separator+tempfileName;
}
else
{
fileName=tempfileName;
}
if(new File(fileName).exists())
{
ta.append("\nFile already exists");
ta.append("\n"+curpath);
flag=true;
}
length=ta.getText().length();
}

public void showOSInfo()
{
ta.append("\n\nOperating system name:-" + System.getProperty("os.name").toString());
ta.append("\nOperating system architecture:-" + System.getProperty("os.arch").toString());
ta.append("\nOperating system version:-" + System.getProperty("os.version").toString());
ta.append("\nFile separator (" + "/" + " on UNIX):-" + System.getProperty("file.separator").toString());
ta.append("\nPath separator (" + ":" + " on UNIX):-" + System.getProperty("path.separator").toString());
ta.append("\nLine separator :-" + System.getProperty("line.separator").toString());
ta.append("\nUser's account name:-" + System.getProperty("user.name").toString());
ta.append("\nUser's home directory:-" + System.getProperty("user.home").toString());
ta.append("\nUser's current working directory:-" + System.getProperty("user.dir").toString());
ta.append("\n\n"+curpath);
length=ta.getText().length();
}


public void showJavaInfo()
{
ta.append("\n\nJava Runtime Environment version:-" + System.getProperty("java.version").toString());
ta.append("\nJava Runtime Environment vendor:-" + System.getProperty("java.vendor").toString());
ta.append("\nJava vendor URL:-" + System.getProperty("java.vendor.url").toString());
ta.append("\nJava installation directory:-" + System.getProperty("java.home").toString());
ta.append("\nJava Virtual Machine specification version:-" + System.getProperty("java.vm.specification.version").toString());
ta.append("\nJava Virtual Machine specification vendor:-" + System.getProperty("java.vm.specification.vendor").toString());
ta.append("\nJava Virtual Machine specification name:-" + System.getProperty("java.vm.specification.name").toString());
ta.append("\nJava Virtual Machine implementation version:-" + System.getProperty("java.vm.version").toString());
ta.append("\nJava Virtual Machine implementation vendor:-" + System.getProperty("java.vm.vendor").toString());
ta.append("\nJava Virtual Machine implementation name:-" + System.getProperty("java.vm.name").toString());
ta.append("\nJava Runtime Environment specification version:-" + System.getProperty("java.specification.version").toString());
ta.append("\nJava Runtime Environment specification vendor:-" + System.getProperty("java.specification.vendor").toString());
ta.append("\nJava Runtime Environment specification name:-" + System.getProperty("java.specification.name").toString());
ta.append("\nJava class format version number:-" + System.getProperty("java.class.version").toString());
ta.append("\nJava class path:-" + System.getProperty("java.class.path").toString());
//ta.append("\nJava Library Path:-" + System.getProperty("java.library.path").toString());
ta.append("\n\n"+curpath);
length=ta.getText().length();
}

public void runJavaProgram(String cmd)
{
String cp=curpath.substring(0,curpath.length()-1);
String fileName=cmd.substring(5);
String str="";
String x=new String("\"");
if(fileName.indexOf(File.separator)==-1)
{
if(cp.length()==3)
{
compileandrun("java -cp "+x+cp.substring(0,2)+x+" "+fileName);
}
else
compileandrun("java -cp "+x+cp+x+" "+fileName);
}
else
{
ta.append("\n"+"Can not run in this way");
ta.append("\n"+curpath);
length=ta.getText().length();
}
}


public void compileAll(String cmd)
{
String cp=curpath.substring(0,curpath.length()-1);
String str=cp+File.separator+"*.java";
String x=new String("\"");
compileandrun("javac "+x+str+x);
}

public void compileJavaFile(String cmd)
{
String cp=curpath.substring(0,curpath.length()-1);
String fileName=cmd.substring(6);
String str="";

if(fileName.indexOf(File.separator)==-1)
{
str=cp+File.separator+fileName;
}
else
{
str=fileName;
}
File f=new File(str);
String x=new String("\"");
if(!f.exists())
{
ta.append("\n"+"File doesn't exists");
ta.append("\n"+curpath);
length=ta.getText().length();
}
else
{
compileandrun("javac "+x+str+x);
}
}

public void compileandrun(String str)
{
System.out.println("command 2 run:"+str);
String s="";
try
{
Process p = Runtime.getRuntime().exec(str);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
while ((s = stdInput.readLine()) != null)
{
ta.append("\n"+s);
}
while ((s = stdError.readLine()) != null)
{
ta.append("\n"+s);
}
}
catch(Exception e)
{
System.out.println("Exception in compilation"+e);
e.printStackTrace();
}
ta.append("\n"+curpath);
length=ta.getText().length();
}

public void deleteDirectory(String cmd)
{
String dirName=cmd.substring(4);
String cp=curpath.substring(0,curpath.length()-1);
String temp="";
if(dirName.indexOf(File.separator)==-1)
temp=cp+File.separator+dirName;
else
temp=dirName;
File path=new File(temp);
if(!path.exists())
{
ta.append("\n"+"Directory doesn't exists");
ta.append("\n"+curpath);
length=ta.getText().length();
}
else
{
ta.append("\n"+"Deleteing......");
try
{
deleteDir(path);
ta.append("\n"+"Deletion successful");
ta.append("\n"+curpath);
length=ta.getText().length();
}
catch(Exception e)
{
ta.append("\n"+"Can not delete this directory");
ta.append("\n"+curpath);
length=ta.getText().length();
}
}
}

public void deleteDir(File path) {
if (path.isDirectory())
{
File[] files = path.listFiles();
for(int i=0; i {
if(files[i].isDirectory())
{
deleteDir(files[i]);
}
else
{
files[i].delete();
}
}
}
path.delete();
}

public void makeDirectory(String cmd)
{
String dirName=cmd.substring(6);
String cp=curpath.substring(0,curpath.length()-1);
String str="";
if(dirName.indexOf(File.separator)==-1)
str=cp+File.separator+dirName;
else if(dirName.indexOf(File.separator)!=-1)
str=dirName;

File f=new File(str);
if(f.exists())
{
ta.append("\n"+"Directory Exists");
ta.append("\n"+curpath);
length=ta.getText().length();
}
else
{
try
{
f.mkdir();
if(f.exists())
{
ta.append("\n"+"Directory created");
ta.append("\n"+curpath);
length=ta.getText().length();
}
else
{
ta.append("\n"+"Directory can't be created");
ta.append("\n"+curpath);
length=ta.getText().length();
}
}
catch(Exception e)
{
System.out.println("can't create directory");
}
}

}


public void goToRoot()
{
String root=curpath.substring(0,3);
curpath=root+">";
ta.append("\n"+curpath);
length=ta.getText().length();
}

public void getParentDirectory()
{
if(curpath.length()>4)
{
String cp=curpath.substring(0,curpath.length()-1);
File f=new File(cp);
String parent=""+f.getParent();
curpath=parent+">";
ta.append("\n"+curpath);
length=ta.getText().length();
}
else
{
ta.append("\n"+curpath);
length=ta.getText().length();
}
}
public void showDirDetail()
{
String path=curpath.substring(0,curpath.length()-1);
int nof=0;
int nod=0;
float tfl=0;
long tdl=0;
File f=new File(path);
File[] list=f.listFiles();
ta.append("\n");
ta.append("Type:"+"\t"+"Size:"+"\t"+"\t"+"Name:");
for(int i=0;i{
ta.append("\n");
if(list[i].isDirectory())
{
//tdl+=getDirectorySize(list[i]);
ta.append(""+"\t"+"\t"+"\t"+list[i].getName());
nod++;
}
else
{
float length=0;
tfl+=list[i].length();
if(list[i].length()>9999)
{
length=list[i].length()/1024;
ta.append(""+"\t"+length+" KB"+"\t"+"\t"+list[i].getName());
}
else
ta.append(""+"\t"+list[i].length()+" bytes"+"\t"+"\t"+list[i].getName());
nof++;
}
}
ta.append("\n");
ta.append("Number of Files:"+nof+"\t"+" Total Length:"+tfl/(1024*1024)+" MB");
ta.append("\n");
ta.append("Number of Directories:"+nod);
//ta.append("\nTotal size iof this Directory:"+(tfl+tdl)/1024+" KB");
ta.append("\n"+curpath);
length=ta.getText().length();
}

public void showInfo()
{
ta.append("\n");
ta.append("*******************************************************************\n");
ta.append("Project Name: "+"Virtual Dos-Prompt\n");
ta.append("Creatred By: "+"Er. Milan Kumar\n");
ta.append("Version : "+"v1.0\n");
ta.append("Devoted to: "+"JAVA\n");
ta.append("*******************************************************************\n");
ta.append(curpath);
length=ta.getText().length();
}

public long getDirectorySize(File path)
{
long size=0;
File[] list=path.listFiles();
for(int i=0;i{
if(list[i].isFile())
size+=list[i].length();
else
getDirectorySize(list[i]);
}
return size;
}

public void changeDrive(String drive)
{
FileSystemView fsv=FileSystemView.getFileSystemView();
File f=new File(drive+File.separator);
if(fsv.isDrive(f))
{
curpath=drive+File.separator+">";
ta.append("\n"+curpath);
length=ta.getText().length();
}
else
{
ta.append("\n"+"No such drive on the system");
ta.append("\n"+curpath);
length=ta.getText().length();
}
}

public void changeDirectory(String cmd)
{
String str=cmd.substring(2).trim();
String cp=curpath.substring(0,curpath.length()-1);
boolean check=sfd(cp,str);
if(check==true)
{
if(curpath.length()>4)
curpath=cp+File.separator+str+">";
else
curpath=cp+str+">";
ta.append("\n"+curpath);
length=ta.getText().length();
}
else
{
ta.append("\nno such directory exits");
ta.append("\n"+curpath);
length=ta.getText().length();
}
}

public boolean sfd(String dir,String temp)
{
File f=new File(dir);
File ch[]=f.listFiles();
for(int i=0;i{
if(ch[i].getName().equalsIgnoreCase(temp) && ch[i].isDirectory())
return true;
}
return false;
}

public void showHelp()
{
ta.append("\n");
ta.append("--------------|------------------------------|-----------------------------\n");
ta.append(" COMMAND | MEANING | EXAMPLE\n");
ta.append("--------------|------------------------------|-----------------------------\n");
ta.append(" javac | Compile the java Program | javac Test.java\n");
ta.append(" javac *.java | Compile all the java files | javac *.java\n");
ta.append(" java | Run the .class file | java Test\n");
ta.append(" cls | Clear the screen | cls\n");
ta.append(" dir | shows the Directory | dir\n");
ta.append(" info | Shows the info of the prgm | info\n");
ta.append(" cd.. | Change Dir(Parent Dir) | cd..\n");
ta.append(" cd\\ | Change Dir to root | cd\\ \n");
ta.append(" mkdir | Make Directory | mkdir dirName or path\n");
ta.append(" del | Delete | del fileName,DirName,or Path\n");
ta.append(" bg | Background Color | bg red\n");
ta.append(" fg | Foreground COlor | fg black\n");
ta.append(" wv | White Video | wv\n");
ta.append(" nv | Normal Video | nv\n");
ta.append(" ov | Orange Video | ov\n");
ta.append(" yv | Yellow Video | yv\n");
ta.append(" gv | Green Video | gv\n");
ta.append(" rv | Red Video | rv\n");
ta.append(" cv | Cyan Video | cv\n");
ta.append(" grv | Gray Video | grv\n");
ta.append(" jinfo | Java Info | jinfo\n");
ta.append(" osinfo | Operating Sys Info | osinfo\n");
ta.append(" ? or help | Shows Help | ? or help\n");
ta.append(" create file | create file,ctrl+s to create | create file milan.txt\n");
ta.append(" ren | Rename file | ren name1.txt name2.txt\n");
ta.append("\n"+curpath);
length=ta.getText().length();
}

}//end inner class
}//end outer class

caution::i have compiled it with jdk1.7,so if you are having trouble recompile it with your version...........
some more commands are yet to be added in the next version....

Download vdp.jar

Download vdp.rar