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
No comments:
Post a Comment