You can even save this information into a file, just give a path and click on "Save to file" button in order to save the quick calss help into a file
![]() |
Quick API reference for a class - GUI interface |
/**
* A quick help tool for a class
* @author Santhosh Reddy Mandadi
* @since 08-Sep-2007
* @version 1.0
*/
import java.awt.*;
import java.lang.reflect.*;
import java.awt.event.*;
import java.io.*;
public class ClassesHelp extends Frame implements ActionListener
{
Label l1,l2,l3,l4,l5,l6,l7,l8;
Button b,b1;
TextField tf1,tf2,tf3;
TextArea ta1,ta2,ta3,ta4;
Panel p1,p2,p3,p4,p5;
Class cl;
File file;
FileOutputStream fos;
String s;
public ClassesHelp(String str)
{
super(str);
setFont(new Font("Helvetica",Font.PLAIN,14));
setBackground(Color.cyan);
setForeground(Color.black);
l1=new Label("Class Name ");
l2=new Label(" Super Class ");
l3=new Label(" Constructors defined");
l4=new Label(" Methods ");
l5=new Label(" Fields ");
l6=new Label(" Interfaces implemented ");
l7=new Label("Classes Help");
l7.setFont(new Font("Helvetica",Font.PLAIN,18));
tf1=new TextField(30);
tf2=new TextField(30);
tf3=new TextField(60);
b=new Button("Submit");
b1=new Button(" Save to File ");
p1=new Panel();
p5=new Panel();
p1.setLayout(new FlowLayout());
p1.add(l1);
p1.add(tf1);
p1.add(b);
p5.setLayout(new FlowLayout());
p5.add(tf3);
p5.add(b1);
ta1=new TextArea(20,30);
ta4=new TextArea(20,30);
ta2=new TextArea(20,30);
ta3=new TextArea(20,50);
p2=new Panel();
p3=new Panel();
p4=new Panel();
p4.add(l7);
p3.add(l2);
p3.add(tf2);
p2.setLayout(new GridLayout(5,2,0,10));
p2.add(l3);
p2.add(ta1);
p2.add(l6);
p2.add(ta4);
p2.add(l4);
p2.add(ta2);
p2.add(l5);
p2.add(ta3);
setLayout(null);
p4.setBounds(1,20,700,45);
p1.setBounds(1,70,700,30);
p3.setBounds(1,105,700,50);
p2.setBounds(1,160,700,330);
p5.setBounds(1,510,700,50);
add(p4);
add(p1);
add(p3);
add(p2);
add(p5);
b.addActionListener(this);
b1.addActionListener(this);
b1.setEnabled(false);
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
ta1.setText("");
ta2.setText("");
ta3.setText("");
ta4.setText("");
Class c;
boolean flag=false;
try
{
cl=Class.forName(tf1.getText());
}
catch(Exception ex)
{
System.out.println(tf1.getText()+" Not Found.");
flag=true;
}
if (e.getSource()==b)
{
if(!flag)
{
System.out.println("Help For "+tf1.getText());
c=cl.getSuperclass();
if(c!=null)
{
tf2.setText(c.getName());
}
else
{
tf2.setText("No super class");
}
Constructor con[]=cl.getConstructors();
for(int i=0;i< con.length;i++)
{
Class pt[]=con[i].getParameterTypes();
ta1.setText(ta1.getText()+con[i].getName()+"(");
for(int j=0;j< pt.length;j++)
{
if (j==pt.length-1)
ta1.setText(ta1.getText()+pt[j].getName());
else
ta1.setText(ta1.getText()+pt[j].getName()+",");
}
ta1.setText(ta1.getText()+")"+System.getProperty("line.separator"));
}
Method m[]=cl.getMethods();
for(int i=0;i< m.length;i++)
{
Class rt=m[i].getReturnType();
Class pt[]=m[i].getParameterTypes();
ta2.setText(ta2.getText()+rt.getName()+" "+m[i].getName()+"(");
for(int j=0;j< pt.length;j++)
{
if (j==pt.length-1)
ta2.setText(ta2.getText()+pt[j].getName());
else
ta2.setText(ta2.getText()+pt[j].getName()+",");
}
ta2.setText(ta2.getText()+")"+System.getProperty("line.separator"));
}
Field f[]=cl.getFields();
for(int x=0;x< f.length;x++)
{
Class tc=f[x].getType();
ta3.setText(ta3.getText()+tc.getName()+" ");
ta3.setText(ta3.getText()+f[x].getName()+System.getProperty("line.separator"));
}
Class I[]=cl.getInterfaces();
for(int i=0;i< I.length;i++)
ta4.setText(ta4.getText()+I[i].getName()+System.getProperty("line.separator"));
b1.setEnabled(true);
s=new String("");
s+=cl.getName()+" classes Methods, Fields and Interfaces List:"+System.getProperty("line.separator");
s+="------------------------------------------------"+System.getProperty("line.separator");
s+="SuperClass : "+tf2.getText()+System.getProperty("line.separator");
s+="-----------------------------------------"+System.getProperty("line.separator");
s+="Constructors :"+System.getProperty("line.separator");
s+="--------------"+System.getProperty("line.separator");
s+=ta1.getText()+System.getProperty("line.separator");
s+="Interfaces :"+System.getProperty("line.separator");
s+="------------"+System.getProperty("line.separator");
s+=ta4.getText()+System.getProperty("line.separator");
s+="Mehtods :"+System.getProperty("line.separator");
s+="---------"+System.getProperty("line.separator");
s+=ta2.getText()+System.getProperty("line.separator");
s+="Fields :"+System.getProperty("line.separator");
s+="--------"+System.getProperty("line.separator");
s+=ta3.getText()+System.getProperty("line.separator");
s+="-------------------------------------------------"+System.getProperty("line.separator");
s+="Program Designed by Santhosh Reddy Mandadi"+System.getProperty("line.separator");
s+="-------------------------------------------------"+System.getProperty("line.separator");
//System.out.println(s);
}
}
else if (e.getSource()==b1)
{
file=new File(tf3.getText());
try
{
fos=new FileOutputStream(file);
fos.write(s.getBytes());
}catch(Exception exc)
{
System.out.println(e.toString());
}
}
}
public static void main(String args[])
{
ClassesHelp clh=new ClassesHelp("Give a Classname and Take a list of Methods, Fields and Interfaces");
clh.setSize(750,620);
clh.setVisible(true);
}
}