Write a java class that reads through a text file

Assignment Help JAVA Programming
Reference no: EM13751234

You will write a Java class that reads through a text file of drawing commands and draws the appropriate shapes onto JFrames. The following commands must be supported

FRAME width height                          // sets up a new frame with given width and height (both integers)

COLOR red green blue                        // sets the current "pen color" to the color with the given rgb components.

RECTANGE x y width height             // draws a rectangle with upper left corner at x,y and given width and height (all // given in integers)

CIRCLE x y radius                                // draws a circle centered at x,y with given radius (as doubles)

ELLIPSE x y xradius yradius               // draws an ellipse centered at x,y with semi-radii xradius and yradius (Note:   

// these parameters are slightly different than that in Ellipse2D.Double's 

// constructor.

LINE x1 y1 x2 y2                                   // draws a line from x1,y1 to x2,y2 (as doubles)

A sample command paint_instructions.txt file is as follows:

FRAME 200 100                                   // open a frame, note: parser must ignore any comments

COLOR 255 0 0                                     // set color to red

RECTANGLE 20 30 40 20                    // draw a red rectangle

COLOR 128 128 128                             // set color to gray

CIRCLE 100 50 25                                 // draw a gray circle

FRAME 100 100                                   // open a second frame

COLOR 0 0 255                                     // set color to blue

ELLIPSE 50 50 30 20                             // draw a blue ellipse

COLOR 0 255 0                                     // set color to green

LINE 10 20 90 80                                   // draw a green line

For simplicity, there should be only one command per line which may end in a comment as shown above.

Your program should read commands and set up appropriate GUI structures in the Java Swing environment. If a command has a syntax error, then your program should detect this and print out a message to the output console indicating the line number from your command file that had the error. Hint: there is an easy way to do this by catching runtime exceptions that are thrown in a try block.

Reference no: EM13751234

Questions Cloud

Explain what using a cloud vendor : Many small businesses operate with local servers running in broom closets or the like. Explain what using a cloud vendor that is compliant with these standards and statements means to such companies
While in prison hitler wrote the first volume of mein kampf : While in prison, Hitler wrote the first volume of Mein Kampf. Hitler's goal was to create a vast empire, based on racial nationalism, ruled by a master race.
Primary types of retirement plans : The two primary types of retirement plans employed are defined benefit plans and defined contribution plans. Please explain the structure of each, how they are funded, and how they pay benefits to retirees.
Economic profit level to continue in subsequent years : What are the profit-maximizing price and output levels? Explain them and calculate algebraically for equilibrium P (price) and Q (output). Then, plot the MC (marginal cost), D (demand), and MR (marginal revenue) curves graphically and illustrate the ..
Write a java class that reads through a text file : You will write a Java class that reads through a text file of drawing commands and draws the appropriate shapes onto JFrames
Importance of internal controls in general : As the new accounting manager for a water district, you have been asked to evaluate the internal controls utilized by your new employer. You find that the following controls are in place. Please define and explain the importance of internal cont..
True about a partnership : 1. The ability of one partner to enter into a contract binding all other partners is termed:
Discusses the role of the leaders in this case study : Case Study: A System Approach, Review the case study in the article, Texas Health Harris Methodist-Cleburne: A System Approach to Surgical Improvement. Discusses the role of the leaders in this case study
Cost of capital for analyzing capital expenditures : Would you recommend that ExxonMobil use a single company- wide cost of capital for analyzing capital expenditures in all its business units? Why or why not?

Reviews

Write a Review

JAVA Programming Questions & Answers

  Write a recursive function that finds and returns the sum

Write a recursive function that finds and returns the sum of the elements of an int array. Also, write a program to test your function.

  Java''s type int has limit onhow large aninteger it can store

Java's type int has a limit on how large an integer it can store. This limit can be circumvented by representing an integer as an array of digits. Write an interactive program that adds two integers of up to 50 digits each.

  Write a program to play a game of craps

Write a program to play a game of "craps," a dice game popular in casinos. Here are the rules - Use functions appropriately. The program should allow the user to play another round.

  Simple single-server queue has one line of waiting

simple single-server queue has one line of waiting customers and one server who wait on customers. suppose that

  Write a number guessing game in java

ou have to write a number guessing game in Java. The program should have three difficulty levels, each one having a different maximum number. After the user selects a difficulty,

  Organization structure change over time

How and why did the organization structure change over time, and in what ways were some of these changes responsible for some of their recent problems?

  What does the variable x contain

What does the variable x contain at the end of each of these computations? If the code is not legal in Java, say so.

  Write an application that extends jframe

Write an application that extends JFrame and that displays a phrase in every font size from 6 through 20.

  Write a bag class with a generic type

Write a Bag class with a generic type. Write a class such as item that has a name and price. Add objects of item to the bag and find the average and the total of the price of all items in the bag.

  In this game we have a number of players interacting in a

in this game we have a number of players interacting in a simple way. the game takes place on a virtual

  Write the bubble sort

The village of Marengo conducted a census and collected records that have household data, including the number of occupants in each household.

  Write a program that prompts the user to enter the mass

Write a program that prompts the user to enter the mass of a person in kilograms and outputs theequivalent weight in pounds. Output both the mass and the weight rounded to two decimalplaces. (Note that for standard Earth gravity, 1 kilogram = 2.2 pou..

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