Google Web Toolkit (GWT) 2.0 Application Development

«»

SHARE & COMMENT :

Adding the banner

This recipe will create a method that we will use to add a banner in the content panel.

Getting ready

Place the banner image banner.png at the location \web\resources\images. You
can use your own image or get it from the code sample provided for this book on the Packt
Publishing website (www.packtpub.com).

How to do it…

    1. Create the method getBanner:

 public ContentPanel getBanner()
 {
 ContentPanel bannerPanel = new ContentPanel();
 bannerPanel.setHeaderVisible(false);
 bannerPanel.add(new Image("resources/images/banner.png"));
 Image("resources/images/banner.png"));
 return bannerPanel;
 }
 
    1. Call the method setTopComponent of the ContentPanel class in the following
      constructor:

 setTop Component(getBanner());
 

How it works…

The method getBanner() creates an instance bannerPanel of type ContentPanel. The
bannerPanel will just show the image from the location resources/images/banner.
png. That’s why, the header is made invisible by invoking setHeaderVisible(false).
Instance of the com.google.gwt.user.client.ui.Image class, which represents the
banner image, is added in the bannerPanel.

In the default constructor of the HomePage class, the method
setTopComponent(getBanner()) is called to set the image as the top component of the
content panel.

See also

  • The Creating the home page layout class recipe
  • The Adding menus recipe
  • The Creating the left-hand sidebar recipe
  • The Creating the right-hand sidebar recipe
  • The Creating main content panel recipe
  • The Creating the footer recipe
  • The Using the HomePage instance in EntryPoint recipe

Adding menus

In this recipe, we will create a method getMenuBar that does the following:

  • Creates a menu bar
  • Creates menus
  • Creates menu items
  • Adds menu items in menus
  • Adds menus in the menu bar

How to do it…

Write the method header pu blic MenuBar getMenuBar(), and do the following in the
method body. Finally, this method should be called in the constructor of the class HomePage
to add the menu bar in the application.

    1. Create an instance of MenuBar:

 MenuBar menuBar=new MenuBar();
 
    1. Create instances of Menu:

 Menu fileMenu=new Menu();
 Menu reportsMenu=new Menu();
 Menu helpMenu=new Menu();
 
    1. Create the menu items and add them in corresponding menus:

 //Items for File menu
 MenuItem productMenuItem=new MenuItem("Product");
 fileMenu.add(productMenuItem);
 MenuItem stockMenuItem=new MenuItem("Stock");
 fileMenu.add(stockMenuItem);
 MenuItem purchaseMenuItem=new MenuItem("Purchase");
 fileMenu.add(purchaseMenuItem);
 MenuItem salesMenuItem=new MenuItem("Sales");
 fileMenu.add(salesMenuItem);
 //Items for Reports menu
 MenuItem productListMenuItem=new MenuItem("Product List");
 reportsMenu.add(productListMenuItem);
 MenuItem stockStatusMenuItem=new MenuItem("Stock Status");
 reportsMenu.add(stockStatusMenuItem);
 MenuItem purchaseDetailMenuItem=new MenuItem(
 "Purchase Detail");
 reportsMenu.add(purchaseDetailMenuItem);
 MenuItem salesDetailMenuItem=new MenuItem("Sales Detail");
 reportsMenu.add(salesDetailMenuItem);
 //Items for Help menu
 MenuItem aboutMenuItem=new MenuItem("About");
 helpMenu.add(aboutMenuItem);
 
    1. Create the menu bar items:

 MenuBarItem menuBarItemFile=new MenuBarItem("File",fileMenu);
 MenuBarItem menuBarItemReports=
 new MenuBarItem("Reports",reportsMenu);
 MenuBarItem menuBarItemHelp=
 new MenuBarItem("Help",helpMenu);
 
    1. Add the menu bar items in menu bar:

 menuBar.add(menuBarItemFile);
 menuBar.add(menuBarItemReports);
 menuBar.add(menuBarItemHelp);
 
    1. Return the menu bar:

 return menuBar;
 

How it works…

The menu bar containing all the required menus with menu items is created in the
following ways:

    1. MenuBar instance menuBar is created where the menu bar items will be added.
    2. Three menus are created for File, Reports, and Help.
    3. Menu items are created and added under corresponding menus.
    4. Three instances of MenuBarItem are created for the three menus.
    5. All of the menu bar items are added in the menu bar. Call this
      method in the HomePage constructor by writing add(getMenuBar,
      menuBarToolBarLayoutData).

See also

  • The Creating the home page layout class recipe
  • The Adding the banner recipe
  • The Creating the left-hand sidebar recipe
  • The Creating the right-hand sidebar recipe
  • The Creating the main content panel recipe
  • The Creating the footer recipe
  • The Using the HomePage instance in EntryPoint recipe

GWT Articles & Books

«»

Comments

comments

Pages: 1 2 3 4

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better