Complete a program to draw circles

Assignment Help JAVA Programming
Reference no: EM131587619

Loops

Complete a program to draw circles, arranged in a grid. For example, 6 circles arranged in a 2 by 3 grid would look like this:

How does it work?

The main method prompts the user for the grid parameters, the number of rows and number of columns. The remaining code in main, creates a graphic window and calls the draw method to actually complete the graphic.

The draw method should contain code that uses a loop (or loops) to draw each circle. A circle is draw using the drawOval method applied to the graphic object g. The drawOval method is defined as
drawOval(int x, int y, int width, int height)

Draws the outline of an oval. The result is a circle or ellipse that fits within the rectangle specified by the x, y, width, and height arguments.

x and y are the coordinates of the circle measured in pixels from the upper lefthand corner of the window. A suitable width and height is 40 pixels.

import java.awt.Graphics; import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JComponent;

public class Lab4C {

public static void draw(Graphics g, int a, int b) {
// Your code goes here
}

public static void main(String[] args) { int a, b;
// Your code to prompt the user for the grid size - a and b JFrame frame = new JFrame();
final int FRAME_WIDTH = 400; final int FRAME_HEIGHT = 400;

frame.setSize(FRAME_WIDTH, FRAME_HEIGHT); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JComponent component = new JComponent() {

public void paintComponent(Graphics graph) { draw(graph, a, b);
}
};

frame.add(component); frame.setVisible(true);
}
}

Reference no: EM131587619

Questions Cloud

Which element is not related with turnaround management : Which element is not related with turnaround management-? Certain changes in the external environments of business organizations demand.
Review case study of mr and mrs garcia : Mr. and Mrs. Garcia have a total of $100,000 to be invested in stocks, bonds, and a money market account. The stocks have a rate of return of9%/year.
Technology and devices impact the pillars of triple aim : In reference to ACOs. How can the use of technology and devices impact the three pillars of the Triple Aim methodology
Construct a mind map for gastritis : Explain how the factor you selected might impact the pathophysiology of GERD, PUD, and gastritis.
Complete a program to draw circles : Complete a program to draw circles, arranged in a grid. For example, 6 circles arranged in a 2 by 3 grid would look like this - Draws the outline of an oval
What must you include in this cost-benefit analysis why : What must you include in this cost/benefit analysis? Why? Discuss from a patient's point of view, how this change might benefit you in terms of cost.
Analyze or reflect on the readings : analyze or reflect on the readings, such as why the readings matter, how they fit in, what things you took away, etc.
Determine the pivot element : Consider the following linear program:min -3x1 - 2x2 - x3 s.t. x1 + 2x2 + 3x3 = 4 2x1 + 2x2 + x3 = 5 2x1 + x2 = 4 xj = 0 ?
Create a job description from the job analysis : Create a job description from the job analysis. Compare two job positions from the episode and perform a job analysis of each position.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd