Javafx - Application - Digital Assignment
Javafx - Application - Digital Assignment
1. JAVA FX:
JavaFx Controls
JavaFX Menu
The webpage is created using JavaFX in Eclipse IDE. There is a Menu Bar
at the top, which is Created using MenuBar object. There are two
Buttons at the bottom of the page, on clicking, the text gets
displayed.setOnAction() method is used to perform this Action.
Screenshot:
Source Code:
import com.sun.prism.paint.Color;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontPosture;
import javafx.scene.text.FontWeight;
import javafx.stage.Stage;
public class MyApplication extends Application{
Label message;
@Override
exitMenuItem.setOnAction(actionEvent->Platform.exit());
menuBar.getMenus().addAll(FileMenu);
FileMenu.getItems().addAll(copyMenuItem,cutMenuItem,pasteMenuItem,
new SeparatorMenuItem(), exitMenuItem);
exitMenuItem.setOnAction(actionEvent->Platform.exit());
menuBar.getMenus().addAll(FileMenu1);
btn1.setText("Topic");
btn2.setText("Name");
btn1.setOnAction(new EventHandler<ActionEvent>(){
@Override
}
);
btn2.setOnAction((ActionEvent e)->{
message.setText("Sanjana");
message.setFont(Font.font("Monotype Corsiva",FontWeight.BOLD,60));
});
root.setCenter(message);
HBox buttons = new HBox();
buttons.getChildren().addAll(btn1,btn2);
root.setBottom(buttons);
root.setTop(menuBar);
primaryStage.setTitle("My Application");
primaryStage.setScene(scene);
primaryStage.show();
}
}