Results 1 to 2 of 2
  1. #1
    Java Example is offline Moderator
    Join Date
    Sep 2014
    Posts
    27
    Rep Power
    0

    Default How to create hyperlink using GWT?

    In this tutorial, we will illustrate how to create Hyperlink using GWT. The steps involved in Building the Hyperlink are described below:-

    private Label label = new Label()
    Here we are declaring label. Label is a widget that contains text.

    Hyperlink link0 = new Hyperlink("Delhi", "Delhi")

    Creating Hyperlink object named 'link0'. Hyperlink is a class or a widget that serves as an "internal" hyperlink

    VerticalPanel panel = new VerticalPanel()
    Creating Vertical panel. Vertical panel is a class that lays all of its widgets out in a single vertical column.

    panel.add(label)
    This is the method of class Vertical panel. By using this method we added a label to the Panel

    History.addHistoryListener(this)

    History is a class that allows us to interact with the browser's history stack. addHistoryListener() is a method of this class to adds a listener to the browser's history stack.


    Java Code: To create hyperlink using GWT
    package org.hyperLink.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.HistoryListener;
    import com.google.gwt.user.client.History;
    import com.google.gwt.user.client.ui.Label;
    import com.google.gwt.user.client.ui.Hyperlink;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.google.gwt.user.client.ui.VerticalPanel;
    
    public class HyperLinkExample implements EntryPoint, HistoryListener {
    
        private Label label = new Label();
    
        public void onModuleLoad() {
            Hyperlink link0 = new Hyperlink("Delhi", "Delhi");
            Hyperlink link1 = new Hyperlink("Mumbai", "Mumbai");
            Hyperlink link2 = new Hyperlink("Chennai", "Chennai");
            Hyperlink link3 = new Hyperlink("Banglore", "Banglore");
    
            String Token = History.getToken();
            if (Token.length() == 0) {
                History.newItem("Banglore");
            }
            VerticalPanel panel = new VerticalPanel();
            panel.add(label);
            panel.add(link0);
            panel.add(link1);
            panel.add(link2);
            panel.add(link3);
            RootPanel.get().add(panel);
            History.addHistoryListener(this);
            History.fireCurrentHistoryState();
        }
    
        public void onHistoryChanged(String historyToken) {
            label.setText("The current Link selected is: " + historyToken);
        }
    }
    Main
    
    .gwt.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <module>
      <inherits name="com.google.gwt.user.User"/>
      <entry-point class  
    
    ="org.hyperLink.client.HyperLinkExample"/>
      
    </module>

    Output of the program

    How to create hyperlink using GWT?-hlink.jpg

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: How to create hyperlink using GWT?

    Moved from GWT

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 3
    Last Post: 02-11-2013, 07:57 PM
  2. Getting the hyperlink URL
    By leifster in forum New To Java
    Replies: 1
    Last Post: 11-27-2010, 05:01 PM
  3. get data from hyperlink
    By shyameni in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 02-19-2010, 10:32 AM
  4. How to create a hyperlink from a text in Java
    By javanewbie in forum New To Java
    Replies: 2
    Last Post: 06-05-2009, 02:12 PM
  5. Hyperlink in swing
    By aneesahamedaa in forum AWT / Swing
    Replies: 1
    Last Post: 07-28-2008, 03:41 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •