Write a graphical application that draws a spiral

Assignment Help JAVA Programming
Reference no: EM13940528

Write a graphical application that draws a spiral, such as the following:

Your main class should be called SpiralViewer.
Complete the following class in your solution:
public class SpiralGenerator
{
// private implementation
. . .

/**
Creates a spiral generator.
@param initialSize the size of the first (shortest) segment
of the spiral, in pixels
@param start the starting point of the spiral
*/
public SpiralGenerator(double initialSize, Point2D.Double start) { . . . }

/**
Returns the next segment of the spiral.
@return the next segment
*/
public Line2D.Double nextSegment() { . . . }
}
Use the following class in your solution:
import javax.swing.JComponent;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.awt.geom.Line2D;

public class SpiralComponent extends JComponent
{
private int segments;

public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;
final int INITIAL_SIZE = 10;

int size = Math.min(getWidth(), getHeight());
SpiralGenerator gen = new SpiralGenerator(
INITIAL_SIZE,
new Point2D.Double(size / 2, size / 2));

while (true)
{
Line2D.Double segment = gen.nextSegment();
if (!segment.intersects(getBounds()))
return;
g2.draw(segment);
}
}
}
Use the following class as your tester class:
import java.awt.geom.Point2D;
import java.awt.geom.Line2D;

public class SpiralTester
{
public static void main(String[] args)
{
SpiralGenerator gen = new SpiralGenerator(10, new Point2D.Double(100, 100));
Line2D line = gen.nextSegment();
System.out.println(line.getX1());
System.out.println("Expected: 100");
System.out.println(line.getY1());
System.out.println("Expected: 100");
System.out.println(line.getX2());
System.out.println("Expected: 110");
System.out.println(line.getY2());
System.out.println("Expected: 100");
line = gen.nextSegment();
System.out.println(line.getX1());
System.out.println("Expected: 110");
System.out.println(line.getY1());
System.out.println("Expected: 100");
System.out.println(line.getX2());
System.out.println("Expected: 110");
System.out.println(line.getY2());
System.out.println("Expected: 90");
}
}

Reference no: EM13940528

Questions Cloud

Determine the tensile stress in the component : Determine, the tensile stress in the component when first loaded, the temperature at which the stress will be zero if the component is rigidly held at its extended length.
How the management systems approach to esh management : Describe how the management systems approach to ESH management results in continuous improvement
Organizational overview and external environment : Organizational overview and external environment: What does the organization do and what are the circumstances under which it operates?
Describe ethical frameworks for punishment: utilitarianism : Describe the three ethical frameworks for punishment: utilitarianism, deontology, and peacemaking. Which one do you think should serve as the ethical framework for punishment today? Why?
Write a graphical application that draws a spiral : Write a graphical application that draws a spiral, such as the following
Search a recent article online or business magazines : Search a recent article online or business magazines such as Forbes, Business Week, WSJ..etc. and identify OM concepts and issues that are discussed.  Please apply these to the topic of "What Do Managers Do?"
What is the sales mix of alpha-basic to alpha-deluxe : Alpha Company produces and sells two products: Alpha-Basic and Alpha-Deluxe. What is the sales mix of Alpha-Basic to Alpha-Deluxe? Compute the break-even quantity of each product.
Concepts of corrective actions and preventive actions : Compare and contrast the concepts of corrective actions and preventive actions as they related to the "check" and the "act" part of the cycle
Determine the magnitude and nature of the stress : Determine the magnitude and nature of the stress induced in the material (a) if the temperature falls to 25 °C, (b) if the temperature rises to 95°C.

Reviews

Write a Review

JAVA Programming Questions & Answers

  Implement a singly linear linked list

Prepare a C++ using visual studios program to implement a singly linear Linked List - You need to implement singly link list in C++.

  Returns the object with the largest measure

public static Measurable maximum(Measurable[] objects)that returns the object with the largest measure. Use that method to determine the country with the largest area from an array of

  Write a program which adds two matrices

Write a program which adds two matrices together and displays the sum - Two arrays will contain user input, and the third array will be used to contain the sum of the two arrays.

  Create a hang man type program

Create a hang man type program - create the full final picture image, and then rub out a piece and save it as a different filename, then rub out another part and save it as a different name.

  Maintain a constant media schedule

It is usually unnecessary or not feasible to maintain a constant media schedule all year. What are the two other alternatives and what key characteristics of these two alternatives would be taken into account?

  Enhance the test score applicaion

Enhance the Test Score applicaion so it uses a "while" or a "do-while" loop plus a for loop - Change the while statement to a do-while statement, andtest this change. Does this work any better than the while loop?

  Write a method called makerow

Write a method called makeRow that is passed two arguments: an int and a String. It returns a String containing n copies of s, concatenated in a row.

  What is printed out by the following code

What is printed out by the following code

  Write a java statement to have the object from manage

Write a Java statement to have the object from manage its display area by dividing it into 3 rows which have 4 columns each.

  This project mainly focuses on explaining your

this project focuses on demonstrating your understanding of java collections. before attempting this project be sure

  Produces a simple formatted report

For this lab you will write a Java program that produces a simple formatted report. The program will prompt the user to enter a file name. This file must contain information in a specific format (detailed below)

  Display random numbers to simulate rolling a die

1. Display random numbers to simulate rolling a die2. Create a java program that simulate a casino game. (rollin a die)

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