Java-based Ajax Tool-GWT

Source: Internet
Author: User

First download GWT, http://code.google.com/webtoolkit /;

Run-> cmd to create a project folder: C:/> mkdir myproject;

Set Path: C:/> set Path = % java_home %/bin; % gwt_home %;

The applicationcreator. CMD command supports the following syntax:

ApplicationCreator [-eclipse projectName] [-out dir] [-overwrite] [-ignore] className

Go to the myproject directory and run projectcreator-Eclipse myproject;

Continue executing applicationcreator-Eclipse myproject com. mycompany. Client. myapplication;

In this case, runMyapplication-shell will see the Google Web Toolkit development shell and wrapper HTML for myapplication two Google interfaces, and there is a simple button to test in the latter; ExecuteMyapplication-compile will be compiled;

Start eclipse, import an existing project, and select myproject to view the complete structure directory of the GWT application :)

Among them, the com. mycompany. Client. myapplication class is the page layout program. I changed it and added

Frame, with a result similar to the registered user entering the user name and prompting whether the user name is occupied, the Code is as follows:

Package com. mycompany. client;

Import com. Google. GWT. Core. Client. entrypoint;
Import com. Google. GWT. User. Client. UI. Button;
Import com. Google. GWT. User. Client. UI. clicklistener;
Import com. Google. GWT. User. Client. UI. label;
Import com. Google. GWT. User. Client. UI. rootpanel;
Import com. Google. GWT. User. Client. UI. widget;
Import com. Google. GWT. User. Client. window;
Import com. Google. GWT. User. Client. UI. frame;
Import com. Google. GWT. User. Client. UI. textbox;
Import com. Google. GWT. User. Client. UI .*;

/**
* Entry point Classes define <code> onmoduleload () </code>.
*/
Public class myapplication implements entrypoint {

/**
* This is the entry point method.
*/
Public void onmoduleload (){
Final button = new button ("Click me ");
Final label Label = new label ();
Final label label1 = new label ();
// Make a new frame, and point it at Google.
Frame frame = new frame ("http://www.google.com /");

// Add it to the root panel.
Rootpanel. Get (). Add (FRAME );

Final textbox TB = new Textbox ();
TB. addfocuslistener (New focuslistener (){
Public void onfocus (widget sender ){
}
Public void onlostfocus (widget sender ){
If (Tb. gettext (). Equals ("Ryan "))

Label1.settext ("Welcome! ");


Else
Label1.settext ("error! ");
}
});

Rootpanel. Get (). Add (TB );

Rootpanel. Get (). Add (label1 );

Button. addclicklistener (New clicklistener (){
Public void onclick (widget sender ){
If (Label. gettext (). Equals (""))
{Label. settext ("Hello world! ");
Window. Alert ("ajax ");
}
Else
Label. settext ("");
}
});

// Assume that the host HTML has elements defined whose
// IDs are "slot1", "slot2". In a real app, you probably wocould not want
// To hard-code IDs. Instead, you cocould, for example, search for all
// Elements with a participant CSS class and replace them with widgets.
//
Rootpanel. Get ("slot1"). Add (button );
Rootpanel. Get ("slot2"). Add (Label );
}
}

After modification, compile myapplication-compileand test myapplication.html in IE,

You can also execute myapplication-shell and use the debugger that comes with GWT to view the effect.

In short, GWT implements a wide range of Ajax effects using pure Java. GWT contains various HTML components and uses Java

The traditional event processing mechanism can be quickly used by people familiar with Java.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.