Searching...
Sunday, 23 September 2012

GWT Menu example

11:59
Here is one simple example to create GWT Menu, please follow below steps to create Menus

1. Create a GWT Project and update Entry point class with below code

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.MenuBar;
import com.google.gwt.user.client.ui.RootPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class PretechGWT implements EntryPoint {

@Override
public void onModuleLoad() {
Command cmd = new Command() {
public void execute() {
Window.alert("You selected a menu item!");
}
};
Label label = new Label("Hello World");
Button button = new Button("Click on this");

MenuBar pretechMenu = new MenuBar();

pretechMenu.addItem("Home", cmd);
pretechMenu.addItem("Frameworks", cmd);
pretechMenu.addItem("Java/J2ee",cmd);
pretechMenu.addItem("Mongodb",cmd);

button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("Hello good morning.. this message from event");
}
});
RootPanel.get().add(pretechMenu);
RootPanel.get().add(label);
RootPanel.get().add(button);
}
}

2. Run application

clip_image002

0 comments: