实现SourcesMouseEvents : 鼠标监听 « GWT « Java

En
Java
1. 图形用户界面
2. 三维图形动画
3. 高级图形
4. 蚂蚁编译
5. Apache类库
6. 统计图
7. 
8. 集合数据结构
9. 数据类型
10. 数据库JDBC
11. 设计模式
12. 开发相关类
13. EJB3
14. 电子邮件
15. 事件
16. 文件输入输出
17. 游戏
18. 泛型
19. GWT
20. Hibernate
21. 本地化
22. J2EE平台
23. 基于J2ME
24. JDK-6
25. JNDI的LDAP
26. JPA
27. JSP技术
28. JSTL
29. 语言基础知识
30. 网络协议
31. PDF格式RTF格式
32. 映射
33. 常规表达式
34. 脚本
35. 安全
36. Servlets
37. Spring
38. Swing组件
39. 图形用户界面
40. SWT-JFace-Eclipse
41. 线程
42. 应用程序
43. Velocity
44. Web服务SOA
45. 可扩展标记语言
Java 教程
Java » GWT » 鼠标监听屏幕截图 
实现SourcesMouseEvents

package com.java2s.gwt.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.KeyboardListenerAdapter;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.MouseListener;
import com.google.gwt.user.client.ui.MouseListenerCollection;
import com.google.gwt.user.client.ui.RadioButton;
import com.google.gwt.user.client.ui.SourcesMouseEvents;
import com.google.gwt.user.client.ui.TextArea;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.MouseListenerAdapter;
import com.google.gwt.user.client.rpc.IsSerializable;

public class GWTClient implements EntryPoint{
  public void onModuleLoad() {
    final UserWidget userWidget = new UserWidget();
    userWidget.addMouseListener(new MouseListenerAdapter() {            
       public void onMouseEnter(Widget sender)
       {
           userWidget.addStyleName("userWidget-focus");
       }
       public void onMouseLeave(Widget sender)
       {
           userWidget.removeStyleName("userWidget-focus");               
       }
    });

    RootPanel.get().add(userWidget);
  }
}

class UserWidget extends VerticalPanel implements SourcesMouseEvents {
    TextBox firstName = new TextBox();
    TextBox lastName = new TextBox();
    TextBox address = new TextBox();
    TextBox city = new TextBox();
    TextBox postalCode = new TextBox();
    ListBox country = new ListBox();
    ListBox stateProvince = new ListBox();
    TextArea comments = new TextArea();
    CheckBox sendMeSpam = new CheckBox();
    RadioButton htmlSpam = new RadioButton("radioGroup""HTML");
    RadioButton textSpam = new RadioButton("radioGroup""Plain Text");
    Grid table = new Grid(112);
    Button submit = new Button("Submit");
    User user = new User();
    MouseListenerCollection listeners;

    public UserWidget() {
        super();
        this.setStyleName("userWidget");
        postalCode.addKeyboardListener(new KeyboardListenerAdapter() {
                public void onKeyPress(Widget sender, char keyCode,
                    int modifiers) {
                    if (!Character.isDigit(keyCode)) {
                        ((TextBoxsender).cancelKey();
                    }
                }
            });
        
        country.addItem("United States""US");
        
        stateProvince.addItem("Alabama""AL");
        stateProvince.addItem("Alaska""AK");
        stateProvince.addItem("American Samoa""AS");
        
        htmlSpam.setChecked(true);

        VerticalPanel spamChoicePanel = new VerticalPanel();
        spamChoicePanel.add(htmlSpam);
        spamChoicePanel.add(textSpam);
        
        submit.addClickListener(new ClickListener() {
                public void onClick(Widget sender) {
                    user.firstName = firstName.getText();
                    user.lastName = lastName.getText();
                    user.address = address.getText();
                    user.city = city.getText();
                    user.postalCode = postalCode.getText();
                    user.country = country.getValue(country.getSelectedIndex());
                    user.stateProvince = stateProvince.getValue(stateProvince.getSelectedIndex());
                    user.comments = comments.getText();
                    user.sendMeSpam = sendMeSpam.isChecked();

                    if (htmlSpam.isChecked()) {
                        user.htmlSpam = true;
                    }

                    Window.alert("User is currently set as - \n" +
                        user.toString());
                }
            });

        table.setWidget(00new Label("First Name"));
        table.setWidget(01, firstName);
        table.setWidget(10new Label("Last Name"));
        table.setWidget(11, lastName);
        table.setWidget(20new Label("Address"));
        table.setWidget(21, address);
        table.setWidget(30new Label("City"));
        table.setWidget(31, city);
        table.setWidget(40new Label("State/Province"));
        table.setWidget(41, stateProvince);
        table.setWidget(50new Label("PostalCode/Zip"));
        table.setWidget(51, postalCode);
        table.setWidget(60new Label("Country"));
        table.setWidget(61, country);
        table.setWidget(70new Label("Comments"));
        table.setWidget(71, comments);
        table.setWidget(80new Label("Sign Up For Our Email List!"));
        table.setWidget(81, sendMeSpam);
        table.setWidget(90new Label("Email Format:"));
        table.setWidget(91, spamChoicePanel);
        table.setWidget(100, submit);
        table.setWidget(101null);

        Label label = new Label("Enter User Information");
        this.add(label);
        this.add(table);

        sinkEvents(Event.MOUSEEVENTS);
    }

    public void onBrowserEvent(Event event) {
        int eventType = DOM.eventGetType(event);
        switch (eventType) {
        case Event.ONMOUSEOVER: 
            if (listeners != null) {
                listeners.fireMouseEnter(this);
            }
            break;
        case Event.ONMOUSEOUT:
            if (listeners != null) {
                listeners.fireMouseLeave(this);
            }
            break;        
        }
    }

    public void addMouseListener(MouseListener listener) {
        if (listeners == null) {
            listeners = new MouseListenerCollection();
        }
        listeners.add(listener);
    }

    public void removeMouseListener(MouseListener listener) {
        if (listeners != null) {
            listeners.remove(listener);
        }
    }
}

class User implements IsSerializable {
    String firstName;
    String lastName;
    String address;
    String city;
    String stateProvince;
    String postalCode;
    String country;
    String comments;
    boolean sendMeSpam;
    boolean htmlSpam;    

    public String toString() {
        StringBuffer sb = new StringBuffer();
        sb.append(" User:");
        sb.append(" [firstName] " + firstName + "\n");
        sb.append(" [lastName] " + lastName + "\n");
        sb.append(" [address] " + address + "\n");
        sb.append(" [city] " + city + "\n");
        sb.append(" [stateProvince] " + stateProvince + "\n");
        sb.append(" [postalCode] " + postalCode + "\n");
        sb.append(" [country] " + country + "\n");
        sb.append(" [comments] " + comments + "\n");
        sb.append(" [sendMeSpam] " + sendMeSpam + "\n");
        sb.append(" [htmlSpam] " + htmlSpam + "\n");
        return sb.toString();
    }
}




           
       
GWT-fillUserObjectToForm.zip( 4 k)
Related examples in the same category
1. Work with mouse Listener
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.