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 Plus Mylab Programming With Pearson Etext -- Access Card Package (8th Edition)
- After our initial deployment for our ML home based security system, the first steps we took to contribute further to the project, we conducted load testing, tested and optimize for low latency, and automated user onboarding. What should be next?arrow_forwardWhy investing in skills and technology is a critical factor in the financial management aspect of system projects.arrow_forwardwhy investing in skills and technology is a critical factor in the financial management aspect of systems projects.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr