服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

实例讲解:开发swing的xml框架(1)

  简介
  现在,市场是紧缩的。框架可以节省设计和开发阶段的时间。ide可以使得我们更容易的开发用户接口。标准的gui应用程序用不同的面板布局来定义gui,已成为一种根本的模式而存在。基于这个模式,考虑使用框架来提高执行速度,达到更高的并行处理程度,协调更宽松的开发方式。我们在这里就要用java swing应用程序来描叙这么一个框架。
  
  简单的应用程序-图书馆管理系统
  我们下面来讨论一个简单的图书馆管理系统,用来理解基于xml的gui框架。

实例讲解:开发swing的xml框架(1)


  
  上面的流程图定义了图书馆用户接口的设计。主目录,会员登录,用户注册和书籍检索,这些都是应用
  程序中存在的面板(panel)。从流程图可以看出,在应用程序中可能的处理路径有下面几种:
  
  主目录->用户注册->书籍检索
  主目录->会员登录->书籍检索

  原则

  任何时候显示的面板依赖于先前面板的输出内容。因此,需要设计一个普通的控制器作为整个框架的窗体(form),它提供面板用来做必要的输入,并处理面板中期待返回的输出内容。这些面板都实现了xsfpanel接口,该接口中有个execute()方法用来将表单中的输入内容存入一个hashmap中,并从另一个hashmap返回输出内容。该框架的控制器处理使用hashmap返回的输出内容,并随时判断应该显示哪个面板。


  public interface xsfpanel extends jpanel
  {
   public hashmap execute(hashmap inputs);
   . . .
  }

  控制器和xml流定义
  流控制器和一个简单的定义着用户接口的xml相关联。这个xml必须基于每个面板输入的内容和料想会输出的内容而定义。我们这里讨论的这个简单的程序是基于下面的xml工作的。


  <xfsframework>

  <xfspanels>

    <xfspanel name="home" class="library.home">
      <inputs/>
      <outputs>
        <output variable="useroption"/>
      </outputs>
    </xfspanel>

    <xfspanel name="memberlogin" class="library.memberlogin">
      <inputs/>
      <outputs>
        <output variable="username"/>
        <output variable="password"/>
      </outputs>
    </xfspanel>

    <xfspanel name="registration" class="library.userregistration">
      <inputs/>
      <outputs>
        <output variable="username"/>
        <output variable="password"/>
        <output variable="emailid"/>
        <output variable="address"/>
      </outputs>
    </xfspanel>

 






    <xfspanel name="registrationpreview" class="library.userpreview">
      <inputs>
        <input variable="username"/>
        <input variable="emailid"/>
        <input variable="address"/>
      </inputs>
      <outputs/>
    </xfspanel>

    <xfspanel name="searchbook" class="library.searchbook">
      <inputs/>
      <outputs>
        <output variable="criterion"/>
        <output variable="searchvalue"/>
      </outputs>
    </xfspanel>
  </xfspanels>

  <xfspanelflow>
    <step id="s1" from="home" to="memberlogin">
      <conditions>
        <condition variable="useroption" value="login"/>
      </conditions>
    </step>
    <step id="s2" from="home" to="registration">
      <conditions>
        <condition variable="useroption" value="newregistration"/>
      </conditions>
    </step>
    <step id="s3" from="registration" to="registrationpreview">
      <conditions/>
    </step>
    <step id="s4" from="memberlogin" to="searchbook">
      <conditions>
        <condition variable="controller_loginresult" value="success"/>
      </conditions>
    </step>
    <step id="s5" from="registrationpreview" to="memberlogin">
      <conditions>
        <condition variable="controller_accountcreationresult" value="success"/>
      </conditions>
    </step>   

  </xfspanelflow>

  </xfsframework>

  注意:这个xml仅仅被用来描叙框架。

  在上面的xml中,提及到所有实现了xfspanel接口的面板。从一个面板出来的流信息到另一个面板。

  translated by caiyi0903(willpower),2004.5.23
 





扫描关注微信公众号