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

  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