Java: An Introduction to Problem Solving and Programming (8th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
bartleby

Concept explainers

Expert Solution & Answer
Book Icon
Chapter 4.3, Problem 26STQ

Explanation of Solution

Loop that is used to draw identical circles:

//Loop from 0 through number of circles

for (int i = 1; i <= 6; i++)

{

    //Set the color to fill

    gc.setFill(Color.BLUE);

    //Draw oval

    gc.fillOval(x, y, DIAMETER, DIAMETER);

    //Set the color to fill

    gc.setFill(Color.BLACK);

    //Draw the stroke

    gc.strokeOval(x, y, DIAMETER, DIAMETER);

    //Update the value of x

    x += DIAMETER + GAP;

}

Explanation:

The above loop is used to create six identical circles. For each iteration,

  • The color “BLUE” is set using “setFill ()” method.
  • An oval is drawn using “fillOval ()” method.
  • The color “BLACK” is set using “setFill ()” method.
  • A stroke is drawn using “strokeOval ()” method.
  • The value of “x” is updated.

Complete program:

The below program is used to create six identical circles using “JavaFX”.

//Import required packages

import javafx.application.Application;

import javafx.scene.canvas.Canvas;

import javafx.scene.Scene;

import javafx.scene.Group;

import javafx.stage.Stage;

import javafx.scene.canvas.GraphicsContext;

import javafx.scene.paint.Color;

//Define the main class that extends application class

public class SelfTest26 extends Application

{

    //Declare required constant variables

    //Set the gap

    public static final int GAP = 50;

    //Set the value of diameter

    public static final int DIAMETER = 50;

    //Set the value of X_CENTER

    public static final int X_CENTER = 100;

    //Set the value of U_CENTER

    public static final int Y_CENTER = 100;

    //Define the main method

    public static void main(String[] args)

    {

        //Launch the application

        launch(args);

    }

    //Override the start method

    @Override

public void start(Stage primaryStage) throws Exception

    {

        //Create a group

        Group g = new Group();

        //Create a scene

        Scene scene = new Scene(g);

        //Create a canvas

        Canvas c = new Canvas(800, 600);

        //Create an object for graphics context

        GraphicsContext gc = c...

Blurred answer
Students have asked these similar questions
Write a program that enables the user to drag thevertices of a triangle and displays the angles dynamically as the triangle shapechanges, as shown in Figure .
Write a JavaFX application that draws a circle using a rubberbanding technique. The circle size is determined by a mouse drag.Use the initial mouse press location as the fixed center point ofthe circle. Compute the distance between the current location ofthe mouse pointer and the center point to determine the currentradius of the circle.
Write a JavaFX program that displays a 10-by-10 binary matrix, where each element in the matrix is either 0 or 1, that are randomly generated. Display each number in a text field. Add an event handler so that clicking on any element in the matrix should change the binary number (0 will be changed to 1 and 1 to 0

Chapter 4 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Ch. 4.1 - Prob. 11STQCh. 4.1 - Write a for statement that displays the even...Ch. 4.1 - Prob. 13STQCh. 4.2 - Write a Java loop that will display the phrase One...Ch. 4.2 - Write a Java loop that will set the variable...Ch. 4.2 - Write a Java loop that will read a list of numbers...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - What output is produced by the following code? for...Ch. 4.2 - Revise the loop shown in Listing 4.6 to use a...Ch. 4.2 - What is the bug in the code in the section Tracing...Ch. 4.2 - Add some suitable output statements to the...Ch. 4.2 - What is the bug in the code in the previous...Ch. 4.2 - Prob. 24STQCh. 4.2 - Suppose that you did not have assertion checking...Ch. 4.3 - Prob. 26STQCh. 4 - Write a fragment of code that will read words from...Ch. 4 - Develop an algorithm for computing the...Ch. 4 - Develop an algorithm for a simple game of guessing...Ch. 4 - Write a fragment of code that will compute the sum...Ch. 4 - Convert the following code so that it uses nested...Ch. 4 - Write a for statement to compute the sum 1 + 22 +...Ch. 4 - (Optional) Repeat the previous question, but use...Ch. 4 - Write a loop that will count the number of blank...Ch. 4 - Write a loop that will create a new string that is...Ch. 4 - Write a program that will compute statistics for...Ch. 4 - Suppose we attend a party. To be sociable, we will...Ch. 4 - Define an enumeration for each of the months in...Ch. 4 - Write a fragment of code that computes the final...Ch. 4 - Suppose that you work for a beverage company. The...Ch. 4 - Suppose that we want to compute the geometric mean...Ch. 4 - Prob. 16ECh. 4 - Create an applet that draws a pattern of circles...Ch. 4 - Prob. 18ECh. 4 - What does the following fragment of code display?...Ch. 4 - Repeat Practice Program 4 of Chapter 3, but use a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Repeat Practice Program 5 of Chapter 3, but use a...Ch. 4 - Write a program to read a list of nonnegative...Ch. 4 - Write a program to read a list of exam scores...Ch. 4 - Combine the programs from Programming Projects 5...Ch. 4 - Write a program that simulates the Magic 8 Ball...Ch. 4 - Whats for dinner? Let the computer decide. Write a...Ch. 4 - Write a program that implements your algorithm...Ch. 4 - Prob. 2PPCh. 4 - Write a program that reads a bank account balance...Ch. 4 - Modify Programming Project 5 from Chapter 2 to...Ch. 4 - Write a program that asks the user to enter the...Ch. 4 - Write a program that simulates a bouncing ball by...Ch. 4 - You have three identical prizes to give away and a...Ch. 4 - Prob. 9PPCh. 4 - Holy digits Batman! The Riddler is planning his...Ch. 4 - Your country is at war and your enemies are using...Ch. 4 - Prob. 12PPCh. 4 - Prob. 13PPCh. 4 - Prob. 14PPCh. 4 - (Challenge) Repeat the previous project, but...Ch. 4 - Write a JavaFx application that displays a series...
Knowledge Booster
Background pattern image
Computer Science
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
  • Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781305480537
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT