package com.zly.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.BlurEvent;
import com.google.gwt.event.dom.client.BlurHandler;
import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.dom.client.ErrorEvent;
import com.google.gwt.event.dom.client.ErrorHandler;
import com.google.gwt.event.dom.client.FocusEvent;
import com.google.gwt.event.dom.client.FocusHandler;
import com.google.gwt.event.dom.client.KeyDownEvent;
import com.google.gwt.event.dom.client.KeyDownHandler;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.event.dom.client.KeyPressHandler;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.event.dom.client.MouseMoveEvent;
import com.google.gwt.event.dom.client.MouseMoveHandler;
import com.google.gwt.event.dom.client.MouseOutEvent;
import com.google.gwt.event.dom.client.MouseOutHandler;
import com.google.gwt.event.dom.client.MouseOverEvent;
import com.google.gwt.event.dom.client.MouseOverHandler;
import com.google.gwt.event.dom.client.MouseUpEvent;
import com.google.gwt.event.dom.client.MouseUpHandler;
import com.google.gwt.event.dom.client.MouseWheelEvent;
import com.google.gwt.event.dom.client.MouseWheelHandler;
import com.google.gwt.event.dom.client.ScrollEvent;
import com.google.gwt.event.dom.client.ScrollHandler;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.SourcesTableEvents;
import com.google.gwt.user.client.ui.TableListener;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.TreeItem;
import com.google.gwt.user.client.ui.TreeListener;
import com.google.gwt.user.client.ui.Widget;
public class Test implements EntryPoint {
@SuppressWarnings ("deprecation" )
public void onModuleLoad() {
Label label = new Label("Change event example:" );
add(label);
final TextBox box = new TextBox();
RootPanel.get().add(box);
box.addChangeHandler(new ChangeHandler() {
public void onChange(ChangeEvent event) {
alert("change event occur" );
}
});
Label label2 = new Label("Click event example" );
add(label2);
final Button[] btns = new Button[5 ];
for (int i = 0 ; i < btns.length; i++) {
btns[i] = new Button("Button" + i);
add(btns[i]);
final Button btn = btns[i];
btns[i].addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
alert(btn.getText() + " " + " click event occur" );
}
});
}
Label label3 = new Label("Focus event example" );
add(label3);
final TextBox box2 = new TextBox();
add(box2);
box2.addFocusHandler(new FocusHandler() {
public void onFocus(FocusEvent event) {
box2.setText("got focus!" );
}
});
box2.addBlurHandler(new BlurHandler() {
public void onBlur(BlurEvent event) {
box2.setText("lost focus!" );
}
});
Label label4 = new Label("keyboard event example" );
add(label4);
TextBox box3 = new TextBox();
add(box3);
box3.addKeyDownHandler(new KeyDownHandler() {
public void onKeyDown(KeyDownEvent event) {
alert("you press " + (char )event.getNativeKeyCode() + " down" );
}
});
box3.addKeyPressHandler(new KeyPressHandler() {
public void onKeyPress(KeyPressEvent event) {
alert("you press " + event.getCharCode());
}
});
box3.addKeyUpHandler(new KeyUpHandler() {
public void onKeyUp(KeyUpEvent event) {
alert("you press " + (char )event.getNativeKeyCode() + " up" );
}
});
Label label5 = new Label("Image event example" );
add(label5);
final Image image = new Image("xx.jpg" );
add(image);
image.addLoadHandler(new LoadHandler() {
public void onLoad(LoadEvent event) {
}
});
image.addErrorHandler(new ErrorHandler() {
public void onError(ErrorEvent event) {
image.setTitle("no such image" );
}
});
HTML html = new HTML("<div></div>" );
html.setSize("300" , "300" );
DOM.setStyleAttribute(html.getElement(), "border" , "solid 1px" );
add(html);
html.addMouseOverHandler(new MouseOverHandler() {
public void onMouseOver(MouseOverEvent event) {
alert("mouse over" );
}
});
html.addMouseMoveHandler(new MouseMoveHandler() {
public void onMouseMove(MouseMoveEvent event) {
alert(event.getClientX() + ":" + event.getClientY());
}
});
html.addMouseOutHandler(new MouseOutHandler() {
public void onMouseOut(MouseOutEvent event) {
alert("mouse out" );
}
});
html.addMouseUpHandler(new MouseUpHandler() {
public void onMouseUp(MouseUpEvent event) {
alert("mouse up" );
}
});
ScrollPanel panel = new ScrollPanel();
panel.setSize("100" , "30" );
panel.add(new Label("This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label.This is a label." ));
add(panel);
panel.addScrollHandler(new ScrollHandler() {
public void onScroll(ScrollEvent event) {
box.setText("Scorll!!!" );
}
});
TextArea area = new TextArea();
area.setSize("150" , "150" );
area.setValue("This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value.This is value." );
area.addMouseWheelHandler(new MouseWheelHandler() {
public void onMouseWheel(MouseWheelEvent event) {
alert("mouse wheel occur!" );
}
});
add(area);
final Grid grid = new Grid(3 , 3 );
for (int i = 0 ; i < 3 ; i++) {
for (int j = 0 ; j < 3 ; j++) {
grid.setText(i, j, "Cell(" + i + " , " + j + ")" );
}
}
grid.setBorderWidth(1 );
add(grid);
grid.addTableListener(new TableListener() {
public void onCellClicked(SourcesTableEvents sender, int row,
int cell) {
DOM.setStyleAttribute(((Grid)(sender)).getCellFormatter().getElement(row, cell), "border" , "3px solid #f00" );
}
});
Tree tree = new Tree();
tree.addItem("Item1" );
tree.addItem("Item2" );
tree.addItem("Item3" );
tree.addItem("Item4" );
tree.addTreeListener(new TreeListener() {
public void onTreeItemSelected(TreeItem item) {
alert(item.getText() + " selected" );
}
public void onTreeItemStateChanged(TreeItem item) {
alert(item.getText() + " changed" );
}
});
add(tree);
}
public void add(Widget element) {
RootPanel.get().add(element);
}
public void alert(String src) {
Window.alert(src);
}
public String getEventType(DomEvent<?> event) {
return event.toString();
}
}
posted @
2014-03-14 15:46
郑文亮
阅读(
1232 )
评论()
编辑
收藏
举报