Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is my javafx code. I want to edit like output. My cancel button is not working. This is output. This is my code. import
This is my javafx code. I want to edit like output.
My cancel button is not working.
This is output.
This is my code.
import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.HPos; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.ColumnConstraints; import javafx.scene.layout.GridPane; import javafx.scene.layout.Priority; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.stage.Stage; import javafx.scene.Node; public class project extends Application { private Label FirstNameLabel; private Label LastNameLabel; private Label EmailLabel; private Label PhoneLabel; private Label AddressLabel; private Label NotesLabel; private TextField FirstNameTextField; private TextField LastNameTextField; private TextField EmailTextField; private TextField PhoneTextField; private TextField AddressTextField; private TextField NotesTextField; private Button CancelButton; private Button SaveButton; public static void main(String[] args) {launch();} public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Contact"); Font font = Font.font("Arial", FontWeight.BOLD,12); GridPane gridPane = createRegistrationFormPane(); createLabels(font); createInputFields(); CancelButton = new Button("Cancel"); CancelButton.setOnAction(e->Cancel()); CancelButton.setFont(font); SaveButton = new Button("Save"); SaveButton.setOnAction(e->Save()); SaveButton.setFont(font); addElements(gridPane); Scene scene = new Scene(gridPane, 400,400); primaryStage.setScene(scene); primaryStage.show(); } private Object Cancel() { return null; } private Object Save() { return null; } private void createLabels(Font font) { FirstNameLabel = new Label("First Name"); LastNameLabel = new Label("Last Name"); EmailLabel = new Label("Email"); PhoneLabel = new Label("Phone"); AddressLabel = new Label("Address"); NotesLabel = new Label("Notes"); FirstNameLabel.setFont(font); LastNameLabel.setFont(font); EmailLabel.setFont(font); PhoneLabel.setFont(font); AddressLabel.setFont(font); NotesLabel.setFont(font); } private void createInputFields() { FirstNameTextField = new TextField(); LastNameTextField = new TextField(); EmailTextField = new TextField(); PhoneTextField = new TextField(); AddressTextField = new TextField(); NotesTextField = new TextField(); } private void addElements(GridPane gridPane) { gridPane.add(FirstNameLabel,0,0,2,1); gridPane.add(FirstNameTextField,0,1,2,1); gridPane.add(LastNameLabel,0,2,2,1); gridPane.add(LastNameTextField,0,3,2,1); gridPane.add(EmailLabel,0,4,2,1); gridPane.add(EmailTextField,0,5,2,1); gridPane.add(PhoneLabel,0,6,2,1); gridPane.add(PhoneTextField,0,7,2,1); gridPane.add(AddressLabel,0,8,2,1); gridPane.add(AddressTextField,0,9,2,1); gridPane.add(NotesLabel,0,10,2,1); gridPane.add(NotesTextField,0,11,2,1); gridPane.add(CancelButton,0,12,1,1); gridPane.setHalignment(CancelButton, HPos.RIGHT); gridPane.add(SaveButton,1,12,1,1); SaveButton.setMaxWidth(70); SaveButton.setMinWidth(50); SaveButton.setAlignment(Pos.CENTER); CancelButton.setMaxWidth(70); CancelButton.setMinWidth(50); CancelButton.setAlignment(Pos.CENTER); } private GridPane createRegistrationFormPane() { GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setPadding(new Insets(20)); gridPane.setHgap(20); gridPane.setVgap(5); ColumnConstraints columnOneConstraints = new ColumnConstraints(140,140,Double.MAX_VALUE); columnOneConstraints.setHalignment(HPos.CENTER); ColumnConstraints columnTwoConstrains = new ColumnConstraints(60,60,Double.MAX_VALUE); columnTwoConstrains.setHgrow(Priority.ALWAYS); columnTwoConstrains.setHalignment(HPos.RIGHT); gridPane.getColumnConstraints().addAll(columnOneConstraints, columnTwoConstrains); return gridPane; } }Contact Information First Name Last Name Email Phone Address Notes Cancel Save
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started