Java Program to Goto a Link Using Applet Last Updated : 29 Dec, 2023 Comments Improve Suggest changes Like Article Like Report In this article, we shall be animating the applet window to show the goto link in Java Applet. A Goto link is basically, any particular link that redirects us from one page to another. Approach to Implement Goto a Link using AppletCreate an applet with the two buttons.Add ActionListener to the buttons.Form the complete URL of the page.Use the Desktop class of java.awt package to open the link.Note: Java Version : 1.8 and above required Goto a Link using Java AppletBelow is the implementation of the above method: Java // Java Program to implement // Java Applet for goto a link import java.applet.*; import java.awt.*; import java.awt.Desktop.*; import java.awt.event.*; import java.net.*; // Driver Class public class GotoLink extends Applet implements ActionListener { // Function to initialize the applet public void init() { setBackground(Color.white); // Button Created Button b1 = new Button("google"); Button b2 = new Button("facebook"); this.add(b1); this.add(b2); // Action Listener to check which option choose b1.addActionListener(this); b2.addActionListener(this); } // Function to go to the link public void actionPerformed(ActionEvent e) { String button = e.getActionCommand(); String link = "https://www." + button + ".com"; try { Desktop.getDesktop().browse(new URI(link)); } catch (Exception ex) { ex.printStackTrace(); } } } /* <applet code=GotoLink.class width=400 height=400> </applet> */ Executing the Applet ProgramSave the file with the name GotoLink.javajavac GotoLink.javaApplet Viewer GotoLink.javaOutputTest case 1: Applet Output Test Case 2 : When user click on google button Test Case 2 : When user click on facebook button Explaination of the Above Program For Example: https://www.geeksforgeeks.org/ or https://www.google.com/Use Desktop class to handle the URI (Uniform Resource Identifier) file.Use method browse(URI) to open the link in the default browser of the system eg. Google Chrome.public void init() function is used to initialize the applet.public void actionPerformed(ActionEvent e) fucntion is used to check on button click what logic we have to perform in our case it will take us to external url like google.com or facebook.comAction Listener is used to check which button is selected. Comment More infoAdvertise with us Next Article Java Program to Goto a Link Using Applet akhilmaurya Follow Improve Article Tags : Java Geeks Premier League Geeks Premier League 2023 Practice Tags : Java Similar Reads How to Use Swing Applet in Java? In this article, we will be using the swing Applet or JApplet in Java. Here, we will make a simple multiplication application that will multiply the two input numbers. Approach to Using Swing Applet in JavaWe need to import the packages for Swing and AWT Components.Once the packages are imported, we 4 min read Java Program to Create Different Shapes using Applet In this article, we will be creating different shapes using Applet. Here, we have taken an Input field, where the user can enter the name of the shape and click on the button. After clicking on the button, the shape that is entered will get drawn on the Applet window. OverviewInitially, we have to i 4 min read How to Read a File using Applet? In this article, we will learn how to read the content of the file using Java and display those contents using Applet. Approach UsedThe user should type the name of the file in the input field that asks for the filename in the output applet window. If the file is already present, it will display the 2 min read How to Draw a Car using Java Applet? An Applet is a Java program that runs in a web browser. An Applet is a Java class that extends the java.applet.Applet class, which means that to create any Applet, you need to import this class and extend it in your Applet class. The applet does not have a main() method. Applets are designed to embe 2 min read How to Open a Link in a New Window Using Applet? A Java applet is a little application created in the Java programming language and run on a web browser while embedded in an HTML page. In essence, it's a method for introducing Java's "write once, run anywhere" feature to the world of web browsers. Components and OrganizationApplets are subclasses 9 min read How to Play Audio File (.WAV) Using Java Applet? In this article, we will learn how to read and play audio (.wav) files using Java Applet. Approach for Playing Audio File(.wav) using AppletMusicPlayerApplet class inherits the property of Applet in Java. The interface consists of the input text field to enter a filename with an extension of the aud 3 min read How to Install Java Applet Viewer on Linux? Applet viewer is a command-line program to run a java applet. It helps you to test an applet before you run it in the browser. The applet's code gets transferred to the system & then the Java Virtual Machine (JVM) of the browser & executes that code. In this article, we will look into the pr 2 min read How to Create a Banner Using Applet? In this article, we shall be building a Java Applet that shows a scrolling banner with a message that moves continually from right to left. In this article, you will learn the fundamentals of Java Applet Basics by creating a banner using Applet. Note: java.applet package package has been deprecated 6 min read How to Get All Available Links on the Page using Selenium in Java? Selenium is an open-source Web-Automation tool that is used to automate web Browser Testing. The major advantage of using selenium is, that it supports all major web browsers and works on all major Operating Systems, and it supports writing scripts on various languages such as Java, Â JavaScript, C# 2 min read How to Play Sound using Applet? In this article, we will be using the Applet window to play the sound or music. Here, we will have buttons like Play, Pause, and Restart. Using these buttons we will manage the sound in the Applet window. Approach for Playing Sound Using AppletWe need to import the essential packages like Applet and 4 min read Like