You may adjust the code as you want. Thank you!
CODING HERE:
import javafx.application.Application;
import javafx.event.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.*;
import javafx.geometry.*;
public class OrderSystem extends Application implements
EventHandler<ActionEvent>
{
// Attributes for GUI
private Stage stage; // The entire window, including title bar and
borders
private Scene scene; // Interior of window
private BorderPane layout;
// Add four labels
private Label itemLabel = new Label("Item Name:");
private Label numberLabel = new Label("Number:");
private Label costLabel = new Label("Cost:");
private Label amountOwedLabel = new Label("Amount Owed:");
// add four textfields for labels
private TextField itemName = new TextField();
private TextField number = new TextField();
private TextField cost = new TextField();
private TextField amountOwed = new TextField();
// add buttons
private Button btnCalc = new Button("Calculate"); //To calculate
the result
private Button btnSave = new Button("Save"); //To save the
result
private Button btnClear = new Button("Clear"); //To clear the
result
private Button btnExit = new Button("Exit"); //To exit the
program
private Button btnLoad = new Button("Load"); //To load the
data
private Button btnPrev = new Button("<Prev"); //To previous the
data
private Button btnNext = new Button(">Next"); //To next the
data
private Button btnCalcSave = new Button("Calculate & Save");
//To calculate then save
// Main of this GUI class
public static void main(String [] args)
{
launch(args);
} // end of main
public void start(Stage _stage) throws Exception
{
stage = _stage; // save stage as an attribute
stage.setTitle("Quoc Huynh Item Orders Calculator"); // set the
text in the title bar
layout = new BorderPane();
FlowPane loTop = new FlowPane(10, 10);
loTop.setAlignment(Pos.CENTER);
loTop.getChildren().add(itemLabel);
loTop.getChildren().add(itemName);
loTop.getChildren().add(numberLabel);
loTop.getChildren().add(number);
loTop.getChildren().add(costLabel);
loTop.getChildren().add(cost);
loTop.getChildren().add(amountOwedLabel);
loTop.getChildren().add(amountOwed);
layout.setTop(loTop);
scene = new Scene(layout, 300, 200);
stage.setScene(scene);
stage.show();
}
public void handle(ActionEvent ae)
{
Button btn = (Button)ae.getSource();
}
}
import javafx.application.Application; import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.control.Alert.AlertType; import javafx.scene.layout.*; import javafx.stage.*; import javafx.geometry.*; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class OrderSystem extends Application implements EventHandler<ActionEvent> { // Attributes for GUI private Stage stage; // The entire window, including title bar and borders private Scene scene; // Interior of window private VBox layout; // Add four labels private Label itemLabel = new Label("Item Name:"); private Label numberLabel = new Label("Number:"); private Label costLabel = new Label("Cost:"); private Label amountOwedLabel = new Label("Amount Owed:"); // add four TextFields for labels private TextField itemName = new TextField(); private TextField number = new TextField(); private TextField cost = new TextField(); private TextField amountOwed = new TextField(); // add buttons private Button btnCalc = new Button("Calculate"); // To calculate the result private Button btnSave = new Button("Save"); // To save the result private Button btnClear = new Button("Clear"); // To clear the result private Button btnExit = new Button("Exit"); // To exit the program private Button btnLoad = new Button("Load"); // To load the data private Button btnPrev = new Button("<Prev"); // To previous the data private Button btnNext = new Button(">Next"); // To next the data // ArrayList to hold items ArrayList<String> records = new ArrayList<String>(); int currentRecordIndex = 0; final String FILE_NAME = "121Lab1.csv"; // Main of this GUI class public static void main(String[] args) { launch(args); } // end of main private void loadRecordIndex(int index) { String firstLine = records.get(index); currentRecordIndex = index; String parts[] = firstLine.split(","); itemName.setText(parts[0]); number.setText(parts[1]); cost.setText(parts[2]); amountOwed.setText(String.format("%.2f", Double.parseDouble(parts[1]) * Double.parseDouble(parts[2]))); calculateCurrentData(); } private void calculateCurrentData() { try { System.out.println(Double.parseDouble(number.getText()) * Double.parseDouble(cost.getText())); amountOwed.setText( String.format("%.2f", Double.parseDouble(number.getText()) * Double.parseDouble(cost.getText()))); } catch (NumberFormatException e) { e.printStackTrace(); } } private void saveCurrentDataInList() { calculateCurrentData(); records.add(String.format("%s,%s,%s,%s", itemName.getText(), number.getText(), cost.getText(), amountOwed.getText())); } private void writeDataToFile() { try { BufferedWriter writer = new BufferedWriter(new FileWriter(FILE_NAME)); for (String line : records) { writer.write(line + "\n"); } writer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public int load() { try { BufferedReader reader = new BufferedReader(new FileReader(FILE_NAME)); String line; records.clear(); while ((line = reader.readLine()) != null) { if (!line.isEmpty()) { records.add(line); } } reader.close(); if (records.size() == 0) { return 0; } loadRecordIndex(0); return records.size(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return -1; } public void start(Stage _stage) throws Exception { stage = _stage; // save stage as an attribute stage.setTitle("Quoc Huynh Item Orders Calculator"); // set the text in the title bar GridPane grid = new GridPane(); grid.setAlignment(Pos.CENTER); grid.setHgap(10); grid.setVgap(3); grid.setPadding(new Insets(5, 5, 5, 5)); grid.add(itemLabel, 0, 0); GridPane.setHalignment(itemLabel, HPos.RIGHT); grid.add(itemName, 1, 0); grid.add(numberLabel, 0, 1); GridPane.setHalignment(numberLabel, HPos.RIGHT); grid.add(number, 1, 1); grid.add(costLabel, 0, 2); GridPane.setHalignment(costLabel, HPos.RIGHT); grid.add(cost, 1, 2); grid.add(amountOwedLabel, 0, 3); GridPane.setHalignment(amountOwedLabel, HPos.RIGHT); grid.add(amountOwed, 1, 3); amountOwed.setDisable(true); HBox firstRow = new HBox(10); firstRow.getChildren().addAll(btnCalc, btnSave, btnClear, btnExit, btnLoad); firstRow.setAlignment(Pos.CENTER); btnCalc.setTooltip(new Tooltip("Calculate amount owned for current record")); btnCalc.setOnAction(this); btnSave.setTooltip(new Tooltip("Saves and writes current record to disk")); btnSave.setOnAction(this); btnClear.setTooltip(new Tooltip("Clears all fields on GUI")); btnClear.setOnAction(this); btnExit.setTooltip(new Tooltip("Close the tool!")); btnExit.setOnAction(this); btnLoad.setTooltip(new Tooltip("Loads the data from the file")); btnLoad.setOnAction(this); HBox secondRow = new HBox(10); secondRow.getChildren().addAll(btnPrev, btnNext); secondRow.setAlignment(Pos.CENTER); btnPrev.setOnAction(this); btnNext.setOnAction(this); layout = new VBox(5); layout.getChildren().addAll(grid, firstRow, secondRow); scene = new Scene(layout, 500, 250); stage.setScene(scene); stage.show(); } public void handle(ActionEvent ae) { Button btn = (Button) ae.getSource(); if (btn.equals(btnCalc)) { calculateCurrentData(); } else if (btn.equals(btnSave)) { saveCurrentDataInList(); writeDataToFile(); } else if (btn.equals(btnClear)) { itemName.setText(null); number.setText(null); cost.setText(null); amountOwed.setText(null); } else if (btn.equals(btnExit)) { System.exit(0); } else if (btn.equals(btnLoad)) { int count = load(); if (count == -1) { Alert alert = new Alert(AlertType.ERROR, "Unable to read file", ButtonType.OK); alert.showAndWait(); } else { Alert alert = new Alert(AlertType.INFORMATION, "File Read \n" + count + " records read.", ButtonType.OK); alert.showAndWait(); } } else if (btn.equals(btnPrev)) { if (currentRecordIndex == 0) { Alert alert = new Alert(AlertType.ERROR, "No Previous record present", ButtonType.OK); alert.showAndWait(); } else { loadRecordIndex(--currentRecordIndex); } } else if (btn.equals(btnNext)) { if (currentRecordIndex == records.size() - 1) { Alert alert = new Alert(AlertType.ERROR, "No next record present", ButtonType.OK); alert.showAndWait(); } else { loadRecordIndex(++currentRecordIndex); } } } }
Hi. please find the answer above.. In case of any doubts, please
ask in comments. If the answer helps you, please upvote.
Thanks!
You may adjust the code as you want. Thank you! CODING HERE: import javafx.application.Application; import javafx.event.*;...
Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start with the bolded comment section in the code below. Create a class that will take string input and process it as a multidimensional array You will modify the program to use a multi-dimensional array to check the input text. SudokuCheckApplication.java import javafx.application.*; import javafx.event.*; import javafx.geometry.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public class SudokuCheckApplication extends Application { public void start(Stage primaryStage)...
(5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.HBox; import javafx.stage.Stage; public class Test extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { Button btOK = new Button("OK"); Button btCancel = new Button("Cancel"); EventHandler<ActionEvent> handler = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) { System.out.println("The OK button is clicked"); } }; btOK.setOnAction(handler); btCancel.setOnAction(handler); HBox pane = new HBox(5); pane.getChildren().addAll(btOK, btCancel); Scene...
Examine the following code and complete missing parts: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class NtoThePowerOfN extends Application{ @Override public void start(Stage primaryStage) throws Exception { TextField inputField; TextField outputField; VBox base = new VBox(10); base.setPadding(new Insets(10)); base.setAlignment(Pos.CENTER); // // A: input components - label and text field // // // B: button - to compute the value // // //...
use this code of converting Km to miles , to create Temperature converter by using java FX import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.geometry.Pos; import javafx.geometry.Insets; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Button; import javafx.event.EventHandler; import javafx.event.ActionEvent; /** * Kilometer Converter application */ public class KiloConverter extends Application { // Fields private TextField kiloTextField; private Label resultLabel; public static void main(String[] args) { // Launch the application. launch(args); } @Override public void start(Stage primaryStage) { //...
/ Finish the code to make it work import static javafx.application.Application.launch; import java.io.File; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.ChoiceBox; import javafx.scene.control.Label; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.media.AudioClip; import javafx.stage.Stage; public class JukeBox extends Application { private ChoiceBox<String> choice; private AudioClip[] tunes; private AudioClip current; private Button playButton, stopButton; //----------------------- // presents an interface that allows the user to select and play // a tune from a drop down box //----------------------- ...
Please Help, JavaFX assignment. This assignment will focus on the use anonymous inner class handlers to implement event handling. Assignment 12 Assignment 12 Submission Follow the directions below to submit Assignment 12: This assignment will be a modification of the Assignment 11 program. This program should use the controls and layouts from the previous assignment. No controls or layouts should be added or removed for this assignment. Add event handlers for the three buttons. The event handlers should be implemented...
For this question you will need to complete the methods to create a JavaFX GUI application that implements two String analysis algorithms. Each algorithm is activated when its associated button is pressed. They both take their input from the text typed by the user in a TextField and they both display their output via a Text component at the bottom of the GUI, which is initialized to “Choose a string methods as indicated in the partially completed class shown after...
Java: In this assignment, you will create an accumulator accumulator-calculator that displays a sad face “ :-( “ whenever the number displayed by the calculator is negative and a happy face “ :-) ” whenever the number displayed is positive. The calculator responds to the following commands: num + , num - , num * , num / and C ( Clear ). After initial run, if the user clicks 8 and then presses the “+” button for example, the...
Intro to Java - Assignment JAVA ASSIGNMENT 13 - Object Methods During Event Handling Assignment 13 Assignment 13 Preparation This assignment will focus on the use of object methods during event handling. Assignment 13 Assignment 13 Submission Follow the directions below to submit Assignment 13: This assignment will be a modification of the Assignment 12 program (see EncryptionApplication11.java below). Replace the use of String concatenation operations in the methods with StringBuilder or StringBuffer objects and their methods. EncryptTextMethods.java ====================== package...
Use Kilometer Converter application code to write Temperature Converter application to convert degrees Fahrenheit into degrees Celsius ((F - 32)*5/9). It needs to be JavaFX 1 import javafx.application. Application; 2 import javafx.stage. Stage; 3 import javafx.scene. Scene; 4 import javafx.scene.layout.HBox; 5 import javafx.scene.layout. VBox; 6 import javafx.geometry.Pos; 7 import javafx.geometry.Insets; 8 import javafx.scene.control.Label; 9 import javafx.scene.control. TextField; 10 import javafx.scene.control.Button; 11 import javafx.event. EventHandler; 12 import javafx.event. ActionEvent; 13 14 ** 15 * Kilometer Converter application 16 17 18 public...