GWT FocusPanel组件
GWT FocusPanel组件 介绍
FocusPanel组件代表一个简单的面板,使得其内容可调焦,并增加了能力,捕捉鼠标和键盘事件。
GWT FocusPanel组件 声明
以下是com.google.gwt.user.client.ui.FocusPanel类的声明
public class FocusPanel
extends SimplePanel
implements HasFocus, SourcesClickEvents,
SourcesMouseEvents, SourcesMouseWheelEvents,
HasAllMouseHandlers, HasClickHandlers,
HasDoubleClickHandlers, HasAllKeyHandlers,
HasAllFocusHandlers
GWT FocusPanel组件 构造方法
构造方法 | 描述 |
---|---|
FocusPanel() | 构建一个新的 FocusPanel。 |
FocusPanel(Widget child) | 使用给定的子小部件创建一个新的焦点面板。 |
GWT FocusPanel组件 方法
方法 | 描述 |
---|---|
HandlerRegistration addBlurHandler(BlurHandler handler) | 添加一个 BlurEvent 处理程序。 |
HandlerRegistration addClickHandler(ClickHandler handler) | 添加 ClickEvent 处理程序。 |
void addClickListener(ClickListener listener) | 已弃用。改用 addClickHandler (com.google.gwt.event.dom.client.ClickHandler) |
HandlerRegistration addDoubleClickHandler (DoubleClickHandler handler) | 添加 DoubleClickEvent 处理程序。 |
HandlerRegistration addFocusHandler(FocusHandler handler) | 添加一个 FocusEvent 处理程序。 |
void addFocusListener (FocusListener listener) | 已弃用。改用 addFocusHandler(com.google.gwt.event.dom.client.FocusHandler) |
void addKeyboardListener (KeyboardListener listener) | 已弃用。使用 addKeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)、addKeyUpHandler (com.google.gwt.event.dom.client.KeyUpHandler) 和 addKeyPressHandler (com.google.gwt.event.dom.client.KeyPressHandler) ) 反而 |
HandlerRegistration addKeyDownHandler (KeyDownHandler handler) | 添加 KeyDownEvent 处理程序。 |
HandlerRegistration addKeyPressHandler (KeyPressHandler handler) | 添加 KeyPressEvent 处理程序。 |
HandlerRegistration addKeyUpHandler (KeyUpHandler handler) | 添加 KeyUpEvent 处理程序。 |
HandlerRegistration addMouseDownHandler (MouseDownHandler handler) | 添加一个 MouseDownEvent 处理程序。 |
void addMouseListener(MouseListener listener) | 已弃用。使用 addMouseOverHandler (com.google.gwt.event.dom.client.MouseOverHandler), addMouseMoveHandler (com.google.gwt.event.dom.client.MouseMoveHandler), addMouseDownHandler (com.google.gwt.event.dom.client.MouseDownHandler) ),改为 addMouseUpHandler (com.google.gwt.event.dom.client.MouseUpHandler) 和 addMouseOutHandler (com.google.gwt.event.dom.client.MouseOutHandler) |
GWT FocusPanel组件 示例
1)修改HelloWorld.gwt.xml
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.0//EN"
"http://gwtproject.org/doctype/2.8.0/gwt-module.dtd">
<module rename-to="HelloWorld">
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. -->
<inherits name = 'com.google.gwt.user.theme.clean.Clean'/>
<!-- Specify the app entry point class. -->
<entry-point class='com.yiidian.helloWorld.client.HelloWorld'/>
<!-- Specify the app servlets. -->
<servlet path='/HelloWorldService' class='com.yiidian.helloWorld.server.HelloWorldServiceImpl'/>
<source path = 'client'/>
<source path = 'shared'/>
</module>
2)修改HelloWorld.css
body {
text-align: center;
font-family: verdana, sans-serif;
}
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
3)修改HelloWorld.html
<html>
<head>
<title>yiidian.com-GWT Hello World</title>
<link type="text/css" rel="stylesheet" href="HelloWorld.css">
<script type="text/javascript" language="javascript" src="HelloWorld/HelloWorld.nocache.js"></script>
</head>
<body>
<h1>FocusPanel Widget Demonstration</h1>
<div id = "gwtContainer"></div>
</body>
</html>
4)HelloWorld.java
package com.yiidian.helloWorld.client;
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.ui.*;
/**
* Entry point classes define <code>onModuleLoad()</code>
*/
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create text
HTML contents = new HTML("This is a FocusPanel."
+" Click on the panel and it will attain focus.");
//create focus panel with content
FocusPanel focusPanel = new FocusPanel(contents);
focusPanel.setSize("400px", "100px");
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(focusPanel);
// Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}
运行应用程序,显示结果如下:
热门文章
优秀文章