您的位置是: 软件 > 开发者网络 > 开发工具 > Java > 正文 查cseek报价

使用Java Swing创建一个XML编辑器之二
2001-09-24作者: wayne出处: yesky
我对此感兴趣
订阅电子杂志
发表评论
advertisement
热点推荐
· 群雄逐鹿 十四种Java开发工具点评
· 网文快捕,将网络资源搬回家
· Windows系统瘦身计划
· PS多媒体教程带你享受快乐学习
· 网络游戏外挂设计深度探索
· 武装你的桌面,桌面工具大阅兵

上一页  1 2 3 4  下一页



  接下来一步是创建一个叫 buildWelcomeTree()的方法。这个方法一次构建一个DefaultTreeModel变量,而不是通过分析一个现有的XML文字字符串。如果用户没有指定 XML文件就启动这个应用程序,将显示 DefaultTreeModel。见代码段1

  代码段1:

private DefaultTreeModel buildWelcomeTree()
{
 DefaultMutableTreeNode root;
 DefaultMutableTreeNode instructions, openingDoc,
             editingDoc, savingDoc;
 DefaultMutableTreeNode openingDocText, editingDocText,
             savingDocText;
 DefaultMutableTreeNode development, addingFeatures,
             contactingKyle;

 root = new DefaultMutableTreeNode( "Welcome to XML View 1.0" );
 instructions = new DefaultMutableTreeNode( "Instructions" );
 openingDoc = new DefaultMutableTreeNode
             ( "Opening XML Documents" );
 openingDocText = new DefaultMutableTreeNode
             ( "When invoking the XmlEditor from
 the command-line, you must specify the filename." );
 editingDoc = new DefaultMutableTreeNode
             ( "Editing an XML Document" );
 editingDocText = new DefaultMutableTreeNode
             ( "XML text in the right hand frame
             can be edited directly.
             The \"refresh\" button will rebuild
             the JTree in the left frame." );
 savingDoc = new DefaultMutableTreeNode
             ( "Saving an XML Document" );
 savingDocText = new DefaultMutableTreeNode
            ( "This iteration of the XmlEditor does
              not provide the ability to save your
              document. That will come with the
              next article." );
 root.add( instructions );
 instructions.add( openingDoc );
 instructions.add( editingDoc );
 openingDoc.add( openingDocText );
 editingDoc.add( editingDocText );
 return new DefaultTreeModel( root );
}

  接下来的我们需要添加一个新的构造程序来简化默认显示功能,我们将修改主构造程序,这样它就不能接受任何参数,创建一个新的能接收单一的 XML文本字符串的构造程序。这样以来,如果没有 XML文本被显示的话就会创建默认 XTree对象,而如果 XML文本被显示的话将创建一个唯一的 XTree对象。代码段2中给出了两个构造程序。

  代码段2:

public XTree( String text ) throws ParserConfigurationException
{
 this();
 refresh( text );
 }
public XTree() throws ParserConfigurationException
{
 super();
 getSelectionModel().setSelectionMode(
     TreeSelectionModel.SINGLE_TREE_SELECTION );
 setShowsRootHandles( true );
 setEditable( false );
 dbf = DocumentBuilderFactory.newInstance();
 dbf.setValidating( false );
 db = dbf.newDocumentBuilder();
 setModel( buildWelcomeTree() );
}

上一页  1 2 3 4  下一页


【责任编辑:方舟】
推荐给朋友我想参加相关培训打印我对此感兴趣订阅电子杂志发表评论

天极商业街
相关内容阅读排行榜
  • 等待是一种美丽
  • 半兽人的神话
  • 微软认为XBOX2没必要兼容XBOX
  • 日本发行新型限定版GameCube
  • 图谋低端市场 Sempron一门三杰再续辉煌
  • 密蜂大盗木马 开MM摄像头偷窥隐私
  • Win2000注册表的备份与恢复
  • 制作无人值守的Win XP安装光盘

  • advertisement