Question

nToThePowerOfN calculator Enter a positive number (n): Compute n to the power n 3 to the power of 3 27.0

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
        //

        //
        
        //  C: output components - label and textfield
        //      Make sure the output field cannot be changed by the user

        //


        //  D: event handler for button goes here - try and use a lambda expression
        //


        Scene sc = new Scene(base);
        primaryStage.setScene(sc);
        primaryStage.setTitle("Square root calculator");
        primaryStage.show();
    }

public static void main(String[] args) {

launch(args);

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
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.GridPane;
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 {

       final TextField inputField = new TextField();
       final TextField outputField = new TextField();
       final Label outputLabel = new Label();
      
       VBox base = new VBox(10);
      
       base.setPadding(new Insets(10));
       base.setAlignment(Pos.CENTER);

       HBox firstRow = new HBox();
       firstRow.getChildren().add(new Label("Enter a positive number(n):\t"));
       firstRow.getChildren().add(inputField);
       firstRow.setAlignment(Pos.CENTER);
      
       base.getChildren().add(firstRow);

       Button computeButton = new Button("Compute n to the power of n");
       base.getChildren().add(computeButton);

       computeButton.setOnAction(new EventHandler<ActionEvent>() {
           @Override
           public void handle(ActionEvent event) {
               try {
                   int n = Integer.parseInt(inputField.getText());
                   outputLabel.setText(n + " to the power of " + n+"\t");
                   outputField.setText(String.valueOf(n * n));
               } catch (NumberFormatException e) {
               }
           }
       });

       HBox secondRow = new HBox();
       secondRow.getChildren().add(outputLabel);
       outputField.setEditable(false);
       secondRow.getChildren().add(outputField);
       secondRow.setAlignment(Pos.CENTER);
      
       base.getChildren().add(secondRow);

       Scene sc = new Scene(base);
       primaryStage.setScene(sc);
       primaryStage.setTitle("Square root calculator");
       primaryStage.show();
   }

   public static void main(String[] args) {
       launch(args);
   }
}

Square root calculator Enter a positive number(n):6 Compute n to the power of rn 6 to the power of 6 36

Add a comment
Know the answer?
Add Answer to:
Examine the following code and complete missing parts: import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Insets;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use this code of converting Km to miles , to create Temperature converter by using java...

    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...

    / 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 //-----------------------   ...

  • (5 points) Analyze the following codes. b) import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import...

    (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...

  • Can someone please comment this on what the javafx do and how they are implemented? import...

    Can someone please comment this on what the javafx do and how they are implemented? import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.layout.GridPane; import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import javafx.scene.paint.Paint; import javafx.scene.text.Font; import javafx.scene.text.FontWeight; import javafx.scene.text.Text; import javafx.stage.Stage; public class TextPanel extends Application { GridPane grid = null; Text scenetitle = null; Label tDrawLabel = null; Label bsc345Label = null; HBox THBox = null; VBox mVBox = new VBox(2); Stage primaryStage = null; @Override public void start(Stage...

  • Use Kilometer Converter application code to write Temperature Converter application to convert degrees Fahrenheit into degrees...

    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...

  • # Java import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class Test extends Application {...

    # Java import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; public class Test extends Application {   @Override // Override the start method in the Application class   public void start(Stage primaryStage) {     // Create a button and place it in the scene     Button btOK = new Button("OK");     btOK.setOnAction(e -> System.out.println("OK 1"));     btOK.setOnAction(e -> System.out.println("OK 2"));     Scene scene = new Scene(btOK, 200, 250);     primaryStage.setTitle("MyJavaFX"); // Set the stage title     primaryStage.setScene(scene); // Place the scene in the stage     primaryStage.show(); // Display the stage...

  • Java: In this assignment, you will create an accumulator accumulator-calculator that displays a sad face “...

    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...

  • The JavaFX framework provides more than one way to handle events. For event handlers, we could...

    The JavaFX framework provides more than one way to handle events. For event handlers, we could use inner classes, anonymous inner classes, or the new Java 8 feature of lambda expressions. In this discussion, you will explore these different ways of writing event handles in JavaFX. To prepare for this discussion, you must unzip the attached NetBeans project zip file (U4D1_HandleEvents.zip) and load it into your NetBeans IDE. The project uses an inner class to handle the click event on...

  • please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart...

    please help me debug this Create a Future Value Calculator that displays error messages in labels.GUISpecificationsStart with the JavaFX version of the Future Value application presented in chapter 17. Create error message labels for each text field that accepts user input. Use the Validation class from chapter 17 to validate user input.Format the application so that the controls don’t change position when error messages are displayed. package murach.business; public class Calculation {        public static final int MONTHS_IN_YEAR =...

  • JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. T...

    JavaFX! Just need to fill several lanes of code please!!! CSE205 OOP and Data Structure Quiz #15 Last Name (print) First Name (print) Write a JavaFX GUI application program that simulates a timer. The timer should show "count: the beginning and increase the number by 1 in every one second, and so on. o" at .3 A Timer - × A Timer Count: 0 Count: 1 (B) After 1 second, the GUI Window (A) Initial GUI Window According to the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT