Author Topic: ZK Window ZUL XML 與 JAVA編程應用  (Read 4303 times)

Van Chan

  • Administrator
  • Newbie
  • *****
  • Posts: 7
    • View Profile
ZK Window ZUL XML 與 JAVA編程應用
« on: July 21, 2012, 05:03:44 PM »
這是一個Ajax應用 Sample03a.zul 和Sample03b.zul 都是做同樣事情, 由於ZK 提供兩種編程方式,第一種是純XML格式,第二種是XML+JAVA格式:
 
Sample03a.zul
--------------------
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<zk>
 <window id="win" title="ZK Window Property Control" width="400px" height="200px" border="normal" closable="true" sizable="true" >
     <button label="Change Window Title" onClick="win.title=&quot;ZK application with Ajax&quot;"/>
 </window>   
</zk>
Hints : 由於.zul文件是XML文件,使用雙引號字符("")時,必須轉換成 &quot; 才可以被XML解釋器正確地進行編譯


Sample03b.zul
--------------------
Code: [Select]
<?xml version="1.0" encoding="UTF-8"?>
<zk>
    <window id="win"  apply="inisoft.mo.gui.Sample03b"></window>
</zk>


Sample03b.java
--------------------
Code: [Select]
package inisoft.mo.gui;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.util.GenericForwardComposer;
import org.zkoss.zul.Button;
import org.zkoss.zul.Window;

/**
 * @author Van Chan
 */
public class Sample03b extends GenericForwardComposer{
    Window win;
    Button btn;
    EventListener btnListener;
   
    public void doAfterCompose(Component comp)throws Exception
    {
        super.doAfterCompose(comp);
        win.setTitle("ZK Window Property Control");
        win.setWidth("400px");
        win.setHeight("200px");
        win.setBorder("normal");
        win.setClosable(true);
        win.setSizable(true);
       
        btn=new Button();
        btn.setLabel("Change Window Title");
        addListener(btn);
       
        win.appendChild(btn);
    }
   
    public void addListener(Button btn){
        btnListener = new EventListener()
        {
            public void onEvent(Event event)throws Exception{
                win.setTitle("ZK application with Java");
            }
        };
        btn.addEventListener(Events.ON_CLICK, btnListener);
    }
}
« Last Edit: July 21, 2012, 05:12:17 PM by Van Chan »