Here in this code getOutput() method returns the output of command executed in the command promt..!
JavaAPI.getOutput()--------->
public static String getOutput(String cmd){
String line;
String output = "";
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader input = new BufferedReader(new InputStreamReader
(p.getInputStream()));
while ((line = input.readLine()) != null) {
output += (line + '\n');
}
input.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
return output;
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class JavaAPI{
static TextArea ta=new TextArea("",30,100);
static TextField path=new TextField("C:\\Java\\jdk1.7.0_21\\bin",60);
static TextField pack=new TextField(60);
public static void main(java.lang.String arg[]){
Frame frame=new Frame("JavaAPI");
Panel panel=new Panel();
panel.setBackground(Color.green);
Button b=new Button("Finish");
frame.add(panel);
panel.add(new Label("Copy and paste JDK Path:"));
panel.add(path);
panel.add(new Label("Enter fully qualified package name eg: java.lang.String"));
panel.add(pack);
panel.add(new Label(""));
panel.add(ta);
panel.add(b);
b.addActionListener(new DisplayAPI());
Label l=new Label();
l.setText("ba-programmer.blogspot.com");
l.setFont(new Font("segoe print",Font.ITALIC,10));
ta.setFont(new Font("segoe print",Font.ITALIC,20));
panel.add(l);
frame.setSize(1500,800);
frame.setVisible(true);
}
static class DisplayAPI implements ActionListener{
public void actionPerformed(ActionEvent ae){
ta.setText(getOutput(path.getText()+"\\"+"javap"+" "+pack.getText()));
}
}
}
comment box is waiting for you...!
stay connected....!
No comments: