Friday, 18 May 2012

client bundle using gwt

Paste thisproject.gwt.xml
 <inherits name="com.google.gwt.resources.Resources" />

For image ,textfile and pdf

1)create  a folder image in workspace  client folder(with some image) sameas create text folder and paste any .txt file and last create a pdf folder and any pd f paste in folder

2) go to client folder in ide than click new and select client bundle .

3)clientbundle.java

package com.ruchi.bundle.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.PushButton;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextArea;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class ClientBundle implements EntryPoint {
/**
* The message displayed to the user when the server cannot be reached or
* returns an error.
*/
private static final String SERVER_ERROR = "An error occurred while "
+ "attempting to contact the server. Please check your network "
+ "connection and try again.";

/**
* Create a remote service proxy to talk to the server-side Greeting service.
*/

/**
* This is the entry point method.
*/
public void onModuleLoad() {
 Grid grid = new Grid(5, 5);
       grid.setBorderWidth(1);

       int numRows = grid.getRowCount();
       int numColumns = grid.getColumnCount();
       for (int row = 0; row < numRows; row++)
       {
         for (int col = 0; col < numColumns; col++)
         {
             grid.setWidget(row, col, new Image(Resource.INSTANCE.alpha1()));
           
         }
       }

       RootPanel.get().add(grid);
     //  Window.alert(Resource.INSTANCE.ruchi().getText());
     
       AbsolutePanel abs=new AbsolutePanel();
       abs.setSize("500px","400px");
     
       TextArea myTextArea=new TextArea();
       myTextArea.setSize("400px","300px");
       abs.add(myTextArea);
     
       myTextArea.setText(Resource.INSTANCE.ruchi().getText());
       RootPanel.get().add(abs);
     
       HorizontalPanel hrzz=new HorizontalPanel();
       hrzz.setSize("1000px", "500px");
       Frame f=new Frame(Resource.INSTANCE.taxUpdatesForJune2012Exams().getUrl());
       f.setSize("1000px", "500px");
       hrzz.add(f);
       RootPanel.get().add(hrzz);
     
   }
}


4) Resource.java

package com.ruchi.bundle.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.DataResource;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.resources.client.TextResource;
import com.google.gwt.resources.client.ClientBundle.Source;

public interface Resource extends ClientBundle {
public static final Resource INSTANCE =GWT.create(Resource.class);
@Source("com/ruchi/bundle/images/alpha1.jpg")
ImageResource alpha1();
@Source("com/ruchi/bundle/text/ruchi.txt")
public TextResource ruchi();
@Source("com/ruchi/bundle/pdf/Tax updates for June 2012 Exams.pdf")
DataResource taxUpdatesForJune2012Exams();

@Source("com/ruchi/bundle/images/Back.gif")
ImageResource back();

@Source("com/ruchi/bundle/images/joinus.gif")
ImageResource joinus();

@Source("com/ruchi/bundle/images/next.gif")
ImageResource next();

}


No comments:

Post a Comment