Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description Write a program that reads a list of graphics primitives from a text file and draws them in a window. This assignment creates a

Description

Write a program that reads a list of graphics primitives from a text file and draws them in a window. This assignment creates a set of Java classes in a very primitive hierarchy to model the various graphics primitives: text, squares, rectangles, triangles, and circles, and ovals. Each primitive has a different set of attributes, for example text has font name, style, and size, and a rectangle has color, width, and height, etc. When your program is complete, you will be able to see the contents of the text file rendered inside of a window. In the next assignment you will substitute a more complex hierarchy of classes that takes advantage of inheritance to reduce duplication and force consistent behavior among graphics primitives. You will also another primitives, polygon.

Create a project called P2.

Download and import P2-starter.jar - https://www.cs.colostate.edu/~cs165/.Spring18/assignments/P2/archive/P2-starter.jar

Each test file has primitives for one type except for the simplePrimitives file which has 37 primitives for all different types.

Data Description

Refer to the simplePrimitives file to see the format of the text files.

The color attributes in the file are numbers in the format RRGGBB, specified in hexadecimal, where each channel has eight bits.

For example FF0000 is red, 00FF00 is green, and 0000FF is blue, all maximum intensity.

The font name can either be "Times Roman" or "Arial".

All coordinates are integer values representing pixels on the drawing surface.

Coordinates

Java AWT(the underlying graphics library used in this project) uses a screen coordinate system where (0,0) corresponds to the pixel in the top left corner of the window. X increases towards the right and Y increases towards the bottom.

For specifications on the precise drawing location of the methods provided in UserIterface, consult the Java AWT Graphics class Javadoc.

Add New Classes

Create the following classes:

Square

Rectangle

Triangle

Circle

Oval

Text

Each shape should inherit from the Primitive class. For example:

public Square extends Primitive { 

Implement the Shape Classes

Each shape requires certain fields and methods. This includes location, size, color, etc. You will need to figure out what each class should include through analyzing the following sources:

The code in the DrawProgram and UserInterface classes.

The code in the DrawProgram class is not complete, this will be the next part of your assignment. However, you should able to deduce what each shape needs from the code that is already provided.

The UML diagram below

The javadoc

Complete the code in the DrawProgram class

The main method calls load, passing args[0] as the name of the text file containing graphics primitives, then it calls draw to draw the primitives. Try running the program with the files corresponding to the Text, Square, or Rectangle classes.

Once you have successfully tested these classes, complete the code for the following methods:

public ArrayList load(String filename); public void draw(ArrayList primitives); 

.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning ASP.NET 4.5 Databases

Authors: Sandeep Chanda, Damien Foggon

3rd Edition

1430243805, 978-1430243809

More Books

Students also viewed these Databases questions