Loading delay component in Echo3

In the previous section of Echo3 tutorial you must have studied about how you can create a server-side application in the Echo3 web framework using the server side API.

Loading delay component in Echo3

Loading delay component in Echo3

     

In the previous section of Echo3 tutorial you must have studied about how you can create a server-side application in the Echo3 web framework using the server side API. Now in this example we have created an application which will describe how to create delay component loading. To create a delay component loading we have created two java classes DelayServlet.java and DelayApp.java.

DelayServlet.java extends WebContainerServlet and creates a new application instance by returning the DelayApp object. DelayApp class extends the abstract class ApplicationInstance and it must overrides the init() method. The method init() must return an object of type Echo Window. Here we will be creating the object of ContentPane for adding contents to the application window. 

 

 

 

 

Button load =new Button("LOAD WINDOW");
  contentPane.add(load);

Above lines of code creates a Button and add it to the ContentPane. Now on the button click we have called the action listener which will describe that what action is to be performed when button is clicked. Here is the code for action to be performed as given below.

 load.addActionListener(new ActionListener() {
 
public void actionPerformed(ActionEvent e) {
  try
  {
  Thread.sleep(5000L);
  windowPane.setTitle("Welcome! to ROSEINDIA");
  windowPane.setTitleInsets(new Insets(105));
  windowPane.setInsets(new Insets(10));
  windowPane.setWidth(new Extent(500));
  windowPane.setHeight(new Extent(280));
  windowPane.setStyleName("Glass Blue");
  windowPane.setModal(true);
  windowPane.add(new Label("Window loaded after 5 seconds"));
  contentPane.add(windowPane);
  }
  catch(InterruptedException ex) { }
  }
  });

Here is the full code of application.

DelayServlet.java

package delay;

import nextapp.echo.app.ApplicationInstance;
import nextapp.echo.webcontainer.WebContainerServlet;

public class DelayServlet extends WebContainerServlet {

  public ApplicationInstance newApplicationInstance() {
  return new DelayApp();
  }
}

DelayApp.java

package delay;

import nextapp.echo.app.ApplicationInstance;
import nextapp.echo.app.ContentPane;
import nextapp.echo.app.Label;
import nextapp.echo.app.Window;
import nextapp.echo.app.*;


import nextapp.echo.app.event.ActionListener;
import nextapp.echo.app.event.ActionEvent;

public class DelayApp extends ApplicationInstance {

 private WindowPane windowPane;
 private ContentPane contentPane;

  public Window init() {
  Window window = new Window();
  window.setTitle("Delay example");
  contentPane = new ContentPane();
 windowPane = new WindowPane();
  Button load =new Button("LOAD WINDOW");
  contentPane.add(load);
  load.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent e) {
  try
  {
  Thread.sleep(5000L);
  windowPane.setTitle("Welcome! to ROSEINDIA");
  windowPane.setTitleInsets(new Insets(105));
  windowPane.setInsets(new Insets(10));
  windowPane.setWidth(new Extent(500));
  windowPane.setHeight(new Extent(280));
  windowPane.setStyleName("Glass Blue");
  windowPane.setModal(true);
  windowPane.add(new Label("Window loaded after 5 seconds"));
  contentPane.add(windowPane);
  }
  catch(InterruptedException ex) { }
  }
  });
  window.setContent(contentPane);
  return window;
  }  

Output :

When user click on the button "LOAD WINDOW" it starts loading window and it takes 5 seconds in loading window since we have programmed it to do so.

Download Project Source Code