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)
- Write code so that you make another image below the image currently in the code so that they are next to each other but not touching each other. And Translate - A function that moves the graphic according to the given input . Grow - a function that increases the size of the graphic according to the given input public class BasicGraphicViewer{ public static void main (String[] args) { Rectangle r1 = new Rectangle(100,10,20,30); r1.draw(); Picture p1 = new Picture(); p1.load(“someimageurl”); // you can put any image link here. p1.draw(); } }arrow_forwardHelp with JavaFX barchart: I have a program that allows a user to deposit and withdraw money while updating their balance based on the month the transaction occured, but I am having trouble with the programs class and am trying to make a bar chart that will have the total balance of that month, so as an example in May the bar would show $70, while the bar for June would show $100, even if the deposits were $20 and $50, then $30, $40 and $30.arrow_forwardIn javacode: Use ArrayList to create an array called myAL of type integer. --Fill the array with the values 5, 10, 15, 22, 33. --Print the array (use enhanced for loop). --Insert the value 25 between 10 and 15 and print the array.--Remove 2 elements on index 1 and 3 and then print the array.--Print if the array contains the value 123 or not.--Print the index of the element 22.--Print the size of the array.arrow_forward
- I am just started to learn Java. My professor has gone over all our projects so I feel comfortable with the honor code to ask for help in designing this. Thank you. In Java, Design a program that generates a 7-digit lottery number. The program should have an integer array with 7 elements. Write a loop that steps through the array, randomly generating a number in the range of 0 through 9 for each element of the array. Write another loop that displays the contents of the array.arrow_forwardWrite a program that creates and initializes an array with the following four values: 2.3, 4.5, 8.0, and 2.1. Use a for loop to print the array elements and then use a for loop to print the array elements in reverse order.arrow_forwardHELP IN JAVA CODE PLEASE Create code using DrawingPanel to generate values for a magic square based on a random magicValue and execute as an example is shown below Make sure the old magic square is erased when the new magic square is executed.arrow_forward
- Lottery.java, to generate a lottery of a two-digitnumber. The two digits in the number are distinct. (Hint: Generate the first digit.Use a loop to continuously generate the second digit until it is different from thefirst digit.)arrow_forwardJAVAWrite a program that will add and remove the following name and phone number list. (List on image below) Once lists of names and phone numbers are added to the program, the program will ask a user whether there is an item to be removed or not. If it is, it will be removed. Otherwise, the program is terminated. The program will delete items continuously if requested. The result of the program looks like following:arrow_forwardCreate a class NestedForPatternB. Use nested for-loops that display the following pattern:arrow_forward
- I want this work be done in C# Visual studio. Given the following: private void btnRun_Click(object sender, EventArgs e){//Your code goes here } Code the statement(s) that will create a integer array of 5 elements and initialize the array with the following values in one line of code 10, 15, 20, 25, and 30. Then using a for loop alter the values in each element of the array by adding 5 to it. So after the for loop runs the values of the array should be 15, 20, 25, 30, and 35.arrow_forwardUsing method verifies whether a given square is a magic square or not Parameter squareData is a symmetrical 2-dimensional array of integers Returns true if the square is magic if all rows or columns, or two main diagonals add up to same value Return false otherwise Design source-code file (MagicSquare.java) and image files for two Magic Squares for magicValue = 74 and magicValue = 99.arrow_forwardwrite a program to create a one dimensional array. get the number of element from the user and the array element from the user using dialog box and display the array element in the reverse order. ( using java netbean)arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education