JavaFX Tutorial 12 - Hyperlink Java GUI

Опубликовано: 12 Май 2025
на канале: Code Amir
1,523
12

JavaFX Tutorial 12 Hyperlink Java GUI
Code Source:
@Override
public void start(Stage primaryStage) {
HBox h = new HBox();
Hyperlink hlink = new Hyperlink("www.youtube.com");
hlink.setOnAction(new EventHandler ActionEvent () {
@Override
public void handle(ActionEvent event) {
JOptionPane.showMessageDialog(null, "Your Link" + hlink.getText());
}
});
Libraries Importing :
import java.util.ArrayList;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import javax.swing.JOptionPane;

The JavaFX Hyperlink control is a text that functions as a button, meaning you can configure a Hyperlink to perform some action when the user clicks it. Just like a hyperlink in a web page. The JavaFX Hyperlink control is represented by the class javafx.scene.control.Hyperlink .
h.getChildren().addAll(hlink);
Scene sc = new Scene(h,600,400);
primaryStage.setScene(sc);
primaryStage.setTitle("Tutorial JavaFX");
primaryStage.show();