- 浏览: 834271 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
贝塔ZQ:
读取excel文件,插件pageoffice也可以实现。
POI读写Excel文件(转)- - -
springmvc-freemarker:
java开源项目源码实例下载
java开源项目源代码 -
xuning2516:
第一种方法是个死循环啊。。。
Java NIO 拷贝文件(使用compact) -
u012046856:
...
SessionFactory.getCurrentSession与openSession的区别 -
Season_Wang:
赞一个呀,挺实用的
java swing 中的FileDialog
package treeroot.reflect; import java.util.List; public interface Node { int CLASS=0x10000; int INTERFACE=0x01000; int CONSTRUCTOR=0x00100; int METHOD=0x00010; int FIELD=0x00001; void setChilds(List childs); boolean hasChild(); List getChilds(); String getName(); String getDetail(); int getType(); //in order to sort int getOrder(); } package treeroot.reflect; import treeroot.reflect.Node; import java.util.List; import java.lang.reflect.Method; public class MethodNode implements Node { private int order; private Method m; public MethodNode(Method m){ this(m,0); } public MethodNode(Method m,int order){ this.m=m; this.order=order; } /** * Method setChilds * * * @param parm1 * */ public void setChilds(List parm1) { throw new UnsupportedOperationException("MothodNode has no child!"); // TODO: Add your code here } /** * Method hasChild * * * @return * */ public boolean hasChild() { return false; // TODO: Add your code here } /** * Method getChilds * * * @return * */ public List getChilds() { throw new UnsupportedOperationException("MothodNode has no child!"); // TODO: Add your code here } /** * Method getName * * * @return * */ public String getName() { return m.getName()+ Helper.getParams(getDetail()); // TODO: Add your code here } /** * Method getDetail * * * @return * */ public String getDetail() { return m.toString(); // TODO: Add your code here } /** * Method getType * * * @return * */ public int getType() { return METHOD; // TODO: Add your code here } /** * Method getOrder * * * @return * */ public int getOrder() { return order; // TODO: Add your code here } public String toString(){ return getName(); } } package treeroot.reflect; import treeroot.reflect.Node; import java.util.List; import java.lang.reflect.*; public class InterfaceNode implements Node { private Class c; private int order; private List childs; public InterfaceNode(Class c){ this(c,0); } public InterfaceNode(Class c,int order){ if(!c.isInterface()){ throw new RuntimeException("InterfaceNode must accept a Interface!"); } this.c=c; this.order=order; } /** * Method setChilds * * * @param parm1 * */ public void setChilds(List parm1) { this.childs=parm1; // TODO: Add your code here } /** * Method hasChild * * * @return * */ public boolean hasChild() { return (childs!=null)&&(childs.size()>0); // TODO: Add your code here } /** * Method getChilds * * * @return * */ public List getChilds() { return childs; // TODO: Add your code here } /** * Method getName * * * @return * */ public String getName() { return c.getName(); // TODO: Add your code here } /** * Method toString * * * @return * */ public String toString() { return "<html><i>"+getName()+"</i></html>"; // TODO: Add your code here } /** * Method getDetail * * * @return * */ public String getDetail() { StringBuffer sb=new StringBuffer(Modifier.toString(c.getModifiers())); sb.append(c.getName()); Class[] inters=c.getInterfaces(); if(inters.length>0){ sb.append(" implements "); for(int i=0;i<inters.length;i++){ sb.append(inters[i].getName()); sb.append(','); } sb.setLength(sb.length()-1); } return sb.toString(); // TODO: Add your code here } /** * Method getType * * * @return * */ public int getType() { return INTERFACE; // TODO: Add your code here } public int getOrder(){ return order; } } package treeroot.reflect; import treeroot.reflect.Node; import java.util.List; import java.lang.reflect.Modifier; import java.lang.reflect.Field; public class FieldNode implements Node { private int order; private int mode; private Field field; public FieldNode(Field field){ this(field,0); } public FieldNode(Field field,int order){ this.field=field; this.order=order; } /** * Method setChilds * * * @param parm1 * */ public void setChilds(List parm1) { throw new UnsupportedOperationException("Field can hava Child Nodes!"); // TODO: Add your code here } /** * Method hasChild * * * @return * */ public boolean hasChild() { return false; // TODO: Add your code here } /** * Method getChilds * * * @return * */ public List getChilds() { //you should call the hasChild() to test. throw new UnsupportedOperationException("Field can hava Child Nodes!"); // TODO: Add your code here } /** * Method getName * * * @return * */ public String getName() { return field.getName(); // TODO: Add your code here } /** * Method getDetail * * * @return * */ public String getDetail() { return field.toString(); // TODO: Add your code here } /** * Method getType * * * @return * */ public int getType() { return FIELD; // TODO: Add your code here } public int getOrder(){ return order; } public String toString(){ return getName(); } } package treeroot.reflect; import treeroot.reflect.Node; import java.util.List; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; public class ConstructorNode implements Node { private Constructor con; private int order; public ConstructorNode(Constructor con){ this(con,0); } public ConstructorNode(Constructor con,int order){ this.con=con; this.order=order; } /** * Method setChilds * * * @param parm1 * */ public void setChilds(List parm1) { throw new UnsupportedOperationException("ConstructorNode has no child!"); // TODO: Add your code here } /** * Method hasChild * * * @return * */ public boolean hasChild() { return false; // TODO: Add your code here } /** * Method getChilds * * * @return * */ public List getChilds() { throw new UnsupportedOperationException("ConstructorNode has no child!"); // TODO: Add your code here } /** * Method getName * * * @return * */ public String getName() { return con.getName()+ Helper.getParams(getDetail()); // TODO: Add your code here } /** * Method getDetail * * * @return * */ public String getDetail() { return con.toString(); // TODO: Add your code here } /** * Method getType * * * @return * */ public int getType() { return CONSTRUCTOR; // TODO: Add your code here } /** * Method getOrder * * * @return * */ public int getOrder() { return order; // TODO: Add your code here } public String toString(){ return getName(); } } package treeroot.reflect; import treeroot.reflect.Node; import java.util.List; import java.lang.reflect.*; public class ClassNode implements Node { private Class c; private int order; private List childs; public ClassNode(Class c){ this(c,0); } public ClassNode(Class c,int order){ if(c.isInterface()||c.isArray()||c.isPrimitive()){ throw new RuntimeException("ClassNode must accept a Class!"); } this.c=c; this.order=order; } /** * Method setChilds * * * @param parm1 * */ public void setChilds(List parm1) { this.childs=parm1; // TODO: Add your code here } /** * Method hasChild * * * @return * */ public boolean hasChild() { return (childs!=null)&&(childs.size()>0); // TODO: Add your code here } /** * Method getChilds * * * @return * */ public List getChilds() { return childs; // TODO: Add your code here } /** * Method getName * * * @return * */ public String getName() { return c.getName(); // TODO: Add your code here } /** * Method toString * * * @return * */ public String toString() { return "<html><b>"+getName()+"</b></html>";// TODO: Add your code here } /** * Method getDetail * * * @return * */ public String getDetail() { StringBuffer sb=new StringBuffer(Modifier.toString(c.getModifiers())); sb.append(" "); sb.append(c.getName()); Class superClass=c.getSuperclass(); if(superClass!=null){ sb.append(" extends "); sb.append(superClass.getName()); } Class[] inters=c.getInterfaces(); if(inters.length>0){ sb.append(" implements "); for(int i=0;i<inters.length;i++){ sb.append(inters[i].getName()); sb.append(','); } sb.setLength(sb.length()-1); } return sb.toString(); } /** * Method getType * * * @return * */ public int getType() { return CLASS; // TODO: Add your code here } public int getOrder(){ return order; } } package treeroot.reflect; class Helper { static String getParams(String s){ return s.substring(s.indexOf('('),s.indexOf(')')+1); } } package treeroot.reflect; import java.util.*; import java.lang.reflect.*; public class ClassMeta { public static Node getClassTree(Class c){ // Node root; if(c.isInterface()){ root=new InterfaceNode(c); } else{ root=new ClassNode(c); } List childs=new ArrayList(); //add super class as first node,if the class if Object.class,break recursion. //only Class has the superClass. Class superClass=c.getSuperclass(); if(superClass!=null) childs.add(getClassTree(superClass)); //add the inteferaces //Class or Interface must have the Interfaces Class[] inters= c.getInterfaces(); for(int i=0;i<inters.length;i++){ childs.add(getClassTree(inters[i])); } //add the constructors //Only Class have the Constructors. Constructor[] cons=c.getConstructors(); for(int i=0;i<cons.length;i++){ childs.add(new ConstructorNode(cons[i])); } //add the methods Method[] methods=c.getDeclaredMethods(); for(int i=0;i<methods.length;i++){ childs.add(new MethodNode(methods[i])); } //add the fields Field[] fields=c.getDeclaredFields(); for(int i=0;i<fields.length;i++){ childs.add(new FieldNode(fields[i])); } root.setChilds(childs); return root; } } //以下是图形界面了 package treeroot.classviewer; import treeroot.reflect.Node; import treeroot.reflect.ClassMeta; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.List; import java.util.*; import javax.swing.tree.*; import javax.swing.event.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.JScrollPane; public class ClassViewer extends JPanel { JTree tree; DefaultTreeModel model; JPanel detail=new JPanel(); JLabel lbl=new JLabel("the Detail Message"); private DefaultMutableTreeNode getRoot(Node node){ DefaultMutableTreeNode root=new DefaultMutableTreeNode(node); if(node.hasChild()){ List childs=node.getChilds(); for(int i=0;i<childs.size();i++){ root.add(getRoot((Node)childs.get(i))); } } return root; } public ClassViewer(){ DefaultMutableTreeNode root=getRoot(ClassMeta.getClassTree(Object.class)); model=new DefaultTreeModel(root); tree=new JTree(model); TreeSelectionModel selectModel =new DefaultTreeSelectionModel(); selectModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setSelectionModel(selectModel); tree.addTreeSelectionListener(new TreeSelectionListener(){ public void valueChanged(TreeSelectionEvent e){ DefaultMutableTreeNode node=(DefaultMutableTreeNode)tree.getLastSelectedPathComponent(); if(node!=null){ Node n=(Node)node.getUserObject(); lbl.setText(n.getDetail()); } } } ); this.setLayout(new BorderLayout()); this.add(new JScrollPane(tree),BorderLayout.CENTER); detail.add(lbl); this.add(detail,BorderLayout.SOUTH); } void setTree(Node treeRoot){ DefaultMutableTreeNode root=getRoot(treeRoot); model=new DefaultTreeModel(root); tree.setModel(model); this.updateUI(); } } package treeroot.classviewer; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.JOptionPane; import treeroot.reflect.*; import javax.swing.tree.*; public class MainFrame extends JFrame{ private JTextField txtClass=new JTextField("java.lang.Object",20); private JButton btnClass=new JButton("confirm"); private JPanel topPanel=new JPanel(); ClassViewer tree=new ClassViewer(); public MainFrame(){ this.setTitle("Class Viewer"); Toolkit kit=Toolkit.getDefaultToolkit(); Dimension d=kit.getScreenSize(); int width=d.width; int height=d.height; this.setLocation((width-WIDTH)/2,(height-HEIGHT)/2); this.setSize(WIDTH,HEIGHT); //this.setResizable(false); topPanel.add(txtClass); topPanel.add(btnClass); btnClass.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ Class c=null; try{ String cls=txtClass.getText().trim(); c=Class.forName(cls); } catch(ClassNotFoundException ex){ JOptionPane.showMessageDialog(null,"can find the class!"); return; } Node root=ClassMeta.getClassTree(c); tree.setTree(root); } } ); this.getContentPane().add(topPanel,BorderLayout.NORTH); this.getContentPane().add(tree,BorderLayout.CENTER); } public static void main(String[] args){ MainFrame main=new MainFrame(); //main.pack(); main.show(); } private static int WIDTH=800; private static int HEIGHT=600; }
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/treeroot/archive/2004/12/29/232826.aspx
相关推荐
基于java的浏览器的设计与实现课程设计.pdf基于java的浏览器的设计与实现课程设计.pdf基于java的浏览器的设计与实现课程设计.pdf基于java的浏览器的设计与实现课程设计.pdf基于java的浏览器的设计与实现课程设计.pdf...
java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java图片浏览器java...
java浏览器java浏览器java浏览器java浏览器简单的
Java编写的浏览器,很少有人用Java编写浏览器,此例子适合广大Javaers,代码解释详细,结构清晰,当然有不完善的地方,但很适合学习!~~
java 自制浏览器 java 自制浏览器 java 自制浏览器
用java模拟访问浏览网站的代码,可以输出各种网页属性,以及html源代码
java简易自制浏览器 java简易自制浏览器 java简易自制浏览器 java简易自制浏览器 java简易自制浏览器 java简易自制浏览器
开始---命令行--regedit ( 如果键值没有的时候,自己手动添加 ) 1.找到HKEY_CLASSES_ROOT\http\shell\open\command,双击"默认",将要用浏览器的可执行文件的完全路径输入到这里,例如...知道后我们使用java来操作注册表
java 内嵌浏览器 DJNativeSwing,可实现内嵌浏览器,提高用户体验。
这是目前最好的java嵌入浏览器的解决办法,做了个demo,放出整个工程,其中包含了所有平台的资源包和license,希望能帮助到你
Java 图片浏览器 源码,实现简单的图片浏览的功能,代码简洁,容易懂的。
java获取浏览器代理设置需要
java实现浏览器在线预览offic(doc、xls、ppt)和pdf文件,本人将例子集成到项目中,已成功。 技术原理:将文件先转换成pdf文件,再将pdf文件转换成swf文件,最后显示在浏览器上。 资源描述:本资源包括swftools...
Java版浏览器开发demo,内部有大量的基于Mozilla的测试例子。例子都是基于swing进行开发
Java网页浏览器 Lobo
JAVA 制作HTML浏览器JAVA 制作HTML浏览器JAVA 制作HTML浏览器
这是一款利用JAVA开发语言开发的网页浏览器实例,供学习用!附带源码!
java编写浏览器接口,可以自己编写一个属于自己的浏览器了
Java实现浏览器CA证书的签名和验证,讲述CA证书的生成方式和在java中的使用方法
java调用chrome浏览器内核,cef实现,非jxbrowser,非常不错