Free Essay

Gwt Tutorial

In: Computers and Technology

Submitted By fener33
Words 14136
Pages 57
Google Web Toolkit Tutorial

GOOGLE WEB TOOLKIT TUTORIAL

Simply Easy Learning by tutorialspoint.com

tutorialspoint.com i COPYRIGHT& DISCLAIMER NOTICE

All

the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com.Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors andtutorialspointprovidesno guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at webmaster@tutorialspoint.com

ii

ABOUT THE TUTORIAL

GWT Tutorial
Google Web Toolkit (GWT) is a development toolkit for building and optimizing complex browser-based applications. GWT is used by many products at Google, including Google AdWords and Orkut. GWT is open source, completely free, and used by thousands of developers around the world. It is licensed under the Apache License version 2.0. This tutorial will give you great understanding on GWT concepts needed to get a web application up and running.

Audience
This tutorial is designed for Software Professionals who are willing to learn GWT Programming in simple and easy steps. This tutorial will give you great understanding on GWT Programming concepts and after completing this tutorial you will be at intermediate level of experties from where you can take yourself at higher level of expertise.

Prerequisites
Before proceeding with this tutorial you should have a basic understanding of Java programming language, text editor and execution of programs etc. Because we are going to develop web based applications usin GWT, so it will be good if you have understanding on other web technologies like, HTML, CSS, AJAX etc.

Copyright & Disclaimer Notice
All
the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at webmaster@tutorialspoint.com

iii

T able of Contents
GWT Tutorial ............................................................................ iii Audience .................................................................................. iii Prerequisites ............................................................................ iii Copyright & Disclaimer Notice .................................................. iii GWTOverview .......................................................................... 1
What is GWT? .............................................................................................. 1 Why to use GWT?......................................................................................... 1 Disadvantages of GWT .............................................................................. 2 The GWT Components .................................................................................. 2

Environment ............................................................................. 3
System Requirement ................................................................................. 3 Step 1 - Verify Java installation on your machine ...................................... 3 Step 2 - Setup Java Development Kit (JDK): ............................................. 4 Step 3 - Setup Eclipse IDE ........................................................................ 4 Step 4: Install GWT SDK & Plugin for Eclipse ........................................... 5 Step 5: Setup Apache Tomcat: .................................................................. 6

Applications .............................................................................. 8
Module Descriptors .................................................................................... 8 Public resources ...................................................................................... 10 Client-side code ....................................................................................... 10 Server-side code...................................................................................... 11

Create Application .................................................................. 12
Step 1 - Create Project .......................................................................... 12 Step 2 - Modify Module Descriptor: HelloWorld.gwt.xml .......................... 15 Step 3 - Modify Style Sheet: HelloWorld.css............................................ 15 Step 4 - Modify Host File: HelloWorld.html .............................................. 16 Step 5 - Modify Entry Point: HelloWorld.java ........................................... 16 Step 6 - Compile Application.................................................................... 16 Step 6 - Run Application .......................................................................... 18

Deploy Application ................................................................. 20
Create WAR File ...................................................................................... 22 Deploy WAR file....................................................................................... 22 iii Run Application........................................................................................ 22

Style with CSS ....................................................................... 24
CSS Styling APIs ..................................................................................... 24 Primary & Secondary Styles .................................................................... 25 Associating CSS Files ............................................................................. 26 GWT CSS Example ................................................................................. 26

Basic Widgets ........................................................................ 30
GWT UI Elements: ................................................................................... 30 GWT UIObject Class ............................................................................... 31 Introduction .............................................................................................. 31 Class declaration ..................................................................................... 31 Field ......................................................................................................... 31 Class constructors ................................................................................... 31 Class methods ......................................................................................... 31 Methods inherited .................................................................................... 33 GWT Widget Class .................................................................................. 34 Introduction .............................................................................................. 34 Class declaration ..................................................................................... 34 Field ......................................................................................................... 34 Class constructors ................................................................................... 34 Class methods ......................................................................................... 34 Methods inherited .................................................................................... 35 Basic Widgets .......................................................................................... 35 Label ........................................................................................................ 36 Introduction .............................................................................................. 36 Class declaration ..................................................................................... 36 CSS style rules ........................................................................................ 36 Class constructors ................................................................................... 36 Class methods ......................................................................................... 36 Methods inherited .................................................................................... 37 Label Widget Example ............................................................................. 37 HTML ....................................................................................................... 40 Introduction .............................................................................................. 40 Class declaration ..................................................................................... 40 CSS style rules ........................................................................................ 40 Class constructors ................................................................................... 40 Class methods ......................................................................................... 41 Methods inherited .................................................................................... 41 Html Widget Example .............................................................................. 41 iii IMAGE ..................................................................................................... 43 Introduction .............................................................................................. 43 Class declaration ..................................................................................... 44 CSS style rules ........................................................................................ 44 Class constructors ................................................................................... 44 Class methods ......................................................................................... 44 Methods inherited .................................................................................... 45 Image Widget Example ............................................................................ 45 ANCHOR ................................................................................................. 47 Introduction .............................................................................................. 47 Class declaration ..................................................................................... 47 CSS style rules ........................................................................................ 48 Class constructors ................................................................................... 48 Class methods ......................................................................................... 48 Methods inherited .................................................................................... 49 Anchor Widget Example .......................................................................... 49

Form Widgets ......................................................................... 52
Form Widgets .......................................................................................... 52 Introduction .............................................................................................. 53 Class declaration ..................................................................................... 53 CSS style rules ........................................................................................ 53 Class constructors ................................................................................... 53 Class methods ......................................................................................... 54 Methods inherited .................................................................................... 54 Button Widget Example ........................................................................... 54 Introduction .............................................................................................. 57 Class declaration ..................................................................................... 57 CSS style rules ........................................................................................ 57 Class constructors ................................................................................... 57 Class methods ......................................................................................... 58 Methods inherited .................................................................................... 58 PushButton Widget Example ................................................................... 59 Introduction .............................................................................................. 62 Class declaration ..................................................................................... 62 CSS style rules ........................................................................................ 62 Class constructors ................................................................................... 62 Class methods ......................................................................................... 63 Methods inherited .................................................................................... 63 ToggleButton Widget Example ................................................................ 63 iii Introduction .............................................................................................. 66 Class declaration ..................................................................................... 66 CSS style rules ........................................................................................ 66 Class constructors ................................................................................... 66 Class methods ......................................................................................... 66 Methods inherited .................................................................................... 67 CheckBox Widget Example ..................................................................... 68 Introduction .............................................................................................. 70 Class declaration ..................................................................................... 70 CSS style rules ........................................................................................ 71 Class constructors ................................................................................... 71 Class methods ......................................................................................... 71 Methods inherited .................................................................................... 71 RadioButton Widget Example .................................................................. 71 Introduction .............................................................................................. 74 Class declaration ..................................................................................... 74 CSS style rules ........................................................................................ 74 Class constructors ................................................................................... 75 Class methods ......................................................................................... 75 Methods inherited .................................................................................... 76 ListBox Widget Example .......................................................................... 76 Introduction .............................................................................................. 79 Class declaration ..................................................................................... 79 CSS style rules ........................................................................................ 80 Class constructors ................................................................................... 80 Class methods ......................................................................................... 80 Methods inherited .................................................................................... 82 Introduction .............................................................................................. 86 Class declaration ..................................................................................... 86 CSS style rules ........................................................................................ 86 Class constructors ................................................................................... 86 Class methods ......................................................................................... 86 Methods inherited .................................................................................... 87 TextBox Widget Example......................................................................... 87 Introduction .............................................................................................. 89 Class declaration ..................................................................................... 89 CSS style rules ........................................................................................ 90 Class constructors ................................................................................... 90 Class methods ......................................................................................... 90 iii Methods inherited .................................................................................... 90 PasswordTextBox Widget Example ......................................................... 90 Introduction .............................................................................................. 93 Class declaration ..................................................................................... 93 CSS style rules ........................................................................................ 93 Class constructors ................................................................................... 93 Class methods ......................................................................................... 93 Methods inherited .................................................................................... 94 TextBox Widget Example......................................................................... 94 Introduction .............................................................................................. 97 Class declaration ..................................................................................... 97 CSS style rules ........................................................................................ 97 Class constructors ................................................................................... 97 Class methods ......................................................................................... 97 Methods inherited .................................................................................... 98 RichTextBox Widget Example ................................................................. 98 Introduction ............................................................................................ 101 Class declaration ................................................................................... 101 CSS style rules ...................................................................................... 101 Class constructors ................................................................................. 101 Class methods ....................................................................................... 101 Methods inherited .................................................................................. 102 FileUpload Widget Example................................................................... 102 Introduction ............................................................................................ 106 Class declaration ................................................................................... 107 Class constructors ................................................................................. 107 Methods inherited .................................................................................. 107 Hidden Widget Example ........................................................................ 108

Complex Widgets ................................................................. 111
Complex Widgets................................................................................... 111 Introduction ............................................................................................ 112 Class declaration ................................................................................... 112 CSS style rules ...................................................................................... 112 Class constructors ................................................................................. 112 Class methods ....................................................................................... 112 Methods inherited .................................................................................. 114 Tree Widget Example ............................................................................ 115 Introduction ............................................................................................ 118 Class declaration ................................................................................... 119 iii CSS style rules ...................................................................................... 119 Class constructors ................................................................................. 119 Class methods ....................................................................................... 120 Methods inherited .................................................................................. 121 MenuBar Widget Example ..................................................................... 122 Introduction ............................................................................................ 127 Class declaration ................................................................................... 127 CSS style rules ...................................................................................... 128 Class constructors ................................................................................. 128 Class methods ....................................................................................... 128 Methods inherited .................................................................................. 130 DatePicker Widget Example .................................................................. 130 Introduction ............................................................................................ 135 Class declaration ................................................................................... 135 Class constructors ................................................................................. 136 Class methods ....................................................................................... 136 Methods inherited .................................................................................. 137 CellTree Widget Example ...................................................................... 137 Introduction ............................................................................................ 144 Class declaration ................................................................................... 144 Class constructors ................................................................................. 144 Class methods ....................................................................................... 144 Methods inherited .................................................................................. 145 CellList Widget Example ........................................................................ 145 Introduction ............................................................................................ 149 Class declaration ................................................................................... 149 Class constructors ................................................................................. 149 Class methods ....................................................................................... 150 Methods inherited .................................................................................. 151 CellTable Widget Example .................................................................... 151 Introduction ............................................................................................ 155 Class declaration ................................................................................... 155 Class constructors ................................................................................. 156 Class methods ....................................................................................... 156 Methods inherited .................................................................................. 156 CellBrowser Widget Example ................................................................ 157

Layout Panels ...................................................................... 164
Introduction ............................................................................................ 164 Class declaration ................................................................................... 164 iii Field ....................................................................................................... 165 Class constructors ................................................................................. 165 Class methods ....................................................................................... 165 Methods inherited .................................................................................. 165 Layout Panels ........................................................................................ 166 Introduction ............................................................................................ 167 Class declaration ................................................................................... 167 Class constructors ................................................................................. 167 Class methods ....................................................................................... 167 Methods inherited .................................................................................. 168 FlowPanel Widget Example ................................................................... 168 Introduction ............................................................................................ 170 Class declaration ................................................................................... 170 Class constructors ................................................................................. 171 Class methods ....................................................................................... 171 Methods inherited .................................................................................. 171 HorizontalPanel Widget Example .......................................................... 172 Introduction ............................................................................................ 174 Class declaration ................................................................................... 174 Class constructors ................................................................................. 174 Class methods ....................................................................................... 174 Methods inherited .................................................................................. 175 VerticalPanel Widget Example............................................................... 175 Introduction ............................................................................................ 178 Class declaration ................................................................................... 178 CSS style rules ...................................................................................... 178 Class constructors ................................................................................. 178 Class methods ....................................................................................... 178 Methods inherited .................................................................................. 179 HorizontalSplitPanel Widget Example ................................................... 180 Introduction ............................................................................................ 182 Class declaration ................................................................................... 182 CSS style rules ...................................................................................... 183 Class constructors ................................................................................. 183 Class methods ....................................................................................... 183 Methods inherited .................................................................................. 184 VerticalSplitPanel Widget Example........................................................ 184 Introduction ............................................................................................ 187 Class declaration ................................................................................... 187 iii Class constructors ................................................................................. 187 Class methods ....................................................................................... 187 Methods inherited .................................................................................. 188 FlexTable Widget Example .................................................................... 188 Introduction ............................................................................................ 192 Class declaration ................................................................................... 192 Class constructors ................................................................................. 192 Class methods ....................................................................................... 192 Methods inherited .................................................................................. 193 Grid Widget Example ............................................................................. 193 Introduction ............................................................................................ 195 Class declaration ................................................................................... 195 Class constructors ................................................................................. 195 Class methods ....................................................................................... 195 Methods inherited .................................................................................. 196 DeckPanel Widget Example .................................................................. 196 Introduction ............................................................................................ 199 Class declaration ................................................................................... 199 Class constructors ................................................................................. 200 Class methods ....................................................................................... 200 Methods inherited .................................................................................. 200 DockPanel Widget Example .................................................................. 201 Introduction ............................................................................................ 203 Class declaration ................................................................................... 204 Class constructors ................................................................................. 204 Class methods ....................................................................................... 204 Methods inherited .................................................................................. 204 HTMLPanel Widget Example ................................................................. 205 Introduction ............................................................................................ 207 Class declaration ................................................................................... 207 Class constructors ................................................................................. 208 Class methods ....................................................................................... 208 Methods inherited .................................................................................. 210 TabPanel Widget Example .................................................................... 210 Introduction ............................................................................................ 213 Class declaration ................................................................................... 213 Class constructors ................................................................................. 213 Class methods ....................................................................................... 213 Methods inherited .................................................................................. 213 iii Composite Widget Example................................................................... 214 Introduction ............................................................................................ 216 Class declaration ................................................................................... 216 Class constructors ................................................................................. 217 Class methods ....................................................................................... 217 Methods inherited .................................................................................. 217 SimplePanel Widget Example................................................................ 217 Introduction ............................................................................................ 220 Class declaration ................................................................................... 220 Class constructors ................................................................................. 221 Class methods ....................................................................................... 221 Methods inherited .................................................................................. 222 ScrollPanel Widget Example.................................................................. 222 Introduction ............................................................................................ 224 Class declaration ................................................................................... 224 Class constructors ................................................................................. 225 Class methods ....................................................................................... 225 Methods inherited .................................................................................. 227 FocusPanel Widget Example ................................................................. 227 Introduction ............................................................................................ 229 Class declaration ................................................................................... 229 Class constructors ................................................................................. 229 Class methods ....................................................................................... 230 Methods inherited .................................................................................. 231 FormPanel Widget Example .................................................................. 231 Introduction ............................................................................................ 235 Class declaration ................................................................................... 235 Class constructors ................................................................................. 235 Class methods ....................................................................................... 235 Methods inherited .................................................................................. 238 PopupPanel Widget Example ................................................................ 238 Introduction ............................................................................................ 241 Class declaration ................................................................................... 241 Class constructors ................................................................................. 242 Class methods ....................................................................................... 242 Methods inherited .................................................................................. 243 DialogBox Widget Example ................................................................... 244

Event Handling ..................................................................... 249
Event Handler Interfaces ....................................................................... 249 iii Event Methods ....................................................................................... 251 Example ................................................................................................. 251

Custom Widgets ................................................................... 255
Create Custom Widget with Composite Class ....................................... 255

UIBinder ............................................................................... 259
Introduction ............................................................................................ 259 UiBinder workflow .................................................................................. 259 Step 1: Create UI Declaration XML File ................................................. 259 Step 2: Use ui:field for Later Binding ..................................................... 260 Step 3: Create Java counterpart of UI XML ........................................... 260 Step 4: Bind Java UI fields with UiField annotation ................................ 260 Step 5: Bind Java UI with UI XML with UiTemplate annotation ............. 260 Step 6: Create CSS File ........................................................................ 261 Step 7: Create Java based Resource File for CSS File ......................... 261 Step 8: Attach CSS resource in Java UI Code file. ................................ 261 UIBinder Complete Example.................................................................. 261

RPC Communication ............................................................ 269
GWT RPC Components ........................................................................ 269 RPC Communication workflow .............................................................. 270 Step 1: Create a Serializable Model Class ............................................ 270 Step 2: Create a Service Interface ......................................................... 270 Step 2: Create a Async Service Interface .............................................. 271 Step 3: Create a Service Implementation Servlet class ......................... 271 Step 4: Update Web.xml to include Servlet declaration ......................... 271 Step 5: Make the remote procedure call in Application Code ................ 272 RPC Communication Complete Example .............................................. 272

JUnit Integration ................................................................... 278
Download Junit archive .......................................................................... 278 Locate GWT installation folder ............................................................... 278 GWTTestCase Class ............................................................................. 278 Using webAppCreator ............................................................................ 279 Understanding the test class: HelloWorldTest.java ................................ 280 Noteworthy Points.................................................................................. 281 GWT - JUnit Integration Complete Example .......................................... 281 Run test cases in Eclipse using generated launch configurations. ........ 285
RUN THE JUNIT TEST IN DEVELOPMENT MODE. ........................... 285 RUN THE JUNIT TEST IN PRODUCTION MODE. .............................. 286

Debug Application ................................................................ 288
Debugging Example .............................................................................. 288 iii Step 1 - Place BreakPoints .................................................................... 291 Step 2 - Debug Application .................................................................... 292

Internationalization ............................................................... 296
Workflow of internationalizing a GWT Application ................................. 296 Step 1: Create properties files ............................................................... 296 Step 2: Add i18n module to Module Descriptor XML File ...................... 297 Step 3: Create Interface equivalent to properties file ............................. 297 Step 4: Use Message Interface in UI component................................... 297 Internationalization - Complete Example ............................................... 298

History Class ........................................................................ 303
History Management Workflow .............................................................. 303 Step 1: Enable History support .............................................................. 303 Step 2: Add token to History .................................................................. 303 Step 3: Retrive token from History ......................................................... 304 History Class - Complete Example ........................................................ 304

Bookmark Support ............................................................... 308
Bookmarking Example ........................................................................... 308

Logging Framework ............................................................. 313
Types of Logger ..................................................................................... 313 Log Handlers ......................................................................................... 313 Configure Logging in GWT Application .................................................. 314 Use logger to log user actions ............................................................... 314 Logging Framework Example ................................................................ 314

iii

CHAPTER

1

GWTOverview
This chapter describes the basic definition and concepts of Google Web Toolkit.

What is GWT?

G
    

WT is an open source, free development toolkit.

Google Web Toolkit (GWT) is a development toolkit to create RICH Internet Application(RIA). GWT provides developers option to write client side application in JAVA. GWT compiles the code written in JAVA to JavaScript code. Application written in GWT is cross-browser compliant. GWT automatically generates javascript code suitable for each browser. GWT is open source, completely free, and used by thousands of developers around the world. It is licensed under the Apache License version 2.0.

Overall, GWT is a framework to build large scale and high performance web appliation while keeping them as easy-to-maintain.

Why to use GWT?

Being Java based, you can use JAVA IDEs like Eclipse to develop GWT applcation. Developers can use code auto-complete/refactoring/navigation/project management and all features of IDEs. GWT provides full debugging capability. Developers can debug the client side application just as an Java Application. GWT provides easy integration with Junit and Maven.

 

TUTORIALSPOINT Simply Easy Learning

Page 1

   

Again being Java based, GWT has a low learning curve for Java Developers. GWT generates optimized javascript code, produces browser's specific javascript code by self. GWT provides Widgets library provides most of tasks required in an application. GWT is extensible and custom widget can be created to cater to application needs.

On top of everything, GWT applications can run on all major browsers and smart phones including Android and iOS based phones/tablets.

Disadvantages of GWT
Though GWT comes with lots of plus points but same time we should consider the following points:

  

Not indexable : Web pages generated by GWT would not be indexed by search engines because these applications are generated dynamically. Not degradable: If your application user disables Javascript then user will just see the basic page and nothing more. Not designer's friendly: GWT is not suitable for web designers who prefer using plain HTML with placeholders for inserting dynamic content at later point in time.

The GWT Components
The GWT framework can be divided into following three major parts:



GWT Java to JavaScript compiler : This is the most important part of GWT which makes it a powerful tool for building RIAs. The GWT compiler is used to translate all the application code written in Java into JavaScript. JRE Emulation library : Google Web Toolkit includes a library that emulates a subset of the Java runtime library. The list includes java.lang, java.lang.annotation, java.math, java.io, java.sql, java.util and java.util.logging





GWT UI building library : This part of GWT consists of many subparts which includes the actual UI components, RPC support, History management, and much more. GWT also provides a GWT Hosted Web Browser which lets you run and execute your GWT applications in hosted mode, where your code runs as Java in the Java Virtual Machine without compiling to JavaScript.



TUTORIALS POINT Simply Easy Learning

Page 2

CHAPTER

2

Environment
This section describes how to setup your system environment before you start using Google Web Toolkit:

T
JDK Memory

his will guide you on how to prepare a development environment to start your

work with GWT Framework. This tutorial will also teach you how to setup JDK, Tomcat and Eclipse on your machine before you setup GWT Framework:

System Requirement
GWT requires JDK 1.6 or higher so the very first requirement is to have JDK installed in your machine. 1.6 or above. no minimum requirement. no minimum requirement. no minimum requirement.

Disk Space Operating System

Follow the given steps to setup your environment to start with GWT application development.

Step 1 - Verify Java installation on your machine
Now open console and execute the following java command. OS Windows Linux Mac Task Open Command Console Open Command Terminal Open Terminal Command c:\> java -version $ java -version machine:~ joseph$ java -version

TUTORIALS POINT Simply Easy Learning

Page 3

Let's verify the output for all the operating systems: OS Windows Generated Output java version "1.6.0_21" Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing) java version "1.6.0_21" Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM) Client VM (build 17.0-b17, mixed mode, sharing) java version "1.6.0_21" Java(TM) SE Runtime Environment (build 1.6.0_21-b07) Java HotSpot(TM)64-Bit Server VM (build 17.0-b17, mixed mode, sharing)

Linux

Mac

Step 2 - Setup Java Development Kit (JDK):
If you do not have Java installed then you can install the Java Software Development Kit (SDK) from Oracle's Java site: Java SE Downloads. You will find instructions for installing JDK in downloaded files, follow the given instructions to install and configure the setup. Finally set PATH and JAVA_HOME environment variables to refer to the directory that contains java and javac, typically java_install_dir/bin and java_install_dir respectively. Set the JAVA_HOME environment variable to point to the base directory location where Java is installed on your machine. For example: OS Windows Linux Mac Output Set the environment variable JAVA_HOME to C:\Program Files\Java\jdk1.6.0_21 export JAVA_HOME=/usr/local/java-current export JAVA_HOME=/Library/Java/Home

Append Java compiler location to System Path. OS Windows Linux Mac Output Append the string ;%JAVA_HOME%\bin to the end of the system variable, Path. export PATH=$PATH:$JAVA_HOME/bin/ not required

Alternatively, if you use an Integrated Development Environment (IDE) like Borland JBuilder, Eclipse, IntelliJ IDEA, or Sun ONE Studio, compile and run a simple program to confirm that the IDE knows where you installed Java, otherwise do proper setup as given document of the IDE.

Step 3 - Setup Eclipse IDE
All the examples in this tutorial have been written using Eclipse IDE. So I would suggest you should have latest version of Eclipse installed on your machine based on your operating system.

TUTORIALS POINT Simply Easy Learning

Page 4

To install Eclipse IDE, download the latest Eclipse binaries from http://www.eclipse.org/downloads/. Once you downloaded the installation, unpack the binary distribution into a convenient location. For example in C:\eclipse on windows, or /usr/local/eclipse on Linux/Unix and finally set PATH variable appropriately. Eclipse can be started by executing the following commands on windows machine, or you can simply double click on eclipse.exe %C:\eclipse\eclipse.exe Eclipse can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine: $/usr/local/eclipse/eclipse After a successful startup, if everything is fine then it should display following result:

Step 4: Install GWT SDK & Plugin for Eclipse
Follow the instructions given at the link Plugin for Eclipse (incl. SDKs) to install GWT SDK & Plugin for Eclipse version installed on your machine. After a successful setup for the GWT plugin, if everything is fine then it should display following screen with google icon marked with red rectangle:

TUTORIALS POINT Simply Easy Learning

Page 5

Step 5: Setup Apache Tomcat:
You can download the latest version of Tomcat from http://tomcat.apache.org/. Once you downloaded the installation, unpack the binary distribution into a convenient location. For example in C:\apache-tomcat-6.0.33 on windows, or /usr/local/apache-tomcat-6.0.33 on Linux/Unix and set CATALINA_HOME environment variable pointing to the installation locations. Tomcat can be started by executing the following commands on windows machine, or you can simply double click on startup.bat %CATALINA_HOME%\bin\startup.bat or C:\apache-tomcat-6.0.33\bin\startup.bat Tomcat can be started by executing the following commands on Unix (Solaris, Linux, etc.) machine: $CATALINA_HOME/bin/startup.sh or /usr/local/apache-tomcat-6.0.33/bin/startup.sh

TUTORIALS POINT Simply Easy Learning

Page 6

After a successful startup, the default web applications included with Tomcat will be available by visiting http://localhost:8080/. If everything is fine then it should display following result

Further information about configuring and running Tomcat can be found in the documentation included here, as well as on the Tomcat web site: http://tomcat.apache.org Tomcat can be stopped by executing the following commands on windows machine: %CATALINA_HOME%\bin\shutdown or C:\apache-tomcat-5.5.29\bin\shutdown Tomcat can be stopped by executing the following commands on Unix (Solaris, Linux, etc.) machine: $CATALINA_HOME/bin/shutdown.sh or /usr/local/apache-tomcat-5.5.29/bin/shutdown.sh

TUTORIALS POINT Simply Easy Learning

Page 7

CHAPTER

3

Applications
This section describes the applications under Google Web Toolkit:

B
   

eforewe start with creating actual HelloWorld application using GWT, let us see

what are the actual parts of a GWT application. A GWT application consists of following four important parts out of which last part is optional but first three parts are mandatory: Module descriptors Public resources Client-side code Server-side code

Sample locations of different parts of a typical gwt application HelloWord will be as shown below: Name Project root Module descriptor Public resources Client-side code Server-side code Location HelloWorld/ src/com/tutorialspoint/HelloWorld.gwt.xml src/com/tutorialspoint/war/ src/com/tutorialspoint/client/ src/com/tutorialspoint/server/

Module Descriptors
A module descriptor is the configuration file in the form of XML which is used to configure a GWT application. A module descriptor file extension is *.gwt.xml, where * is the name of the application and this file should reside in the project's root. Following will be a default module descriptorHelloWorld.gwt.xml for a HelloWorld application:

TUTORIALS POINT Simply Easy Learning

Page 8

--> --> -->

-->

-->

--

2

This adds other gwt module in application just like import does in java applications. Any number of modules can be inherited in this manner. This specifies the name of class which will start loading the GWT Application. Any number of entry-point classes can be added and they are called sequentially in the order in which they appear in the module file. So when the onModuleLoad() of your first entry point finishes, the next entry point is called immediately. This specifies the names of source folders which GWT compiler will search for source compilation. The public path is the place in your project where static resources referenced by your GWT module, such as CSS or images, are stored. The default public path is the public subdirectory underneath where the Module XML File is stored. Automatically injects the external JavaScript file located at the location specified by src. Automatically injects the external CSS file located at the location specified by src.

3

4

5

6 7

TUTORIALS POINT Simply Easy Learning

Page 9

Public resources
These are all files referenced by your GWT module, such as Host HTML page, CSS or images. The location of these resources can be configured using element in module configuration file. By default, it is the public subdirectory underneath where the Module XML File is stored. When you compile your application into JavaScript, all the files that can be found on your public path are copied to the module's output directory. The most important public resource is host page which is used to invoke actual GWT application. A typical HTML host page for an application might not include any visible HTML body content at all but it is always expected to include GWT application via a tag as follows: Hello World

Hello World Welcome to first GWT application Following is the sample style sheet which we have included in our host page: body { text-align: center; font-family: verdana, sans-serif; } h1 { font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; }

Client-side code
This is the actual Java code written implementing the business logic of the application and that the GWT compiler translates into JavaScript, which will eventually run inside the browser. The location of these resources can be configured using element in module configuration file. For example Entry Point code will be used as client side code and its location will be specified using . A module entry-point is any class that is assignable to EntryPoint and that can be constructed without parameters. When a module

TUTORIALS POINT Simply Easy Learning

Page 10

is loaded, every entry point class is instantiated and its EntryPoint.onModuleLoad() method gets called. A sample HelloWorld Entry Point class will be as follows: publicclassHelloWorldimplementsEntryPoint{ publicvoid onModuleLoad(){ Window.alert("Hello, World!"); } }

Server-side code
This is the server side part of your application and its very much optional. If you are not doing any backend processing with-in your application then you do not need this part, but if there is some processing required at backend and your client-side application interact with the server then you will have to develop these components. Next chapter will make use of all the above mentioned concepts to create HelloWorld application using Eclipse IDE.

TUTORIALS POINT Simply Easy Learning

Page 11

CHAPTER

4

Create Application
This section describes how to create application:

A

s power of GWT lies in Write in Java, Run in JavaScript, we'll be using Java

IDE Eclipse to demonstrate our examples. Let's start with a simple HelloWorld application:

Step 1 - Create Project
The first step is to create a simple Web Application Project using Eclipse IDE. Launch project wizard using the option Google Icon > New Web Application Project....

Now name your project asHelloWorld using the wizard window as follows:

TUTORIALS POINT Simply Easy Learning

Page 12

Unselect Use Google App Engine because we're not using it in this project and leave other default values (keep Generate Sample project code option checked) as such and click Finish Button. Once your project is created successfully, you will have following content in your Project Explorer:

TUTORIALS POINT Simply Easy Learning

Page 13

Here is brief description of all important folders: Folder Location

   src Source code (java classes) files. Client folder containing the client-side specific java classes responsible for client UI display. Server folder containing the server-side java classes responsible for server side processing. Shared folder containing the java model class to transfer data from server to client and vice versa. HelloWorld.gwt.xml, a module descriptor file required for GWT compiler to compile the HelloWorld project.

 

 test Test code (java classes) source files. Client folder containing the java classes responsible to test gwt client side code.



TUTORIALS POINT Simply Easy Learning

Page 14

  war This is the most important part, it represents the actual deployable web application. WEB-INF containing compiled classes, gwt libraries, servlet libraries. HelloWorld.css, project style sheet. HelloWorld.html, hots HTML which will invoke GWT UI Application.

 

Step 2 - Modify Module Descriptor:
HelloWorld.gwt.xml
GWT plugin will create a default module descriptor file src/com.tutorialspoint/HelloWorld.gwt.xml which is given below. For this example we are not modifying it, but you can modify it based on your requirement.

--> -->

Step 3 - Modify Style Sheet: HelloWorld.css
GWT plugin will create a default Style Sheet file war/HelloWorld.css. Let us modify this file to keep our example at simplest level of understaning: body { text-align: center; font-family: verdana, sans-serif; } h1 { font-size:2em; font-weight: bold;

TUTORIALS POINT Simply Easy Learning

Page 15

color:#777777; margin:40px0px70px; text-align: center; }

Step 4 - Modify Host File: HelloWorld.html
GWT plugin will create a default HTML host file war/HelloWorld.html. Let us modify this file to keep our example at simplest level of understaning: Hello World Hello World Welcome to first GWT application You can create more static files like HTML, CSS or images in the same source directory or you can create further sub-directories and move files in those sub-directories and configure those sub-directories in module descriptor of the application.

Step 5 - Modify Entry Point: HelloWorld.java
GWT plugin will create a default Java file src/com.tutorialspoint/HelloWorld.java, which keeps an entry point for the application. Let us modify this file to display "Hello,World!": package com.tutorialspoint.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.Window; publicclassHelloWorldimplementsEntryPoint{ publicvoid onModuleLoad(){ Window.alert("Hello, World!"); } } You can create more Java files in the same source directory to define either entry points or to define helper routines.

Step 6 - Compile Application

TUTORIALS POINT Simply Easy Learning

Page 16

Once you are ready with all the changes done, its time to compile the project. Use the option Google Icon box as shown below: > GWT Compile Project... to launch GWT Compile dialogue

Keep default values intact and click Compile button. If everything goes fine, you will see following output in Eclipse console Compiling module com.tutorialspoint.HelloWorld Compiling 6 permutations Compiling permutation 0... Compiling permutation 1... Compiling permutation 2... Compiling permutation 3... Compiling permutation 4... Compiling permutation 5... Compile of permutations succeeded Linking into C:\workspace\HelloWorld\war\helloworld

TUTORIALS POINT Simply Easy Learning

Page 17

Link succeeded Compilation succeeded -- 33.029s

Step 6 - Run Application
Now click on application. Run application menu and select HelloWorld application to run the

If everything is fine, you must see GWT Development Mode active in Eclipse containing a URL as shown below. Double click the URL to open the GWT application.

Because you are running your application in development mode, so you will need to install GWT plugin for your browser. Simply follow the onscreen instructions to install the plugin. If you already have GWT plugin set for your browser, then you should be able to see the following output:

TUTORIALS POINT Simply Easy Learning

Page 18

Congratulations! you have implemented your first application using Google Web Toolkit (GWT).

TUTORIALS POINT Simply Easy Learning

Page 19

CHAPTER

5

Deploy Application
This section describes how to deploy application under Google Web Toolkit:

T
1 2 3 4 5

his tutorial will explain you how to create an application war file and how to deploy

that in Apache Tomcat Websever root. If you understood this simple example then you will also be able to deploy a complex GWT application following the same steps. Let us have working Eclipse IDE along with GWT plug in place and follow the following steps to create a GWT application: Step Description Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. Compile and run the application to make sure business logic is working as per the requirements. Finally, zip the content of the war folder of the application in the form of war file and deploy it in Apache Tomcat Webserver. Launch your web application using appropriate URL as explained below in the last step. modified module

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> -->

Following is the content of the modified Style Sheet file war/HelloWorld.css. body { text-align: center; font-family: verdana, sans-serif; } h1 { font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; } Following is the content of the modified HTML host file war/HelloWorld.html. Hello World Hello World

I modified HTML a little bit from previous example. Here I created a placeholder ... where we will insert some content using our entry point java class. So let us have following content of Java filesrc/com.tutorialspoint/HelloWorld.java. package com.tutorialspoint.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.RootPanel; public class HelloWorld implementsEntryPoint{ public void onModuleLoad(){ HTML html =new HTML("Welcome to GWT application"); RootPanel.get("gwtContainer").add(html); } } Here we created on basic widgest HTML and added it inside the div tag having id="gwtContainer". We will study different GWT widgets in coming chapters.

TUTORIALS POINT Simply Easy Learning

Page 21

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

Create WAR File
Now our applictaion is working fine and we are ready to export it as a war file. Follow the following steps:

   

Go into your project's war directory C:\workspace\HelloWorld\war Select all the files & folders available inside war directory. Zip all the selected files & folders in a file called HelloWorld.zip. Rename HelloWorld.zip to HelloWorld.war.

Deploy WAR file
    
Stop the tomcat server. Copy the HelloWorld.war file to tomcat installation directory > webapps folder. Start the tomcat server. Look inside webapps directory, there should be a folder helloworld got created. Now HelloWorld.war is successfully deployed in Tomcat Webserver root.

Run Application
TUTORIALS POINT Simply Easy Learning

Page 22

Enter a url in web browser: http://localhost:8080/HelloWorld to launch the application Server name (localhost) and port (8080) may vary as per your tomcat configuration.

TUTORIALS POINT Simply Easy Learning

Page 23

CHAPTER

6

Style with CSS
This section describes CSS with Google Web Toolkit:

G

WT widgets rely on cascading style sheets (CSS) for visual styling. By default,

the class name for each component is gwt-. For example, the Button widget has a default style of gwt-Buttonand similar way TextBox widgest has a default style of gwtTextBox. In order to give all buttons and text boxes a larger font, you could put the following rule in your application's CSS file: .gwt-Button{ font-size:150%;} .gwt-TextBox{ font-size:150%;} By default, neither the browser nor GWT creates default id attributes for widgets. You must explicitly create a unique id for the elements which you can use in CSS. In order to give a particular button with idmy-button-id a larger font, you could put the following rule in your application's CSS file: #my-button-id { font-size: 150%; } To set the id for a GWT widget, retrieve its DOM Element and then set the id attribute as follows: Button b =newButton(); DOM.setElementAttribute(b.getElement(),"id","my-button-id")

CSS Styling APIs
There are many APIs available to hangle CSS setting for any GWT widget. Following are few important APIs which will help you in your day to day web programming using GWT: S.N. API & Description 1 public void setStyleName(java.lang.String style) This method will clear any existing styles and set the widget style to the new CSS class provided using style.

TUTORIALS POINT Simply Easy Learning

Page 24

2

public void addStyleName(java.lang.String style) This method will add a secondary or dependent style name to the widget. A secondary style name is an additional style name that is,so if there were any previous style names applied they are kept. public void removeStyleName(java.lang.String style) This method will remove given style from the widget and leaves any others associated with the widget. public java.lang.String getStyleName() This method gets all of the object's style names, as a space-separated list. public void setStylePrimaryName(java.lang.String style) This method sets the object's primary style name and updates all dependent style names.

3

4

5

For example, let's define two new styles which we will apply to a text: .gwt-Big-Text{ font-size:150%; } .gwt-Small-Text{ font-size:75%; } .gwt-Red-Text{ color:red; } Now you can use setStyleName(Style) to change the default setting to new setting. After applying the below rule, a text's font will become large: txtWidget.setStyleName("gwt-Big-Text"); We can apply a secondary CSS rule on the same widget to change its color as follows: txtWidget.addStyleName("gwt-Red-Text"); Using above method you can add as many styles as you like to apply on a widget. If you remove first style from the button widget then second style will still remain with the text: txtWidget.removeStyleName("gwt-Big-Text");

Primary & Secondary Styles
By default, the primary style name of a widget will be the default style name for its widget class for example gwt-Button for Button widgets. When we add and remove style names using AddStyleName() method, those styles are called secondary styles. The final appearance of a widget is determined by the sum of all the secondary styles added to it, plus its primary style. You set the primary style of a widget with the setStylePrimaryName(String) method. To illustrate, let's say we have a Label widget. In our CSS file, we have the following rules defined: .MyText{ color: blue; }

TUTORIALS POINT Simply Easy Learning

Page 25

.BigText{ font-size: large; } .LoudText{ font-weight: bold; } Let's suppose we want a particular label widget to always display blue text, and in some cases, use a larger, bold font for added emphasis. We could do something like this: // set up our primary style Label someText =newLabel(); someText.setStylePrimaryName("MyText"); ... // later on, to really grab the user's attention someText.addStyleName("BigText"); someText.addStyleName("LoudText"); ... // after the crisis is over someText.removeStyleName("BigText"); someText.removeStyleName("LoudText");

Associating CSS Files
There are multiple approaches for associating CSS files with your module. Modern GWT applications typically use a combination of CssResource and UiBinder. We are using only first approach in our examples.

   

Using a tag in the host HTML page. Using the element in the module XML file. Using a CssResource contained within a ClientBundle. Using an inline element in a UiBinder template.

GWT CSS Example
This example will take you through simple steps to apply different CSS rules on your GWT widgest. Let us have working Eclipse IDE along with GWT plug in place and follow the following steps to create a GWT application: Step Description 1 2 3 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. Compile and run the application to verify the result of the implemented logic.

TUTORIALS POINT Simply Easy Learning

Page 26

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> --> -->

--> --> -->

--> --> -->

Following is the content of the modified Style Sheet file war/HelloWorld.css. body{ text-align: center; font-family: verdana, sans-serif; } h1{ font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; } .gwt-Green-Border{ border:1px solid green; } .gwt-Blue-Border{ border:1px solid blue; } Following is the content of the modified HTML host file war/HelloWorld.html. Hello World HTML Widget Demonstration

Let us have following content of Java file src/com.tutorialspoint/HelloWorld.java which will demonstrate use of HTML widget. package com.tutorialspoint.client;

TUTORIALS POINT Simply Easy Learning

Page 42

import import import import

com.google.gwt.core.client.EntryPoint; com.google.gwt.user.client.ui.HTML; com.google.gwt.user.client.ui.RootPanel; com.google.gwt.user.client.ui.VerticalPanel;

public class HelloWorld implements EntryPoint{ public void onModuleLoad(){ // create two HTML widgets HTML html1 = new HTML("This is first GWT HTML widget using tag of html."); HTML html2 = new HTML("This is second GWT HTML widget using tag of html."); // use UIObject methods to set HTML widget properties. html1.addStyleName("gwt-Green-Border"); html2.addStyleName("gwt-Blue-Border"); // add widgets to the root panel. VerticalPanel panel =newVerticalPanel(); panel.setSpacing(10); panel.add(html1); panel.add(html2); RootPanel.get("gwtContainer").add(panel); } }

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

IMAGE
Introduction
The Image widget displays an image at a given URL.The image widget can be in 'unclipped' mode (the default mode) or 'clipped' mode. In clipped mode, a viewport is overlaid on top of the image so that a subset of the image will be displayed. In unclipped

TUTORIALS POINT Simply Easy Learning

Page 43

mode, there is no viewport - the entire image will be visible. Methods will operate differently depending on the mode that the image is in. These differences are detailed in the documentation for each method.

Class declaration
Following is the declaration for com.google.gwt.user.client.ui.Image class: public lass Image extends Widget implements SourcesLoadEvents,HasLoadHandlers, HasErrorHandlers,SourcesClickEvents, HasClickHandlers,HasAllMouseHandlers, SourcesMouseEvents

CSS style rules
Following default CSS Style rule will be applied to all the Image widget. You can override it as per your requirements. .gwt-Image{}

Class constructors
S.N. Constructor & Description 1 2 3 4 Image() Creates an empty image. protected Image(Element element) This constructor may be used by subclasses to explicitly use an existing element. Image(java.lang.String url) Creates an image with the specified url. Image(java.lang.String html, int left, int top, int width, int height) Creates a clipped image with a specified URL and visibility rectangle.

Class methods
S.N. Function name & Description 1 2 3 4 5 6 7 void addClickListener(ClickListener listener) Adds a listener interface to receive click events. void addLoadListener(LoadListener listener) Adds a listener interface to receive load events. void addMouseListener(MouseListener listener) Adds a listener interface to receive mouse events. void addMouseWheelListener(MouseWheelListener listener) Gets this widget's parent panel. int getHeight() Gets the height of the image. int getOriginLeft() Gets the horizontal co-ordinate of the upper-left vertex of the image's visibility rectangle. int getOriginTop() Gets the vertical co-ordinate of the upper-left vertex of the image's visibility rectangle.

TUTORIALS POINT Simply Easy Learning

Page 44

8 9 10 11

java.lang.String getUrl() Gets the URL of the image. int getWidth() Gets the width of the image. void onBrowserEvent(Event event) Removes a previously added listener interface. static void prefetch(java.lang.String url) Causes the browser to pre-fetch the image at a given URL. void removeClickListener(ClickListener listener) This method is called immediately before a widget will be detached from the browser's document. void removeLoadListener(LoadListener listener) Removes a previously added listener interface. void removeMouseListener(MouseListener listener) Removes a previously added listener interface. void removeMouseWheelListener(MouseWheelListener listener) Removes a previously added listener interface. void setUrl(java.lang.String url) Sets the URL of the image to be displayed. void setUrlAndVisibleRect(java.lang.String url, int left, int top, int width, int height) Sets the url and the visibility rectangle for the image at the same time. void setVisibleRect(int left, int top, int width, int height) Sets the visibility rectangle of an image. static Image wrap(Element element) Creates a Image widget that wraps an existing element.

12

13 14 15 16 17 18 19

Methods inherited
This class inherits methods from the following classes:

  

com.google.gwt.user.client.ui.UIObject com.google.gwt.user.client.ui.Widget java.lang.Object

Image Widget Example
This example will take you through simple steps to show usage of a Image Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter: Step Description 1 2 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged.

TUTORIALS POINT Simply Easy Learning

Page 45

3

Compile and run the application to verify the result of the implemented logic. modified module

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> --> -->

--> --> -->

TUTORIALS POINT Simply Easy Learning

Page 54

--> -->

Following is the content of the modified Style Sheet file war/HelloWorld.css. body{ text-align: center; font-family: verdana, sans-serif; } h1{ font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; } .gwt-Button{ color:red; } .gwt-Green-Button{ color:green; } .gwt-Blue-Button{ color:blue; } Following is the content of the modified HTML host file war/HelloWorld.html. Hello World Button Widget Demonstration

Let us have following content of Java file src/com.tutorialspoint/HelloWorld.java which will demonstrate use of Button widget. package com.tutorialspoint.client; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.event.dom.client.ClickEvent;

TUTORIALS POINT Simply Easy Learning

Page 55

import import import import import

com.google.gwt.event.dom.client.ClickHandler; com.google.gwt.user.client.Window; com.google.gwt.user.client.ui.Button; com.google.gwt.user.client.ui.RootPanel; com.google.gwt.user.client.ui.VerticalPanel;

public class HelloWorld implements EntryPoint{ public void onModuleLoad(){ //create buttons Button redButton =new Button("Red"); Button greenButton =new Button("Green"); Button blueButton =new Button("Blue"); // use UIObject methods to set button properties. redButton.setWidth("100px"); greenButton.setWidth("100px"); blueButton.setWidth("100px"); greenButton.addStyleName("gwt-Green-Button"); blueButton.addStyleName("gwt-Blue-Button"); //add a clickListener to the button redButton.addClickHandler(new ClickHandler(){ @Override public void onClick(ClickEvent event){ Window.alert("Red Button clicked!"); } }); //add a clickListener to the button greenButton.addClickHandler(new ClickHandler(){ @Override public void onClick(ClickEvent event){ Window.alert("Green Button clicked!"); } }); //add a clickListener to the button blueButton.addClickHandler(new ClickHandler(){ @Override public void onClick(ClickEvent event){ Window.alert("Blue Button clicked!"); } }); // Add button to the root panel. VerticalPanel panel =new VerticalPanel(); panel.setSpacing(10); panel.add(redButton); panel.add(greenButton); panel.add(blueButton); RootPanel.get("gwtContainer").add(panel); } }

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

TUTORIALS POINT Simply Easy Learning

Page 56

When you click Click Me button, it will show an alert message Hello World!

PushButton
Introduction
The PushButton widget represents a standard push button with custom styling.

Class declaration
Following is the declaration for com.google.gwt.user.client.ui.PushButton class: public class PushButton extends CustomButton

CSS style rules
Following default CSS Style rules will be applied to all the PushButton widget. You can override it as per your requirements. .gwt-PushButton-up {} .gwt-PushButton-down {} .gwt-PushButton-up-hovering {} .gwt-PushButton-down-hovering {} .gwt-PushButton-up-disabled {} .gwt-PushButton-down-disabled {}

Class constructors
S.N. Constructor & Description

TUTORIALS POINT Simply Easy Learning

Page 57

1 2 3 4 5 6 7 8

PushButton() Constructor for PushButton. PushButton(Image upImage) Creates a PushButton with up state image. PushButton(Image upImage, ClickListener listener) Creates a PushButton with up state image and clickListener. PushButton(Image upImage, Image downImage) Creates a PushButton with up state image. PushButton(Image upImage, Image downImage, ClickListener listener) Creates a PushButton with up state image. PushButton(java.lang.String upText) Creates a PushButton with up state text. PushButton(java.lang.String upText, ClickListener listener) Creates a PushButton with up state text and clicklistener. PushButton(java.lang.String upText, java.lang.String downText) Creates a PushButton with up state and down state text. PushButton(java.lang.String upText, java.lang.String downText, ClickListener listener) Creates a PushButton with up state, down state text and click listener.

8

Class methods
S.N. Function name & Description 1 protected void onClick() Called when the user finishes clicking on this button. protected void onClickCancel() Called when the user aborts a click in progress; for example, by dragging the mouse outside of the button before releasing the mouse button. protected void onClickStart() Called when the user begins to click on this button.

2

3

Methods inherited
This class inherits methods from the following classes:

    

com.google.gwt.user.client.ui.UIObject com.google.gwt.user.client.ui.Widget com.google.gwt.user.client.ui.FocusWidget com.google.gwt.user.client.ui.CustomWidget java.lang.Object

TUTORIALS POINT Simply Easy Learning

Page 58

PushButton Widget Example
This example will take you through simple steps to show usage of a PushButton Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Applicationchapter: Step Description 1 2 3 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. Compile and run the application to verify the result of the implemented logic. modified module

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> --> -->

--> -->

Following is the content of the modified Style Sheet file war/HelloWorld.css. body{ text-align: center; font-family: verdana, sans-serif; } h1{ font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; } .gwt-ToggleButton-up { color:green; } .gwt-ToggleButton-down { color:blue; } .gwt-ToggleButton-up-hovering { color:pink; } .gwt-ToggleButton-down-hovering { color:aqua; } .gwt-ToggleButton-up-disabled { color:lime; } .gwt-ToggleButton-down-disabled { color:maroon; } Following is the content of the modified HTML host file war/HelloWorld.html. Hello World ToggleButton Widget Demonstration

Let us have following file src/com.tutorialspoint/HelloWorld.java which ToggleButton widget.

content of will demonstrate

use

Java of

public class HelloWorld implements EntryPoint{

TUTORIALS POINT Simply Easy Learning

Page 64

public void onModuleLoad(){ //create toggle buttons ToggleButton toggleButton =new ToggleButton("Click Me!"); ToggleButton toggleButton1 =new ToggleButton("Click Me!"); //disable a toggle button toggleButton1.setEnabled(false); //add a clickListener to the toggle button toggleButton.addClickHandler(new ClickHandler(){ @Override public void onClick(ClickEvent event){ Window.alert("Hello World!"); } }); // Add toggle button to the root panel. VerticalPanel panel =new VerticalPanel(); panel.setSpacing(10); panel.add(toggleButton); panel.add(toggleButton1); RootPanel.get("gwtContainer").add(panel); } }

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

TUTORIALS POINT Simply Easy Learning

Page 65

When you click Click Me button, it will show an alert message Hello World! You can see color of button text will change with your interaction.

  

Hover over the button, color will be pink. Press the button, color will be blue. Release the button, button will remain down.

CheckBox
Introduction
The Checkbox widget represents a standard checkbox.

Class declaration
Following is the declaration for com.google.gwt.user.client.ui.CheckBox class: public class CheckBox extends ButtonBase implements HasName

CSS style rules
Following default CSS Style rules will be applied to all the CheckBox widget. You can override it as per your requirements. .gwt-CheckBox{} .gwt-CheckBox-disabled {}

Class constructors
S.N. Constructor & Description 1 2 3 4 CheckBox() Constructor for CheckkBox. CheckBox(Element element) This constructor may be used by subclasses to explicitly use an existing element. CheckBox(java.lang.String label) Creates a check box with the specified text label. CheckBox(java.lang.String label, boolean asHTML) Creates a check box with the specified text label and set its contents as HTML.

Class methods
S.N. Function name & Description 1 java.lang.String getName() Gets the widget's name.

TUTORIALS POINT Simply Easy Learning

Page 66

2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

int getTabIndex() Gets the widget's position in the tab index. java.lang.String getText() Gets this object's text. boolean isChecked() Determines whether this check box is currently checked. boolean isEnabled() Gets whether this widget is enabled. protected void onEnsureDebugId(java.lang.String baseID) Affected Elements: -label = label next to checkbox. protected void onLoad() This method is called when a widget is attached to the browser's document. protected void onUnload() This method is called when a widget is detached from the browser's document. protected void replaceInputElement(Element elem) Replace the current input element with a new one. void setAccessKey(char key) Sets the widget's 'access key'. void setChecked(boolean checked) Checks or unchecks this check box. void setEnabled(boolean enabled) Sets whether this widget is enabled. void setFocus(boolean focused) Explicitly focus/unfocus this widget. void setHTML(java.lang.String html) Sets this object's contents via HTML. void setName(java.lang.String name) Sets the widget's name. void setTabIndex(int index) Sets the widget's position in the tab index. void setText(java.lang.String text) Sets this object's text. void sinkEvents(int eventBitsToAdd) Adds a set of events to be sunk by this object. java.lang.String getHTML() Gets this object's contents as HTML.

Methods inherited
This class inherits methods from the following classes:

 

com.google.gwt.user.client.ui.UIObject com.google.gwt.user.client.ui.Widget

TUTORIALS POINT Simply Easy Learning

Page 67

 

com.google.gwt.user.client.ui.FocusWidget java.lang.Object

CheckBox Widget Example
This example will take you through simple steps to show usage of a CheckBox Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
Step Description 1 2 3 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. Compile and run the application to verify the result of the implemented logic.

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

-->

TUTORIALS POINT Simply Easy Learning

Page 98

-->

Following is the content of the modified Style Sheet file war/HelloWorld.css. body{ text-align: center; font-family: verdana, sans-serif; } h1{ font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; } .gwt-RichTextArea{ padding:10px; } Following is the content of the modified HTML host file war/HelloWorld.html. Hello World RichTextArea Widget Demonstration

Let us have following content of Java file src/com.tutorialspoint/HelloWorld.java which will demonstrate use of TextBox widget. package com.tutorialspoint.client; import import import import com.google.gwt.core.client.EntryPoint; com.google.gwt.user.client.ui.RichTextArea; com.google.gwt.user.client.ui.RootPanel; com.google.gwt.user.client.ui.VerticalPanel;

public class HelloWorld implementsEntryPoint{ public void onModuleLoad(){ //create RichTextArea elements RichTextArea richTextArea =new RichTextArea();

TUTORIALS POINT Simply Easy Learning

Page 99

richTextArea.setHeight("200"); richTextArea.setWidth("200"); //add text to text area richTextArea.setHTML("Hello World!"+ "Be Happy!Stay Cool!"); // Add text boxes to the root panel. VerticalPanel panel =new VerticalPanel(); panel.add(richTextArea); RootPanel.get("gwtContainer").add(panel); } }

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

TUTORIALS POINT Simply Easy Learning

Page 100

FileUpload
Introduction
The FileUpload widget wraps the HTML element. This widget must be used with FormPanel if it is to be submitted to a server.

Class declaration
Following is the declaration for com.google.gwt.user.client.ui.FileUpload class: public class FileUpload Extends Widget Implements HasName,HasChangeHandlers

CSS style rules
Following default CSS Style rules will be applied to all the TextBox widget. You can override it as per your requirements. .gwt-FileUpload{}

Class constructors
S.N. Constructor & Description 1 2 FileUpload() Constructs a new file upload widget. FileUpload(Element element) This constructor may be used by subclasses to explicitly use an existing element.

Class methods
S.N. Function name & Description 1 2 3 4 5 6 7 HandlerRegistration addChangeHandler(ChangeHandler handler) Adds a ChangeEvent handler. java.lang.String getFilename() Gets the filename selected by the user. java.lang.String getName() Gets the widget's name. boolean isEnabled() Gets whether this widget is enabled. void onBrowserEvent(Event event) Fired whenever a browser event is received. void setEnabled(boolean enabled) Sets whether this widget is enabled. void setName(java.lang.String name) Sets the widget's name.

TUTORIALS POINT Simply Easy Learning

Page 101

8

static FileUpload wrap(Element element) Creates a FileUpload widget that wraps an existing element.

Methods inherited
This class inherits methods from the following classes:

  

com.google.gwt.user.client.ui.UIObject com.google.gwt.user.client.ui.Widget java.lang.Object

FileUpload Widget Example
This example will take you through simple steps to show usage of a FileUpload Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
Step Description 1 2 3 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. Compile and run the application to verify the result of the implemented logic.

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

Following is the content of the modified Style Sheet file war/HelloWorld.css. body{ text-align: center; font-family: verdana, sans-serif; } h1{ font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; } Following is the content of the modified HTML host file war/HelloWorld.html. Hello World CellTable Widget Demonstration

TUTORIALS POINT Simply Easy Learning

Page 152

Let us have following content of Java file src/com.tutorialspoint/HelloWorld.java which will demonstrate use of CellTable widget. package com.tutorialspoint.client; import java.util.Arrays; import java.util.Date; import java.util.List; import com.google.gwt.cell.client.DateCell; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.user.cellview.client.CellTable; import com.google.gwt.user.cellview.client.Column; import com.google.gwt.user.cellview.client .HasKeyboardSelectionPolicy.KeyboardSelectionPolicy; import com.google.gwt.user.cellview.client.TextColumn; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.view.client.SelectionChangeEvent; import com.google.gwt.view.client.SingleSelectionModel; public class HelloWorld implements EntryPoint{ /** * A simple data type that represents a contact. */ private static class Contact{ private final String address; private final Date birthday; private finalString name; public Contact(String name,Date birthday,String address){ this.name = name; this.birthday = birthday; this.address = address; } } /** * The list of data to display. */ private static final List CONTACTS =Arrays.asList( new Contact("John",new Date(80,4,12),"123 Fourth Avenue"), new Contact("Joe",new Date(85,2,22),"22 Lance Ln"), new Contact("George",new Date(46,6,6),"1600 Pennsylvania Avenue")); public void onModuleLoad(){ // Create a CellTable. CellTable table =new CellTable(); table.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED); // Add a text column to show the name. TextColumn nameColumn = new TextColumn(){ @Override public String getValue(Contactobject){ return object.name; }

TUTORIALS POINT Simply Easy Learning

Page 153

}; table.addColumn(nameColumn,"Name"); // Add a date column to show the birthday. DateCell dateCell =new DateCell(); Column dateColumn =new Column(dateCell){ @Override public Date getValue(Contact object){ return object.birthday; } }; table.addColumn(dateColumn,"Birthday"); // Add a text column to show the address. TextColumn addressColumn =new TextColumn(){ @Override public String getValue(Contact object){ return object.address; } }; table.addColumn(addressColumn,"Address"); // Add a selection model to handle user selection. final SingleSelectionModel selectionModel =newSingleSelectionModel(); table.setSelectionModel(selectionModel); selectionModel.addSelectionChangeHandler( new SelectionChangeEvent.Handler(){ public void onSelectionChange(SelectionChangeEvent event){ Contact selected = selectionModel.getSelectedObject(); if(selected !=null){ Window.alert("You selected: "+ selected.name); } } }); // Set the total row count. This isn't strictly necessary, // but it affects paging calculations, so its good habit to // keep the row count up to date. table.setRowCount(CONTACTS.size(),true); // Push the data into the widget. table.setRowData(0, CONTACTS); VerticalPanel panel =newVerticalPanel(); panel.setBorderWidth(1); panel.setWidth("400"); panel.add(table); // Add the widgets to the root panel. RootPanel.get().add(panel); } }

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

TUTORIALS POINT Simply Easy Learning

Page 154

CellBrowser
Introduction
The CellBrowser widget represents a browsable view of a tree in which only a single node per level may be open at one time.

Class declaration
Following is the for com.google.gwt.user.cellview.client.CellBrowser class: declaration

public class CellBrowser extends AbstractCellTree implements ProvidesResize,RequiresResize,HasAnimation

TUTORIALS POINT Simply Easy Learning

Page 155

Class constructors
S.N. Constructor & Description 1 CellBrowser(TreeViewModel viewModel, T rootValue) Construct a new CellBrowser. CellBrowser(TreeViewModel viewModel, T rootValue, CellBrowser.Resources resources) Construct a new CellBrowser with the specified CellBrowser.Resources.

2

Class methods
S.N. Function name & Description 1 2 3 4 5 6 7 8 9 protected Widget createPager(HasData display) Create a pager to control the list view. int getDefaultColumnWidth() Get the default width of new columns. int getMinimumColumnWidth() Get the minimum width of columns. TreeNode getRootTreeNode() Get the root TreeNode. boolean isAnimationEnabled() Returns true if animations are enabled, false if not. void onBrowserEvent(Event event) Fired whenever a browser event is received. void onResize() This method must be called whenever the implementor's size has been modified. void setAnimationEnabled(boolean enable) Enable or disable animations. void setDefaultColumnWidth(int width) Set the default width of new columns. void setKeyboardSelectionPolicy(HasKeyboardSelectionPolicy.KeyboardSelectionP olicy policy) Set the HasKeyboardSelectionPolicy.KeyboardSelectionPolicy. void setMinimumColumnWidth(int minWidth) Set the minimum width of columns.

10

11

Methods inherited
This class inherits methods from the following classes:

  

com.google.gwt.user.client.ui.UIObject com.google.gwt.user.client.ui.Widget com.google.gwt.user.client.ui.Composite

TUTORIALS POINT Simply Easy Learning

Page 156

 

com.google.gwt.user.cellview.client.AbstractCellTree java.lang.Object

CellBrowser Widget Example
This example will take you through simple steps to show usage of a CellBrowser Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Applicationchapter: Step Description 1 2 3 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.jav a as explained below. Keep rest of the files unchanged. Compile and run the application to verify the result of the implemented logic. modified module

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

TUTORIALS POINT Simply Easy Learning

Page 196

--> -->

Following is the content of the modified Style Sheet file war/HelloWorld.css. body{ text-align: center; font-family: verdana, sans-serif; } h1{ font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; } .deckpanel { border:1px solid #BBBBBB; padding:3px; } Following is the content of the modified HTML host file war/HelloWorld.html. Hello World DeckPanel Widget Demonstration

Let us have following file src/com.tutorialspoint/HelloWorld.java which DeckPanel widget. package com.tutorialspoint.client; import import import import import import import

content of will demonstrate

use

Java of

com.google.gwt.core.client.EntryPoint; com.google.gwt.event.dom.client.ClickEvent; com.google.gwt.event.dom.client.ClickHandler; com.google.gwt.user.client.ui.Button; com.google.gwt.user.client.ui.DeckPanel; com.google.gwt.user.client.ui.HorizontalPanel; com.google.gwt.user.client.ui.Label;

TUTORIALS POINT Simply Easy Learning

Page 197

import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.VerticalPanel; public class HelloWorld implements EntryPoint{ public void onModuleLoad(){ // Create DeckPanel widget final DeckPanel deckPanel =new DeckPanel(); deckPanel.setSize("300px","120px"); deckPanel.setStyleName("deckpanel"); // Create lables to add to deckpanel Label label1 =new Label("This is first Page"); Label label2 =new Label("This is second Page"); Label label3 =new Label("This is third Page"); // Add labels to deckpanel deckPanel.add(label1); deckPanel.add(label2); deckPanel.add(label3); //show first label deckPanel.showWidget(0); //create button bar HorizontalPanel buttonBar =new HorizontalPanel(); buttonBar.setSpacing(5); // create button and add click handlers // show different labels on click of different buttons Button button1 =new Button("Page 1"); button1.addClickHandler(new ClickHandler(){ @Override public void onClick(ClickEvent event){ deckPanel.showWidget(0); } }); Button button2 =newButton("Page 2"); button2.addClickHandler(newClickHandler(){ @Override public void onClick(ClickEvent event){ deckPanel.showWidget(1); } }); Button button3 =new Button("Page 3"); button3.addClickHandler(new ClickHandler(){ @Override public void onClick(ClickEvent event){ deckPanel.showWidget(2); } }); buttonBar.add(button1); buttonBar.add(button2); buttonBar.add(button3); VerticalPanel vPanel =new VerticalPanel(); vPanel.add(deckPanel); vPanel.add(buttonBar); // Add the widgets to the root panel. RootPanel.get().add(vPanel); } }

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

TUTORIALS POINT Simply Easy Learning

Page 198

DockPanel
Introduction
The DockPanel widget represents a panel that lays its child widgets out "docked" at its outer edges, and allows its last widget to take up the remaining space in its center.

Class declaration
Following is the declaration for com.google.gwt.user.client.ui.DockPanel class:

@Deprecated public class DockPanel extends CellPanel

TUTORIALS POINT Simply Easy Learning

Page 199

implements HasAlignment

Class constructors
S.N. Constructor & Description 1 DockPanel() Constructor for DockPanel.

Class methods
S.N. Function name & Description 1 2 3 4 void add(Widget widget, DockPanel.DockLayoutConstant direction) Deprecated. Adds a widget to the specified edge of the dock. HasHorizontalAlignment.HorizontalAlignmentConstant getHorizontalAlignment() Deprecated. Gets the horizontal alignment. HasVerticalAlignment.VerticalAlignmentConstant getVerticalAlignment() Deprecated. Gets the vertical alignment. DockPanel.DockLayoutConstant getWidgetDirection(Widget w) Deprecated. Gets the layout direction of the given child widget. protected void onEnsureDebugId(java.lang.String baseID) Deprecated. DockPanel supports adding more than one cell in a direction, so an integer will be appended to the end of the debug id. boolean remove(Widget w) Deprecated. Removes a child widget. void setCellHeight(Widget w, java.lang.String height) Deprecated. Sets the height of the cell associated with the given widget, related to the panel as a whole. void setCellHorizontalAlignment(Widget w, HasHorizontalAlignment.HorizontalAlignmentConstant align) Deprecated. Sets the horizontal alignment of the given widget within its cell. void setCellVerticalAlignment(Widget w, HasVerticalAlignment.VerticalAlignmentConstant align) Deprecated. Sets the vertical alignment of the given widget within its cell. void setCellWidth(Widget w, java.lang.String width) Deprecated. Sets the width of the cell associated with the given widget, related to the panel as a whole. void setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align) Deprecated. Sets the default horizontal alignment to be used for widgets added to this panel. void setVerticalAlignment(HasVerticalAlignment.VerticalAlignmentConstant align) Deprecated. Sets the default vertical alignment to be used for widgets added to this panel.

5

6

7

8

9

10

11

12

Methods inherited
This class inherits methods from the following classes:



com.google.gwt.user.client.ui.UIObject

TUTORIALS POINT Simply Easy Learning

Page 200

    

com.google.gwt.user.client.ui.Widget com.google.gwt.user.client.ui.Panel com.google.gwt.user.client.ui.ComplexPanel com.google.gwt.user.client.ui.CellPanel java.lang.Object

DockPanel Widget Example
This example will take you through simple steps to show usage of a DockPanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
Step Description 1 2 3 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. Compile and run the application to verify the result of the implemented logic.

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

--> --> -->

-->

-->

Following is the content of the modified Style Sheet file war/HelloWorld.css. body{ text-align: center; font-family: verdana, sans-serif; } h1{ font-size:2em; font-weight: bold; color:#777777; margin:40px0px70px; text-align: center; } Following is the content of the modified HTML host file war/HelloWorld.html. Hello World FormPanel Widget Demonstration

Let us have following file src/com.tutorialspoint/HelloWorld.java which FormPanel widget. package com.tutorialspoint.client; import import import import import import import import import import import import import import

content of will demonstrate

use

Java of

com.google.gwt.core.client.EntryPoint; com.google.gwt.event.dom.client.ClickEvent; com.google.gwt.event.dom.client.ClickHandler; com.google.gwt.user.client.Window; com.google.gwt.user.client.ui.Button; com.google.gwt.user.client.ui.DecoratorPanel; com.google.gwt.user.client.ui.FileUpload; com.google.gwt.user.client.ui.FormPanel; com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent; com.google.gwt.user.client.ui.FormPanel.SubmitEvent; com.google.gwt.user.client.ui.ListBox; com.google.gwt.user.client.ui.RootPanel; com.google.gwt.user.client.ui.TextBox; com.google.gwt.user.client.ui.VerticalPanel;

TUTORIALS POINT Simply Easy Learning

Page 232

public class HelloWorld implements EntryPoint{ public void onModuleLoad(){ // Create a FormPanel and point it at a service. final FormPanel form =new FormPanel(); form.setAction("/myFormHandler"); // Because we're going to add a FileUpload widget, // we'll need to set the form to use the POST method, // and multipart MIME encoding. form.setEncoding(FormPanel.ENCODING_MULTIPART); form.setMethod(FormPanel.METHOD_POST); // Create a panel to hold all of the form widgets. VerticalPanel panel =new VerticalPanel(); panel.setSpacing(10); form.setWidget(panel);
// Create a TextBox, giving it a name so that it will be submitted.

final TextBox tb =new TextBox(); tb.setWidth("220"); tb.setName("textBoxFormElement"); panel.add(tb); // Create a ListBox, giving it a name and // some values to be associated with its options. ListBox lb =new ListBox(); lb.setName("listBoxFormElement"); lb.addItem("item1","item1"); lb.addItem("item2","item2"); lb.addItem("item3","item3"); lb.setWidth("220"); panel.add(lb); // Create a FileUpload widget. FileUpload upload =new FileUpload(); upload.setName("uploadFormElement"); panel.add(upload); // Add a 'submit' button. panel.add(newButton("Submit",new ClickHandler(){ @Override public void onClick(ClickEvent event){ form.submit(); } })); // Add an event handler to the form. form.addSubmitHandler(new FormPanel.SubmitHandler(){ @Override public void onSubmit(SubmitEvent event){ // This event is fired just before the form is submitted. // We can take this opportunity to perform validation. if(tb.getText().length()==0){ Window.alert("The text box must not be empty"); event.cancel(); } } }); form.addSubmitCompleteHandler(newFormPanel. SubmitCompleteHandler(){

TUTORIALS POINT Simply Easy Learning

Page 233

@Override public void onSubmitComplete(SubmitCompleteEvent event){ // When the form submission is successfully completed, // this event is fired. Assuming the service returned // a response of type text/html, we can get the result // here. Window.alert(event.getResults()); } }); DecoratorPanel decoratorPanel =new DecoratorPanel(); decoratorPanel.add(form); // Add the widgets to the root panel. RootPanel.get().add(decoratorPanel); } }

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

PopupPanel
TUTORIALS POINT Simply Easy Learning

Page 234

Introduction
The PopupPanel widget represents a panel that can pop up over other widgets. It overlays the browser's client area (and any previously-created popups).

Class declaration
Following is the declaration for com.google.gwt.user.client.ui.PopupPanel class: public class PopupPanel extends SimplePanel implements SourcesPopupEvents,EventPreview, HasAnimation,HasCloseHandlers

Class constructors
S.N. Constructor & Description 1 2 3 PopupPanel() Creates an empty popup panel. PopupPanel(boolean autoHide) Creates an empty popup panel, specifying its auto-hide property. PopupPanel(boolean autoHide, boolean modal) Creates an empty popup panel, specifying its auto-hide and modal properties.

Class methods
S.N. Function name & Description 1 void addAutoHidePartner(Element partner) Mouse events that occur within an autoHide partner will not hide a panel set to autoHide. HandlerRegistration addCloseHandler(CloseHandler handler) Adds a CloseEvent handler. void addPopupListener(PopupListener listener) Deprecated. Use addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler) instead void center() Centers the popup in the browser window and shows it. protected Element getContainerElement() Override this method to specify that an element other than the root element be the container for the panel's child widget. protected Element getGlassElement() Get the glass element used by this PopupPanel. java.lang.String getGlassStyleName() Gets the style name to be used on the glass element. int getOffsetHeight() Gets the panel's offset height in pixels. int getOffsetWidth() Gets the panel's offset width in pixels.

2

3

4

5

6 7 8 9

TUTORIALS POINT Simply Easy Learning

Page 235

10 11 12 13 14 15 16

int getPopupLeft() Gets the popup's left position relative to the browser's client area. int getPopupTop() Gets the popup's top position relative to the browser's client area. protected Element getStyleElement() Template method that returns the element to which style names will be applied. java.lang.String getTitle() Gets the title associated with this object. void hide() Hides the popup and detaches it from the page. void hide(boolean autoClosed) Hides the popup and detaches it from the page. boolean isAnimationEnabled() Returns true if animations are enabled, false if not. boolean isAutoHideEnabled() Returns true if the popup should be automatically hidden when the user clicks outside of it. boolean isAutoHideOnHistoryEventsEnabled() Returns true if the popup should be automatically hidden when the history token changes, such as when the user presses the browser's back button. boolean isGlassEnabled() Returns true if a glass element will be displayed under the PopupPanel. boolean isModal() Returns true if keyboard or mouse events that do not target the PopupPanel or its children should be ignored. boolean isPreviewingAllNativeEvents() Returns true if the popup should preview all native events, even if the event has already been consumed by another popup. boolean isShowing() Determines whether or not this popup is showing. boolean isVisible() Determines whether or not this popup is visible. boolean onEventPreview(Event event) Deprecated. Use onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent) instead boolean onKeyDownPreview(char key, int modifiers) Deprecated. Use onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent) instead boolean onKeyPressPreview(char key, int modifiers) Deprecated. Use onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent) instead boolean onKeyUpPreview(char key, int modifiers)

17

18

19

20

21

22 23

24

25

26

27

TUTORIALS POINT Simply Easy Learning

Page 236

Deprecated. Use onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent) instead 28 29 protected void onPreviewNativeEvent(Event.NativePreviewEvent event) protected void onUnload() This method is called immediately before a widget will be detached from the browser's document. void removeAutoHidePartner(Element partner) Remove an autoHide partner. void removePopupListener(PopupListener listener) Deprecated. Use the HandlerRegistration.removeHandler() method on the object returned by addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler) instead void setAnimationEnabled(boolean enable) Enable or disable animations. void setAutoHideEnabled(boolean autoHide) Enable or disable the autoHide feature. void setAutoHideOnHistoryEventsEnabled(boolean enabled) Enable or disable autoHide on history change events. void setGlassEnabled(boolean enabled) When enabled, the background will be blocked with a semi-transparent pane the next time it is shown. void setGlassStyleName(java.lang.String glassStyleName) Sets the style name to be used on the glass element. void setHeight(java.lang.String height) Sets the height of the panel's child widget. void setModal(boolean modal) When the popup is modal, keyboard or mouse events that do not target the PopupPanel or its children will be ignored. void setPopupPosition(int left, int top) Sets the popup's position relative to the browser's client area. void setPopupPositionAndShow(PopupPanel.PositionCallback callback) Sets the popup's position using a PopupPanel.PositionCallback, and shows the popup. void setPreviewingAllNativeEvents(boolean previewAllNativeEvents) When enabled, the popup will preview all native events, even if another popup was opened after this one. void setTitle(java.lang.String title) Sets the title associated with this object. void setVisible(boolean visible) Sets whether this object is visible. void setWidget(Widget w) Sets this panel's widget. void setWidth(java.lang.String width) Sets the width of the panel's child widget.

30

31

32 33 34

35

36 37

38

39

40

41

42 43 44 45

TUTORIALS POINT Simply Easy Learning

Page 237

46

void show() Shows the popup and attach it to the page. void showRelativeTo(UIObject target) Normally, the popup is positioned directly below the relative target, with its left edge aligned with the left edge of the target.

47

Methods inherited
This class inherits methods from the following classes:

    

com.google.gwt.user.client.ui.UIObject com.google.gwt.user.client.ui.Widget com.google.gwt.user.client.ui.Panel com.google.gwt.user.client.ui.SimplePanel java.lang.Object

PopupPanel Widget Example
This example will take you through simple steps to show usage of a PopupPanel Widget in GWT. Follow the following steps to update the GWT application we created in GWT - Create Applicationchapter:
Step Description 1 2 3 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. Compile and run the application to verify the result of the implemented logic.

Following is the content of the descriptor src/com.tutorialspoint/HelloWorld.gwt.xml. --> --> -->

--> --> -->

--> --> -->

--> --> -->

Hello World Custom Widget Demonstration Let us have following content of Java file src/com.tutorialspoint/HelloWorld.java which will demonstrate creation of a Custom widget. package com.tutorialspoint.client; import import import import import import import import com.google.gwt.core.client.EntryPoint; com.google.gwt.event.dom.client.ClickEvent; com.google.gwt.event.dom.client.ClickHandler; com.google.gwt.user.client.ui.CheckBox; com.google.gwt.user.client.ui.Composite; com.google.gwt.user.client.ui.HorizontalPanel; com.google.gwt.user.client.ui.RootPanel; com.google.gwt.user.client.ui.TextBox;

public class HelloWorld implements EntryPoint{ /** * A composite of a TextBox and a CheckBox that optionally enables it.

TUTORIALS POINT Simply Easy Learning

Page 256

*/ private static class OptionalTextBox extends Composite implements ClickHandler{ private TextBox textBox =new TextBox(); private CheckBox checkBox =new CheckBox(); private boolean enabled =true; public boolean isEnabled(){ return enabled; } public void setEnabled(boolean enabled){ this.enabled = enabled; } /** * Style this widget using .optionalTextWidget CSS class. * Style textbox using .optionalTextBox CSS class. * Style checkbox using .optionalCheckBox CSS class. * Constructs an OptionalTextBox with the given caption * on the check. * @param caption the caption to be displayed with the check box */ public OptionalTextBox(String caption){ // place the check above the text box using a vertical panel. HorizontalPanel panel =new HorizontalPanel(); // panel.setBorderWidth(1); panel.setSpacing(10); panel.add(checkBox); panel.add(textBox); // all composites must call initWidget() in their constructors. initWidget(panel); //set style name for entire widget setStyleName("optionalTextWidget"); //set style name for text box textBox.setStyleName("optionalTextBox"); //set style name for check box checkBox.setStyleName("optionalCheckBox"); textBox.setWidth("200"); // Set the check box's caption, and check it by default. checkBox.setText(caption); checkBox.setValue(enabled); checkBox.addClickHandler(this); enableTextBox(enabled,checkBox.getValue()); } public void onClick(ClickEvent event){ if(event.getSource()== checkBox){ // When the check box is clicked, //update the text box's enabled state. enableTextBox(enabled,checkBox.getValue()); } } private void enableTextBox(boolean enable,boolean isChecked){ enable =(enable && isChecked)||(!enable &&!isChecked); textBox.setStyleDependentName("disabled",!enable); textBox.setEnabled(enable); } } public void onModuleLoad(){

TUTORIALS POINT Simply Easy Learning

Page 257

// Create an optional text box and add it to the root panel.
OptionalTextBox otb =new OptionalTextBox("Want to explain the solution?");

otb.setEnabled(true); RootPanel.get().add(otb); } }

Once you are ready with all the changes done, let us compile and run the application in development mode as we did in GWT - Create Application chapter. If everything is fine with your application, this will produce following result:

You can notice following points

   

Creation of Custom Widget by extending Composite widget is pretty easy. We've created a widget with GWT inbuilt widgets, TextBox and CheckBox thus using the concept of reusability. TextBox get disabled/enabled depending on state of checkbox. We've provided an API to enable/disable the control. We've exposed internal widgets styles via documented CSS styles.

TUTORIALS POINT Simply Easy Learning

Page 258

13
UIBinder
This section describes the UI Binder under Google Web Toolkit:

CHAPTER

T
     

he UIBinder under Google Web Toolkit is a framework which allows developers to

build GWT applications.

Introduction
The UiBinder is a framework designed to separate Functionality and View of User Interface. The UiBinder framework allows developers to build gwt applications as HTML pages with GWT widgets configured throughout them. The UiBinder framework makes easier collaboration with UI designers who are more comfortable with XML, HTML and CSS than Java source code The UIBinder provides a declarative way of defining User Interface. The UIBinder seperates the programmic logic from UI. The UIBinder is similar to what JSP is to Servlets.

UiBinder workflow Step 1: Create UI Declaration XML File
Create a XML/HTML based User a Login.ui.xml file in our example. Interface declaration file. We've created

TUTORIALS POINT Simply Easy Learning

Page 259

...

Step 2: Use ui:field for Later Binding
Use ui:field attribute in XML/HTML element to relate UI field in XML with UI field in JAVA file for later binding.

Step 3: Create Java counterpart of UI XML
Create Java based counterpart of XML based layout by extending Composite widget. We've created aLogin.java file in our example. package com.tutorialspoint.client; ... public class Login extends Composite{ ... }

Step 4: Bind Java UI fields with UiField annotation use @UiField annotation in Login.java to designate counterpart class members to bind to XMLbased fields in Login.ui.xml public class Login extends Composite{ ... @UiField Label completionLabel1; @UiField Label completionLabel2; ... }

Step 5: Bind Java UI with UI XML with UiTemplate annotation
Instruct GWT to bind java based component Login.java and layout Login.ui.xml using @UiTemplate annotation public class Login extends Composite{ private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class); /* * @UiTemplate is not mandatory but allows multiple XML templates * to be used for the same widget. * Default file loaded will be .ui.xml */ @UiTemplate("Login.ui.xml") interface LoginUiBinder extends UiBinder{ } ... }

XML

based

TUTORIALS POINT Simply Easy Learning

Page 260

Step 6: Create CSS File
Create an external CSS fileLogin.css and Java based Resource LoginResources.java file equivalent to css styles .blackText { font-family:Arial,Sans-serif; color:#000000; font-size:11px; text-align: left; } ...

Step 7: Create Java based Resource File for CSS File package com.tutorialspoint.client; ... public interface LoginResources extends ClientBundle{ public interface MyCss extends CssResource{ String blackText(); ... } @Source("Login.css") MyCss style(); }

Step 8: Attach CSS resource in Java UI Code file.
Attach an external class Login.java CSS fileLogin.css using Contructor of Java based widget public Login(){ this.res = GWT.create(LoginResources.class); res.style().ensureInjected(); initWidget(uiBinder.createAndBindUi(this)); }

UIBinder Complete Example
This example will take you through simple steps to show usage of a UIBinder in GWT. Follow the following steps to update the GWT application we created in GWT - Create Application chapter:
Step Description 1 2 3 Create a project with a name HelloWorld under a package com.tutorialspoint as explained in the GWT - Create Application chapter. Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorld.html and HelloWorld.java as explained below. Keep rest of the files unchanged. Compile and run the application to verify the result of the implemented logic. the modified module

Following is the content of descriptor src/com.tutorialspoint/HelloWorld.gwt.xml.

TUTORIALS POINT Simply Easy Learning

Page 261

--> --> --> -->

Following is the content of the modified HTML host file war/HelloWorld.html. Hello World UiBinder Demonstration Now create a new UiBinder template and owner class (File -> New -> UiBinder).

TUTORIALS POINT Simply Easy Learning

Page 262

Choose the client package for the project and then name it Login. Leave all of the other defaults.Click Finish button and the plugin will create a new UiBinder template and owner class.

TUTORIALS POINT Simply Easy Learning

Page 263

Now create Login.css file in the src/com.tutorialspoint/client package and place the following contents in it
.blackText { font-family:Arial,Sans-serif; color:#000000; font-size:11px; text-align: left; } .redText { font-family:Arial,Sans-serif; color:#ff0000; font-size:11px; text-align: left; } .loginButton { border:1px solid #3399DD; color:#FFFFFF; background:#555555; font-size:11px; font-weight: bold; margin:05px00; padding:4px10px5px;

TUTORIALS POINT Simply Easy Learning

Page 264

text-shadow:0-1px0#3399DD; } .box { border:1px solid #AACCEE; display: block; font-size:12px; margin:005px; padding:3px; width:203px; } .background { background-color:#999999; border:1px none transparent; color:#000000; font-size:11px; margin-left:-8px; margin-top:5px; padding:6px; }

Now create LoginResources.java file in the src/com.tutorialspoint/client package and place the following contents in it package com.tutorialspoint.client; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.CssResource; public interface LoginResources extends ClientBundle{ /** * Sample CssResource. */ public interface MyCss extends CssResource{ String blackText(); String redText(); String loginButton(); String box(); String background(); } @Source("Login.css") MyCss style(); }

Replace the contents of Login.ui.xml in src/com.tutorialspoint/client package with the following

TUTORIALS POINT Simply Easy Learning

Page 265

Replace the contents of Login.java in src/com.tutorialspoint/client package with the following package com.tutorialspoint.client; import import import import import import import import import import import import com.google.gwt.core.client.GWT; com.google.gwt.event.dom.client.ClickEvent; com.google.gwt.event.logical.shared.ValueChangeEvent; com.google.gwt.uibinder.client.UiBinder; com.google.gwt.uibinder.client.UiField; com.google.gwt.uibinder.client.UiHandler; com.google.gwt.uibinder.client.UiTemplate; com.google.gwt.user.client.Window; com.google.gwt.user.client.ui.Composite; com.google.gwt.user.client.ui.Label; com.google.gwt.user.client.ui.TextBox; com.google.gwt.user.client.ui.Widget;

public class Login extends Composite{ private static LoginUiBinder uiBinder = GWT.create(LoginUiBinder.class); /* * @UiTemplate is not mandatory but allows multiple XML templates * to be used for the same widget. * Default file loaded will be .ui.xml */ @UiTemplate("Login.ui.xml") interface LoginUiBinder extends UiBinder{ } @UiField(provided =true) final LoginResources res; public Login(){ this.res = GWT.create(LoginResources.class); res.style().ensureInjected(); initWidget(uiBinder.createAndBindUi(this)); } @UiField TextBox loginBox; @UiField TextBox passwordBox; @UiField Label completionLabel1; @UiField Label completionLabel2; private Boolean tooShort =false; /*

TUTORIALS POINT Simply Easy Learning

Page 266

* Method name is not relevant, the binding is done according to the class of the parameter. */ @UiHandler("buttonSubmit") void doClickSubmit(ClickEvent event){ if(tooShort){ Window.alert("Login Successful!"); }else{ Window.alert("Login or Password is too short!"); } } @UiHandler("loginBox") void handleLoginChange(ValueChangeEvent event){ if(event.getValue().length()…...

Similar Documents

Free Essay

The Tutorials

...A reminder that tutorials start next Monday - 22 July Please check the list below for your Group. All tutorials will be held in the Engineering Demonstration Theatre Group 1 Group 2 Group 3 Group 4 Group 5 Group 6 Monday Monday Monday Wednesday Wednesday Wednesday 13.30 to 14.20 15.30 to 16.20 16.30 to 17.20 9.30 to 10.20 10.30 to 11.20 11.30 to 12.20 ID 1104002 1108305 1109502 1077831 1102302 1096127 1110048 1111423 1101900 1102570 1109000 1092083 1112768 1106513 1108847 1109555 1109208 1110604 1109145 1109543 1108719 1090471 1085067 1104689 1084561 1109934 1086473 1091955 1108668 1108096 1108204 Tutorial Group 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1107714 1094474 1108322 1103558 1107829 1110185 1108336 1108514 1108472 1036708 1096899 1108999 1108633 1090988 1087104 1099054 1107550 1109424 1109192 1109119 1109019 1110883 1109025 1102940 1107637 1107898 1108102 1108526 1108642 1110989 1107840 1107706 1108412 1108717 1109528 1110552 1099108 1107625 1102621 1108494 1110324 1109260 1109368 1105809 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 1108458 1099247 1090357 1105240 1110811 1108774 1109275 1107503 1109162 1110671 1108262 1108203 1102494 1099126 1112082 1103428 1100142 1110063 1109885 1105419 1107722 1100860 1106818 1101452 1104269 1107364 1111003 1104847 1097638 1104084 Waiver 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 ...

Words: 289 - Pages: 2

Premium Essay

8 Tutorials

...Table of Contents S. No Page No. 1. Tutorial 1………………………………………………………………………… 2 2. Tutorial 2………………………………………………………………………… 5 3. Tutorial 4………………………………………………………………………… 7 4. Tutorial 5………………………………………………………………………… 11 5. Tutorial 6………………………………………………………………………… 14 6. Tutorial 7………………………………………………………………………… 16 7. Tutorial 8………………………………………………………….…………….. 23 Tutorial 1: Question 1. In this paper, Collinson discussed based on shop-floor humor, particular its relationship on the organization. To purpose is to gender identify and working class resistance. 3 main points Collinson made in this paper: * Human as resistance * Human as conformity * Human as control Each element that author gave some exactly examples and databases in the work place and then he analyzed his opinion depend on Willis case study Question 2. There are 3 parts in structure of the paper: * Human as resistance * Human as conformity * Human as control Human as resistance * Shop-floor humor was in part a form of resistance both to the tightly controlled repetitious work tasks and to the social organization of production within a company * Some nicknames come from exaggerated and stereotyped personal characteristics. * Human was shown to operate as one medium through which collective solidarity to resist boredom, the organizational status system and managerial control emerged.......

Words: 5021 - Pages: 21

Free Essay

Jms Tutorial

...executed. For more info on these two swing thread types see http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html ImsCommonsSwing also has a Components class which provides a common way to create swing UI components (JButton, JTextField, JComboBox (with populators), etc) Another useful class is the UncaughtExceptionHandler which, as the name suggests, catches all exceptions which have flowed up the stack and pops up a dialog to the user. A common pattern used in most of our UI applications is the use of ClientContext. This class is extended by project specific classes and usually hold references to remote services. This context class is usually passed around to UI/action classes to gain access to these remote services, dialog manager, window manager, etc. Some other userful classes: DialogManager, WindowManager, SwingHelper, EventDispatchThreadComboBoxPopulator, SwingWorkerThreadComboBoxPopulator Widget/Component classes: TypedComboBoxModel, FormattedTextFieldWithInputValidation, ComboBoxWithWidePopup, AutoCompleteEntryField One of the more painful aspects of Swing UI development is the use of layout managers to lay out the components on the screen. We've tried to standardize on using MigLayout library to try and simplify this task and make it consistent across projects. (See http://www.miglayout.com/) Google Web Toolkit (GWT) http://developers.google.com/web-toolkit/ GWT is an open source set of tools that allows web developers to create and maintain complex......

Words: 6069 - Pages: 25

Free Essay

Tutorial

...UNIVERSITI TUNKU ABDUL RAHMAN Centre Course Year/ Trimester Lecturer : : : : Centre for Foundation Studies Foundation In Science Year 1 Trimester 1 Unit Code Unit Title Session : : : FHSC1114 Physical Chemistry 2014/05 Ms Azlina Banu, Mr Tam Yun Hong, Ms Chong Pui Kuan, Ms Amelia Chiang Kar Mun, Ms Farhanah, Ms Wong Jing Tyng, Ms Jamie Anne, Ms Lau Mei Chien, Mr Ng Sweet Kin, Ms Phang Ying Ning, Ms Precilla, Ms Rachel Tham, Ms Rajalakshmi, Mr Tan Jun Bin, Ms Tan Lee Siew Tutorial 3 : Chapter 3 Stoichiometry and Solution Concentration 1. Balance the following equations: (a) Al(s) + NH4ClO4(s) → Al2O3(s) + AlCl3(s) + NO(g) + H2O(g) (b) GaBr3(aq) + Na2SO3(aq) → Ga2(SO3)3(aq) + NaBr(aq) 2. Ethanol, C2H5OH, is a liquid with a density of 0.789 g ml-1 at 25 °C. Calculate the molarity of ethanol solution made by dissolving 20.00 mL of ethanol at 25 °C in enough water to make 250.0 ml of solution. [Ans: 1.37 mol L-1] 3. Copper sulfate is widely used as a dietary supplement for animal feed. A lab technician prepares a “stock” solution of CuSO4 by dissolving 79.80 g of CuSO4 in enough water to make 500.0 mL of solution. (a) Determine the molarity of the CuSO4 “stock” solution prepared by the technician. [Ans: 1 mol L-1] (b) Calculate the volume of CuSO4 “stock” solution that should be diluted to give 2.5 L of [Ans: 0.25 L] 0.1 M CuSO4. 4. Aluminum is a limiting reactant in the reaction with sulfur gas to form aluminum sulfide. Initially, 1.18 mol of aluminum and 2.25 mol of...

Words: 447 - Pages: 2

Premium Essay

Tutorial

...Business Information Systems Tutorial Week 6 CASE Study 1: Cloud computing * 1.Are the security arrangements for data and applications stored in the cloud the responsibility of the user or the vendor? * Yes it is the responsibility of user to arrange security arrangement for data and applications stored in the cloud because cloud computing help computers by breaking physical bonds between IT infrastructure and their users.Security threats should be taken so that one can fully benefit from this type of new model.In the cloud one can lose control over assets in some respects,Therefore it is necessary to rethink about security arrangement. 2 . Do you agree with Microsoft’s bold prediction that the cloud is the foundation of the 21st-century digital economy? Yes I agree with Microsoft bold prediction that cloud is the foundation of 21st century because it has various advantages over traditional storage on hard drives.People who uses cloud computing can easily access data application from any part of the world.By this hardware cost of the organization can be reduce which results in less requirement of space by the hardware. 3.As an individual user you need to consider whether you would utilise the cloud for data, photo and music storage, among other things. Discuss the reasons for your decision. If cloud for data,photo and music storage works through web app then your browser address bar looks for “https” instead of http,this extra s tells......

Words: 686 - Pages: 3

Free Essay

Flash Tutorial

...Flash Tutorials Trademarks 1 Step RoboPDF, ActiveEdit, ActiveTest, Authorware, Blue Sky Software, Blue Sky, Breeze, Breezo, Captivate, Central, ColdFusion, Contribute, Database Explorer, Director, Dreamweaver, Fireworks, Flash, FlashCast, FlashHelp, Flash Lite, FlashPaper, Flash Video Encoder, Flex, Flex Builder, Fontographer, FreeHand, Generator, HomeSite, JRun, MacRecorder, Macromedia, MXML, RoboEngine, RoboHelp, RoboInfo, RoboPDF, Roundtrip, Roundtrip HTML, Shockwave, SoundEdit, Studio MX, UltraDev, and WebHelp are either registered trademarks or trademarks of Macromedia, Inc. and may be registered in the United States or in other jurisdictions including internationally. Other product names, logos, designs, titles, words, or phrases mentioned within this publication may be trademarks, service marks, or trade names of Macromedia, Inc. or other entities and may be registered in certain jurisdictions including internationally. Third-Party Information This guide contains links to third-party websites that are not under the control of Macromedia, and Macromedia is not responsible for the content on any linked site. If you access a third-party website mentioned in this guide, then you do so at your own risk. Macromedia provides these links only as a convenience, and the inclusion of the link does not imply that Macromedia endorses or accepts any responsibility for the content on those third-party sites. Speech compression and decompression technology licensed from Nellymoser...

Words: 58741 - Pages: 235

Free Essay

Tutorial

...EPPD2023: STATISTIK UNTUK EKONOMI DAN PERNIAGAAN (SET 2) TUTORIAL 2 1. Jadual menunjukkan gaji sehari bagi 85 pekerja di syarikat pembinaan. |Gaji (RM) |Bilangan | |50.00 – 59.99 |10 | |60.00 – 69.99 |14 | |70.00 – 79.90 |20 | |80.00 – 89.99 |16 | |90.00 – 99.99 |13 | |100.00 – 109.99 |12 | |Jumlah |85 | Dari jadual taburan ulangan di atas tentukan yang berikut: a) Min aritmetik, (jw: 80.17) varians dan sisihan piawai gaji pekerja. b) Paras gaji harian di mana 30% dari pekerja memperoleh gaji harian lebih daripadanya. (Jwp:83.42) c) Kepencongan taburan data tersebut. (jwp: kanan sbb mod = 76) 2. Berikut menunjukkan kedudukan pendapatan bulanan 200 orang nelayan di Besut, Terengganu. |Pendapatan |Ulangan | |Bulanan (RM) | | | 1 – 100 |3 | |101 – 200 |28 | |201 – 400 |96 | |401 – 600 |30 | |601 – 1,000 |24 ......

Words: 428 - Pages: 2

Free Essay

Android Tutorial

...Android Tutorial ANDROID TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i ABOUT THE TUTORIAL Android Tutorial Android is an open source and Linux-based operating system for mobile devices such as smartphones and tablet computers. Android was developed by the Open Handset Alliance, led by Google, and other companies. This tutorial will teach you basic Android programming and will also take you through some advance concepts related to Android application development. Audience This tutorial has been prepared for the beginners to help them understand basic Android programming. After completing this tutorial you will find yourself at a moderate level of expertise in Android programming from where you can take yourself to next levels. Prerequisites Android programming is based on Java programming language so if you have basic understanding on Java programming then it will be a fun to learn Android application development. Copyright & Disclaimer Notice All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you......

Words: 22354 - Pages: 90

Premium Essay

C Tutorial

...C Programming Tutorial C PROGRAMMING TUTORIAL Simply Easy Learning by tutorialspoint.com tutorialspoint.com i COPYRIGHT & DISCLAIMER NOTICE  All the content and graphics on this tutorial are the property of tutorialspoint.com. Any content from tutorialspoint.com or this tutorial may not be redistributed or reproduced in any way, shape, or form without the written permission of tutorialspoint.com. Failure to do so is a violation of copyright laws. This tutorial may contain inaccuracies or errors and tutorialspoint provides no guarantee regarding the accuracy of the site or its contents including this tutorial. If you discover that the tutorialspoint.com site or this tutorial content contains some errors, please contact us at webmaster@tutorialspoint.com ii T able of Contents C Language Overview .............................................................. 1 Facts about C ............................................................................................... 1 Why to use C ? ............................................................................................. 2 C Programs .................................................................................................. 2 C Environment Setup ............................................................... 3 Text Editor ................................................................................................... 3 The C Compiler ................................................

Words: 14106 - Pages: 57

Premium Essay

Tutorial

...ECONOMICS, FINANCE AND MARKETING FINANCIAL ECONOMETRICS TUTORIAL EXERCISES We will not use Turnitin in this course; rather tutorials are to be submitted in the assignment box on level 7 in building 80 or sent via the post. Tutorials sent in the mail must be post marked on or before the submission date. Only hard copies will be accepted, also it is best to use a cover sheet. That is, tutorials cannot be submitted by email or via the Learning Hub. ____________________________________________________________________ T1 - 10 marks: DUE DATE: Friday 20th March 2015 SIMPLE LINEAR REGRESSION T1 covers the material in Modules 1 and 2. You are not expected to use material from later modules to answer these questions, but you may need to refer to material covered in Quantitative Methods in Finance and other finance courses. QUESTION 1 – A Cross-sectional study In this question you will be investigating the relationship between exports and imports using a cross-country study. The data needed is on the sheet called countries in the file Tutorial data s1 2015.xls. Economic data on the world’s countries and territories, including exports and imports is sourced from the CIA World Factbook and can be found at: http://www.cia.gov/library/publications/the-world-factbook/ (a) Check and clean the data on exports and imports so it can loaded into Eviews (you will need to do this for all data used in this Tutorial). Checking and setting the data in horizontal line,......

Words: 1720 - Pages: 7

Premium Essay

Database Tutorials

...Database Management Systems Tutorial Week 7 Weight 1% The tutorial assessment each week is generally based on your understanding of the week’s course content, your written answers to each week’s tutorial questions, your group interaction in discussing your answers, and your presentation to the class. You are required to provide written answers to each week’s tutorial questions. The due date for providing answers to each week’s tutorial tasks is by the beginning of your following week’s tutorial session. Make sure to submit your answers to the tutorial questions by its due date electronically using Moodle; and to take with you a printed/hand-written copy of your answers to the next tutorial session. For some questions your tutor may randomly select students to share their answers with the class. For some other questions, your tutor may invite students to discuss their written answers in groups and may ask you to present your group’s collective responses to the class. Due to some particular circumstances, if you are not able to attend a tutorial session, make sure to: a) let your tutor know asap the reason(s) you missed the class by email; b) submit your answers to the tutorial questions by its due date electronically using Moodle. Before attempting the following tutorial activities, you need to learn this week’s lecture slides. To gain more understanding of the topics covered in this week review Chapters: 7.2, 7.3, 7.5, and 8.1 up to but not including 8...

Words: 625 - Pages: 3

Premium Essay

Tutorial

...HRPYC81/103/0/2013 Tutorial Letter 103/0/2013 Research Report HRPYC81 Year module Department of Psychology This tutorial letter contains Projects 4808 to 4813 Bar code CONTENTS READ ME FIRST .......................................................................................................................................... 3 PROJECT 4808 ............................................................................................................................................ 4 PROJECT 4809 ............................................................................................................................................ 5 PROJECT 4810 .......................................................................................................................................... 14 PROJECT 4811 .......................................................................................................................................... 36 PROJECT 4812 .......................................................................................................................................... 42 PROJECT 4813 .......................................................................................................................................... 55 2 HRPYC81/103 READ ME FIRST Tutorial Letter 102 Tutorial Letter contains Assignment 01as well as the following projects: Project 4802 Project 4803 Project 4804 Project 4805 Project 4807 Tutorial Letter 103 Tutorial Letter......

Words: 20483 - Pages: 82

Free Essay

Tutorial Letter

...HRBUS83/101/0/2016 Tutorial Letter 101/0/2016 HRBUS83 - Research Project (Business Management) Department of Business Management IMPORTANT INFORMATION This tutorial letter contains important information about module HRBUS83. YOU MUST READ THROUGH THIS TUTORIAL LETTER AND BECHONB/301/3/2016. Open Rubric CONTENTS Page 1 INTRODUCTION ..........................................................................................................................3 2 PURPOSE OF AND OUTCOMES FOR THE MODULE ................................................................ 3 2.1 Purpose ........................................................................................................................................3 2.2 Learning outcomes .......................................................................................................................4 3 LECTURER(S) AND CONTACT DETAILS................................................................................... 4 3.1 Coordinator and lecturer/supervisor .............................................................................................. 4 3.2 Department ...................................................................................................................................4 3.3 Unisa contact details .....................................................................................................................4 4 MODULE-RELATED RESOURCES ............................................

Words: 5654 - Pages: 23

Premium Essay

Tutorial 11

...Tutorial 11 – Chapter 10 Expatriate Management Tutorial activity 1: Ongoing Semester Case Study – Businessville Hotel. The manager of the Beijing Businessville Hotel is leaving to be the manager of a new hotel elsewhere. Around the World Hotels, the parent company of Beijing Businessville Hotel decides to send one of its very successful managers from Australia to China to manage the Beijing Businessville Hotel. Your role is to train the new manager so you will need to formulate an information sheet for that person. You might like to consider which aspects of Chinese life and culture will be different from that in Australia, what the company can do to ensure that the new manager makes a successful transition, what training will need to be supplied Tutorial activity 2: Video 6 – Global HRM After viewing the video you will be asked to engage in a group discussion based on the following questions: • What factors, other than those discussed in the video, do you think might have contributed to the situation? • What else do you think the company could have done to prepare this person for the overseas assignment? • What should the company do with that employee now? Tutorial activity 3: Facilitation Case Study. Consider the case study ‘Avon in Global Markets in 2009: Managing and Developing a Global Workforce’ on pages 387-392 of your textbook and prepare discussion points for questions 1, 4, 5 & 7 at the end. Tutorial activity 4:......

Words: 276 - Pages: 2

Premium Essay

Tutorial Program

...Australian School of Business School of Taxation and Business Law LEGT 2741 BUSINESS ENTITIES TUTORIAL GUIDE SESSION ONE 2012 1 LEGT 2741 BUSINESS ENTITIES Tutorial Guide TUTORIALS PURPOSE The purpose of the questions in the tutorial guide is to help interpret and apply the lecture material. Additionally, the tutorial problems and questions also allow you to practice for the final exam which will consist of similar questions. Note: there will be no answers given out to the tutorial questions or past exam papers in class or posted to Blackboard. The purpose of the questions is to allow you to apply the course material and gauge your own level of competence. Simply giving you the suggested answers will defeat this purpose. It is your responsibility to attend tutorials prepared so that you can gauge your own level of competence and are able to contribute to class discussion. However, if you are uncertain and wish to explore a topic further or test your understanding of past exam questions, please do not hesitate to consult with your tutor or lecturer. The purpose of this tutorial guide is also to allow students to develop the skills (both verbal and written) necessary to analyse problems which may arise in practice. The guide is designed to allow each student to reach the goal of being able to apply theory, knowledge and problem solving technique to fact situations that may arise in company law. It is essential that students learn to select the important issues...

Words: 9850 - Pages: 40