The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

dato.java (1) [Avatar] Offline
#1
Hello ,

I am developing little web application using GWT 2.1 in my Application class where i override onModuleLoad() have the following code:

public void onModuleLoad() {
Button b = new Button("Click");
b.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
try {
Thread.currentThread().sleep(5000);
Window.alert("After 5 seconds");
} catch (Exception ex) {
Window.alert(ex.getMessage());
}

}
});

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

but when i compile the code using maven it gets following error:


[INFO] Compiling module david.chokhonelidze.gxt.status.Application
[INFO] Validating newly compiled units
[INFO] [ERROR] Errors in 'file:/D:/java/Maven/GWT/workspace/gxt-status/src/main/java/david/chokhonelidze/gxt/status/client/Application.java'
[INFO] [ERROR] Line 16: No source code is available for type java.lang.Thread; did you forget to inherit a required module?
[INFO] Finding entry point classes
[INFO] [ERROR] Unable to find type 'david.chokhonelidze.gxt.status.client.Application'
[INFO] [ERROR] Hint: Previous compiler errors may have made this type unavailable
[INFO] [ERROR] Hint: Check the inheritance chain from your module; it may not be inheriting a required module or a module may not be adding its source path entries properly
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE



did i miss anything? here is my Application.gw.xml file

<module>
<inherits name="com.google.gwt.user.User" />

<entry-point class="david.chokhonelidze.gxt.status.client.Application" />

</module>


is it really possible to use J2SE classes in client module ,if yes please tell how?
adam.tacy (269) [Avatar] Offline
#2
Re: Using J2SE classes inside GWT client module
Hi,

GWT supports a subset of J2SE that is sensible in the browser. You can find what is supported here: http://code.google.com/intl/sv-SE/webtoolkit/doc/latest/RefJreEmulation.html

As the browser is single threaded, support of Thread does not make too much sense when you Java GWT program gets compiled to JavaScript. However, if you are looking at delaying something for a period of time, you can use the GWT Timer object, i.e.

public void onModuleLoad() {
Button b = new Button("Click");
b.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
Timer timer = new Timer() {
public void run() {
Window.alert ("After 5 seconds");
}
};

// Execute the timer to run after 5 seconds
timer.schedule(5000);
});

Hope that helps

//Adam