Question
for cse 205, please help
Add code and complete a program to change the x position of rectangle with the slider by binding the rectables x and slider
public class Q23 extends Application Slider slider; Rectangle rect; public void start (Stage stage) { Scene scene1 = new Scen
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q23.java

package Test.Q36;
//importing required file and classes
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Slider;
import javafx.scene.layout.Pane;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;



public class Q23 extends Application {

//    slider object
    Slider slider;
//    rect object
    Rectangle rect;
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage stage) {

        // creating new scene object with createPane , width and height
        Scene scene = new Scene(createPane(),430,150);
//        setting scene to the stage
        stage.setScene(scene);
//        showing the stage
        stage.show();
    }

    public Pane createPane()
    {
//        creating new rect with x, y, width , height
        rect = new Rectangle(20,20,100,100);
//        creating new pane object
        Pane pane = new Pane(rect);

//        creating new slider with min, max value
        slider = new Slider(0,300,20);
//        adding slider to the pane
        pane.getChildren().add(slider);

//        listening to change property of slider then applying new value to rect.setX
        slider.valueProperty().addListener((observable, oldValue, newValue) -> {

//            setting rect.setX
            rect.setX(Double.parseDouble(Double.toString(newValue.intValue())));

        });
//        return pane
        return pane;
    }

}

Output

Х

Code Output

file Edit View Navigate Code Analyze Refactor Build Run Tools VCS Window Help WebDev - Q23.java WebDev src Test Q36 C023 023

file Edit View Navigate Code Analyze Refactor Build Run Tools VCS Window Help WebDev - Q23.java WebDev src Test Q36 C023 023

file Edit View Navigate Code Analyze Refactor Build Run Tools VCS Window Help WebDev - Q23.java WebDev src Test 036 C 023 023

Add a comment
Know the answer?
Add Answer to:
for cse 205, please help Add code and complete a program to change the x position...
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
  • A game clock that starts at zero and begins to count up in seconds. Add buttons...

    A game clock that starts at zero and begins to count up in seconds. Add buttons to pause and resume the clock. Given this initial code: import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.stage.Stage; import javafx.util.Duration; import javafx.scene.paint.Color; public class AnimationCounter2 extends Application{ @Override public void start(Stage stage) throws Exception{ // Create the label and align its contents. Label label = new Label("0"); label.setTextFill(Color.RED); label.setStyle("-fx-font-size: 4em;"); label.setAlignment(Pos.CENTER); EventHandler<ActionEvent> handler =...

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

  • JavaFX programming (Not Javascript) Using the code from BallPane.java and BounceBallControl.java create a "Pong for One"...

    JavaFX programming (Not Javascript) Using the code from BallPane.java and BounceBallControl.java create a "Pong for One" game - a rectangular paddle moves back and forth via mouse drag along the bottom of the pane; the bottom of the paddle should be about 1/2 the diameter of the ball off the bottom. If the ball connects with the paddle, then it bounces at a 90 degree angle back into the pane space. If the ball misses the paddle, then the score...

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

  • This is my code. I need the UML for this code My code: public class Main...

    This is my code. I need the UML for this code My code: public class Main extends FlightManager {    Stage window;    Scene scene;    Button button;    HBox layout = new HBox(20);    Label dateTxt, airlineTxt, originTxt, destTxt, clssTxt, scopeTxt, adultsTxt, childTxt;    @Override public void start(Stage stage) { // create the UI and show it here    window = stage; window.setTitle("Reservations 2020"); button = new Button("New Flight");    VBox group3 = new VBox(10); dateTxt = Text("", group3);...

  • Java Programming Assignment (JavaFX required). You will modify the SudokuCheckApplication program that is listed below. Start...

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

  • 15.3 (Move the ball) Write a program that moves the ball in a pane. You should...

    15.3 (Move the ball) Write a program that moves the ball in a pane. You should define a pane class for displaying the ball and provide the methods for moving the ball left, right, up, and down, as shown in Figure 15.24c. Check the boundary to prevent the ball from moving out of sight completely. import javafx.application.Application; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import javafx.scene.layout.Pane; import javafx.scene.shape.Circle; import javafx.stage.Stage; public class Driver extends Application...

  • Consider the blowing code snippet Question 4 2 pts 2 pts Canvas XC Question 3 2...

    Consider the blowing code snippet Question 4 2 pts 2 pts Canvas XC Question 3 2 pts Consider the following code snippet public class Hypp extends Application public void start (Stage stapelt Button button new lutton("Calculate"); Label label new Label("Total amount dut) > public class Handler rolesents EventHandler Action vest public void handle (Actiontrent event) label.Text("Hell) > 2 What is wrong with this code? label must be declared as an instance variable. button must be declared as an instance variable...

  • changes needed is at the end of the code //************************************************************************ // Snowman.java Author: Lewis/Loftus // //...

    changes needed is at the end of the code //************************************************************************ // Snowman.java Author: Lewis/Loftus // // Demonstrates the translation of a set of shapes. //************************************************************************ import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.scene.shape.*; public class Snowman extends Application { //-------------------------------------------------------------------- // Presents a snowman scene. //-------------------------------------------------------------------- public void start(Stage primaryStage) { Ellipse base = new Ellipse(80, 210, 80, 60); base.setFill(Color.WHITE);    Ellipse middle = new Ellipse(80, 130, 50, 40); middle.setFill(Color.WHITE);    Circle head = new Circle(80,...

  • You may adjust the code as you want. Thank you! CODING HERE: import javafx.application.Application; import javafx.event.*;...

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

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