Chapter 18 Problem 38.PE  Textbook: Introduction to Java programming and datastructure.  11th Edition Y. Daniel Liang Publisher: PEARSON ISBN: 9780134670942 This code is taken from your website does not work.  package e38; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.stage.Stage; import javafx.geometry.Pos; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.control.Textfield; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.shape.Line; import javafx.stage.Stage; public class E38 extends Application {          @Override     public void start(Stage primaryStage) {                 // Create a pane         TreePane tp = new TreePane();                  // Create a textfield         TextField tfOrder = new TextField();                 // Set the Depth        tfOrder.setOnAction(e->tp.set_Depth(Integer.parseInt(tfOrder.getText())));                // Set the value of the property        tfOrder.setPrefColumnCount(4);                // Set the alignment        tfOrder.setAlignment(Pos.BOTTOM_RIGHT);               // Create ahbox pane       HBox hBox = new HBox(10);              // Add the label and textfield object       hBox.getChildren().addAll(new Label("Enter an order"), tfOrder);             // Set the alignment      hBox.setAlignment(Pos.CENTER);            // Create a border pane      BorderPane borderPane = new BorderPane();           // Set the pane to center location     borderPane.setCenter(tp);          // Set the pane at the bottom     borderPane.setBottom(hBox);          // Create a scene a place it in the stage     Scene scene = new Scene(borderPane,200,210);          // Set the title     primaryStage.setTitle("Exercise18_38");          // Set the scene on the stage     primaryStage.setScene(scene);          // Display the stage     primaryStage.show();          // Set the width     scene.widthProperty().addListener(ov->tp.paint());          // Set the height     scene.heightProperty().addListener(ov->tp.paint());     }     // Pane for displaying Tree     static class TreePane extends Pane     {     // Declare required variables         private int treedepth = 0;     private double angle_Factor =Math.PI/5;     private double size_Factor =0.58;          // Function to set depth of the tree     public void set_Depth(int treedepth)     {     // Seth the depth     this.treedepth = treedepth;     // Call the function     paint();     }     // Function definition to paint     public void paint()        {     // Clear     getChildren().clear();     // Paint the branch     paint_Branch(treedepth,getWidth()/2,getHeight()-10,getHeight()/3, Math.PI/2);     }           // Function definition to paint the branch     public void paint_Branch(int treedepth, double x1, double y1,double length, double angle)              {              // Check if the tree depth is greater than 0         if(treedepth>=0)         {                  // Calculate the values            double x2 = x1 + Math.cos(angle)*length;     double y2 = y1 + Math.sin(angle)*length;          // Draw the line and add it to the pane     getChildren().add(new Line(x1,y1,x2,y2));          // Draw the left branch     paint_Branch(treedepth-1, x2,y2,length*size_Factor, angle+angle_Factor);         // Draw the right branch     paint_Branch(treedepth-1, x2,y2,length*size_Factor, angle-angle_Factor);         }       }        }          public static void main(String[]args)     {              launch(args);     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Chapter 18 Problem 38.PE  Textbook: Introduction to Java programming and datastructure. 

11th Edition
Y. Daniel Liang
Publisher: PEARSON
ISBN: 9780134670942

This code is taken from your website does not work. 

package e38;

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;

import javafx.stage.Stage;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.control.Textfield;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Line;
import javafx.stage.Stage;

public class E38 extends Application {
    
    @Override
    public void start(Stage primaryStage) {
       
        // Create a pane
        TreePane tp = new TreePane();
        
        // Create a textfield
        TextField tfOrder = new TextField();
        
       // Set the Depth
       tfOrder.setOnAction(e->tp.set_Depth(Integer.parseInt(tfOrder.getText())));
       
       // Set the value of the property
       tfOrder.setPrefColumnCount(4);
       
       // Set the alignment
       tfOrder.setAlignment(Pos.BOTTOM_RIGHT);
       
      // Create ahbox pane
      HBox hBox = new HBox(10);
      
      // Add the label and textfield object
      hBox.getChildren().addAll(new Label("Enter an order"), tfOrder);
      
     // Set the alignment
     hBox.setAlignment(Pos.CENTER);
     
     // Create a border pane
     BorderPane borderPane = new BorderPane();
     
    // Set the pane to center location
    borderPane.setCenter(tp);
    
    // Set the pane at the bottom
    borderPane.setBottom(hBox);
    
    // Create a scene a place it in the stage
    Scene scene = new Scene(borderPane,200,210);
    
    // Set the title
    primaryStage.setTitle("Exercise18_38");
    
    // Set the scene on the stage
    primaryStage.setScene(scene);
    
    // Display the stage
    primaryStage.show();
    
    // Set the width
    scene.widthProperty().addListener(ov->tp.paint());
    
    // Set the height
    scene.heightProperty().addListener(ov->tp.paint());
    }
    // Pane for displaying Tree
    static class TreePane extends Pane
    {
    // Declare required variables    
    private int treedepth = 0;
    private double angle_Factor =Math.PI/5;
    private double size_Factor =0.58;
    
    // Function to set depth of the tree
    public void set_Depth(int treedepth)
    {
    // Seth the depth
    this.treedepth = treedepth;

    // Call the function
    paint();
    }

    // Function definition to paint
    public void paint()   
    {
    // Clear
    getChildren().clear();

    // Paint the branch
    paint_Branch(treedepth,getWidth()/2,getHeight()-10,getHeight()/3, Math.PI/2);
    } 
    
    // Function definition to paint the branch
    public void paint_Branch(int treedepth, double x1, double y1,double length, double angle)
        
    {
        
    // Check if the tree depth is greater than 0
        if(treedepth>=0)
        {
            
    // Calculate the values       
    double x2 = x1 + Math.cos(angle)*length;
    double y2 = y1 + Math.sin(angle)*length;
    
    // Draw the line and add it to the pane
    getChildren().add(new Line(x1,y1,x2,y2));
    
    // Draw the left branch
    paint_Branch(treedepth-1, x2,y2,length*size_Factor, angle+angle_Factor);
   
    // Draw the right branch
    paint_Branch(treedepth-1, x2,y2,length*size_Factor, angle-angle_Factor);
        }
      }   
    }
    
    public static void main(String[]args)
    {
        
    launch(args);
    }
}    
         

 

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Developing computer interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education