import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Myjavap implements ActionListener
{
JFrame mainFrame;
JPanel upperPanel;
JPanel lowerPanel;
JTextField textField;
JTextArea textArea;
JScrollPane sp;
JLabel intro;
int flag=0;
String mod="";
String fields="";
String superclass="";
String interfaces="";
String constructors="";
String methods="";
String finalinf="";
Myjavap()
{
mainFrame=new JFrame("MyjavapTool ~~~~~Milan~~~~~");
upperPanel=new JPanel();
textField=new JTextField("java.awt.Color");
intro=new JLabel("Enter the class name to find its content(press enter):",JLabel.CENTER);
upperPanel.setLayout(new GridLayout(2,1));
textField.requestFocus();
textField.setFont(new Font("Comic Sams MS",Font.PLAIN,15));
upperPanel.add(intro);
upperPanel.add(textField);
lowerPanel=new JPanel(new BorderLayout());
textArea=new JTextArea();
textArea.setEditable(false);
textArea.setLineWrap(true);
textArea.setFont(new Font("Comic Sams MS",Font.PLAIN,15));
sp=new JScrollPane(textArea);
lowerPanel.add(sp);
mainFrame.add(upperPanel,BorderLayout.NORTH);
mainFrame.add(lowerPanel,BorderLayout.CENTER);
mainFrame.setSize(700,600);
mainFrame.setVisible(true);
mainFrame.setLocation(150,75);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
textField.addActionListener(this);
}
public static void main(String... s)
{
new Myjavap();
}
public void actionPerformed(ActionEvent e)
{
flag=0;
try
{
Class c=Class.forName(textField.getText());
textArea.setText(getClassInformation(c));
textArea.setCaretPosition(0);
}
catch(Exception p)
{
System.out.println("ok error"+p);
JOptionPane.showMessageDialog(null,"Entered class Doesn't exist..", "Error",JOptionPane.ERROR_MESSAGE);
}
}
public String getClassInformation(Class c)
{
mod=getClassModifiers(c);
if(flag==0)
{
superclass=getClassSuperClass(c);
}
interfaces=getClassInterfaces(c,flag);
fields=getClassFields(c);
if(flag==0)
{
constructors=getClassConstructors(c);
}
methods=getClassMethods(c);
if(flag==0)
finalinf=mod+" "+superclass+interfaces+"\n"+"{"+"\n"+fields+constructors+methods+"}";
else
finalinf=mod+" "+c.getName()+" "+interfaces+"\n"+"{"+"\n"+fields+methods+"}";
return finalinf;
}
public String getClassModifiers(Class temp)
{
int m=temp.getModifiers();
if(Modifier.isInterface(m))
{
flag++;
}
return (Modifier.toString(m));
}
public String getClassSuperClass(Class c)
{
Class tmp=c.getSuperclass();
String str="";
str="class "+c.getName()+" extends "+tmp.getName();
return str;
}
public String getClassInterfaces(Class c,int flag)
{
String str="";
String temp="";
Class inter[]=c.getInterfaces();
for(int i=0;i
temp=temp+" "+inter[i].getName()+",";
}
if(flag==0 && inter.length>0)
{
str=str+" implements"+temp;
}
else
{
if(inter.length>0)
str=str+" extends"+temp;
}
return str;
}
public String getClassFields(Class c)
{
String tmp="";
Field f[]=c.getDeclaredFields();
for(int i=0;i
Class type=f[i].getType();
int m=f[i].getModifiers();
tmp+=Modifier.toString(m)+" "+type.getName()+" "+f[i].getName()+";"+"\n";
}
return tmp;
}
public String getClassConstructors(Class c)
{
Constructor cs[]=c.getDeclaredConstructors();
String temp="";
String temp1="";
for(int i=0;i
int m=cs[i].getModifiers();
temp=temp+Modifier.toString(m)+" "+cs[i].getName()+"(";
Class type[]=cs[i].getParameterTypes();
temp1="";
for(int k=0;k
temp1=temp1+type[k].getName()+",";
}
temp=temp+temp1+")"+";"+"\n";
}
return temp;
}
public String getClassMethods(Class c)
{
Method m[]=c.getDeclaredMethods();
String temp="";
String temp1="";
String temp2="";
String st="throws";
for(int i=0;i
int r=m[i].getModifiers();
temp=temp+Modifier.toString(r)+" "+m[i].getReturnType().getName()+" "+m[i].getName()+"(";
Class type[]=m[i].getParameterTypes();
temp1="";
for(int k=0;k
temp1=temp1+type[k].getName()+",";
}
temp=temp+temp1+")"+";"+"\n";
}
return temp;
}
}//end class
Download
0 comments:
Post a Comment