Concept explainers
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...
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
- javascripts write a loop prints all three digits number in decreasing order (999 , 998 ,997,..,101,100)arrow_forwardWrite a program that displays a checkerboardin which each white and black cell is a Rectangle with a fill color black orwhite, as shown in Figure .arrow_forwardWrite a Javafx application that draws 100 circle of random color and random size in random locations. Ensure that the entire circle appears in the visible area of the scene.arrow_forward
- java Use a loop to track the growth of the Utopian Tree. The tree grows exactly 1 cm for the first three years, and then afterwards it grows by 2 cm every year. Show the growth of the tree each year up to year 10. See the example flow below. Use the format: year x - growth x cm tree size: x cm where the 'x' values are different values of year, the growth amount, and the total tree size up to that yeararrow_forwardCan you change the code below to remove the repeated lines of code and use a loop to draw 4 sides of the square? please show screenshots of your work. import java.util.*;import java.awt.*; public class TurtleDrawSquare{ public static void main(String[] args) { World world = new World(300,300); Turtle yertle = new Turtle(world); // Change the following code to use a for loop to draw the square yertle.forward(); yertle.turn(90); yertle.forward(); yertle.turn(90); yertle.forward(); yertle.turn(90); yertle.forward(); yertle.turn(90); world.show(true); }}arrow_forwardWrite a while loop to print the product of the odd integers between 0 and 10, inclusive.Javascriptarrow_forward
- In JavaFX I need to create a standard calculator with two input fields and one output field that can only add, subtract, multiply, and divide. This needs to be completed in the simplist way. No overcomplication or unnecessary additions.arrow_forwardWrite a code use JavaFX to build the login formarrow_forwardin java, make a code that returns the values that are asked within the imagearrow_forward
- Write a Javafx application that draws 10 circles of random radius in random locations. Leave all circles unfilled exceptfor the largest circle, which should be filled with a translucent red (30% opaque). If multiple circles have the same largest size, fill any one of them.arrow_forwardJava Program ASAP 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 empty."); } else {…arrow_forwardWrite JavaScript program using While loop for designing this. Do it separately for each of them. For designing a yellow star the value is- document.write("🌟"), for smile sticker the value is- 😋, for heart sticker the value is �rrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT