Friday, September 23, 2011

SIMPLE ZK CODE TO HANDLE MULTIPLE BUTTONS ON (.zul) FILE

OUTPUT IMAGE
-------------------------






.JAVA CLASS FILE
-----------------------

package classes;

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.util.Composer;
import org.zkoss.zul.Label;

public class MultipleEvents implements Composer, EventListener{
Component comp=null;
Label message;

@Override
public void doAfterCompose(Component comp) throws Exception {
this.comp=comp;
comp.getFellow("FIRST").addEventListener("onClick", this);
comp.getFellow("SECOND").addEventListener("onClick", this);
comp.getFellow("THIRD").addEventListener("onClick", this);
message=(Label) comp.getFellow("message");
}

@Override
public void onEvent(Event event) throws Exception {
if (event.getTarget().getId().equals("FIRST")){

message.setValue("hi, good morning");
}
if (event.getTarget().getId().equals("SECOND")){
message.setValue("how are you.");
}
if (event.getTarget().getId().equals("THIRD")){
message.setValue("Have a happy happy day.");
}

}

}
-------------------------------------------------------------------------

.ZUL FILE
---------------

------------------------------------------------------------


No comments:

Post a Comment