Related questions
Chapter 18 Problem 38.PE Textbook: Introduction to Java programming and datastructure.
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);
}
}
Step by stepSolved in 2 steps
- Write the application JFrameDisableButton that instantiates a JFrame that contains a JButton. Modify the JFrameDisableButton program so that the JButton is not disabled until the user has clicked at least eight times. At that point, display a JLabel that indicates "That’s enough!". import java.awt.*; import javax.swing.*; import java.awt.event.*; public class JFrameDisableButton extends JFrame implements ActionListener { final int SIZE = 180; Container con = getContentPane(); JButton button = new JButton("Press Me"); int count = 0; final int MAX = 8; JLabel label = new JLabel("That's enough!"); public JFrameDisableButton() { // Write your code here } @Override public void actionPerformed(ActionEvent e) { // Write your code here } public static void main(String[] args) { JFrameDisableButton frame = new JFrameDisableButton(); } }arrow_forwardWrite JavaFX code with an intuitive GUI design that can generate a Fibonacci number sequence of a certain length (e.g., 30-50 numbers) via pressing a ‘Fib Gen’ button. The program should have at least two filtering functions on the generated number sequence.arrow_forwardImplement a date picker in javafx having following properties1) only numerical value can be typed in it2) / ( forward slash) appears in it when form prompt and user can write date in it3)only 8 digits can be typed in itarrow_forward
- Create a class RectangleExample in eclipse. Copy the following code into the class. RectangleExample.java package mypackage; import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.scene.shape.Rectangle; public class RectangleExample extends Application { Rectangle rect1, rect2; @Override public void start(Stage stage) { Group root = new Group(); //Drawing a Rectangle rect1 = new Rectangle(); //Setting the properties of the rectangle rect1.setX(20.0f); rect1.setY(20.0f); rect1.setWidth(300.0f); rect1.setHeight(10.0f); rect1.setFill(javafx.scene.paint.Color.RED); //Add to a Group object root.getChildren().add(rect1); //Drawing a Rectangle rect2 = new Rectangle(); //Setting the properties of the rectangle rect2.setX(20.0f); rect2.setY(40.0f); rect2.setWidth(200.0f); rect2.setHeight(10.0f); rect2.setFill(javafx.scene.paint.Color.GREEN); //Add to a Group object root.getChildren().add(rect2); //Creating a scene...arrow_forwardcan someone help me resize the picture in Java. This is my code: import java.awt.*;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO; class ImageDisplayGUI { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { createAndShowGUI(); }); } private static void createAndShowGUI() { JFrame frame = new JFrame("Bears"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setLayout(new BorderLayout()); // Load and display the JPG image try { BufferedImage image = ImageIO.read(new File("two bears.png")); // Replace with your image path ImageIcon icon = new ImageIcon(image); JLabel imageLabel = new JLabel(icon); frame.add(imageLabel, BorderLayout.CENTER); } catch (IOException e) { // Handle image loading error...arrow_forwardHow to create an AnimationGUI in java?arrow_forward
- How could I resize an image on Java. I'm using JGRASParrow_forwardQuestion 11 A constructor can be used to initialize all fields within a class. O True O Falsearrow_forwardJava Program ASAP I want only one program. Please pay attention to the screenshot for test case 2 and 3 and please make sure you match the result. Modify this program so it passes the test cases in Hypergrade becauses it says 5 out of 7 passed. import java.io.BufferedReader;import java.io.FileReader;import java.io.IOException;import java.util.ArrayList;import java.util.Arrays;import java.util.InputMismatchException;import java.util.Scanner;public class FileSorting { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (true) { System.out.println("Please enter the file name or type QUIT to exit:"); String fileName = scanner.nextLine(); if (fileName.equalsIgnoreCase("QUIT")) { break; } try { ArrayList<String> lines = readFile(fileName); if (lines.isEmpty()) { System.out.println("File " + fileName + " is...arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education