Overview In this project you will create 3 simple, binary 25x25 images or your c
ID: 3802385 • Letter: O
Question
Overview In this project you will create 3 simple, binary 25x25 images or your choice and use Java 2D graphic methods to rotate, scale and translate each of the images. Requirements: 1. Using Netbeans or Eclipse, develop a Java 2D graphics application that creates 3 images. The images should have the following specifications: a. Size: 25x25 pixels b. Type: binary (consists of ones or zeros) c. Simple form or shape (Hint: consider a letter or number, or even simple shapes such as crossing lines, rectangles, or circles d. You should generate the image inside of separate methods and store them as 2D arrays. 2. Use Java 2D graphics to display your original images. 3. For each image use the existing Java 2D graphics transformation methods to translate, rotate and scale each object. You should perform the following transformations on each image: a. Translate -5 in x direction, Translate +7 in the y direction. b. Rotate 45? counter clockwise. c. Rotate 90? clockwise d. Scale 2 times for the x component, scale 0.5 times for the y component e. Each of these transformations should be displayed in sequence with the images always starting from the previous transformation as opposed to the original image. f. Use Java 2D graphics to display each transformation for each image. (Hint: you can do this with loop and slight pause for each display) 4. All Java source code should be written using Google Java style guide. 5. Prepare, conduct and document a test plan verifying each method is functioning properly. (Hint: Using JUNIT tests are recommended) Deliverables: 1. All Java source code used for this project. Code should adhere to the Google Java style guide. 2. Word or PDF file demonstrating with clearly labeled screen captures and associated well-written descriptions, the success execution of your 2D graphics transformation. The document should be well-written, well-organized, include page numbers, captions for all screen captures, and a title page including your name, class, section number and date. References should be included for all sources used and formatted in APA style.
Explanation / Answer
001 package com.javaworld.media.j2d; 002 003 import java.awt.*; 004 import java.awt.event.*; 005 006 public class Example01 extends Frame { 007 /** 008 * Instantiates an Example01 object. 009 **/ 010 public static void main(String args[]) { 011 new Example01(); 012 } 013 014 /** 015 * Our Example01 constructor sets the frame's size, adds the 016 * visual components, and then makes them visible to the user. 017 * It uses an adapter class to deal with the user closing 018 * the frame. 019 **/ 020 public Example01() { 021 //Title our frame. 022 super("Java 2D Example01"); 023 024 //Set the size for the frame. 025 setSize(400,300); 026 027 //We need to turn on the visibility of our frame 028 //by setting the Visible parameter to true. 029 setVisible(true); 030 031 //Now, we want to be sure we properly dispose of resources 032 //this frame is using when the window is closed. We use 033 //an anonymous inner class adapter for this. 034 addWindowListener(new WindowAdapter() 035 {public void windowClosing(WindowEvent e) 036 {dispose(); System.exit(0);} 037 } 038 ); 039 } 040 041 /** 042 * The paint method provides the real magic. Here we 043 * cast the Graphics object to Graphics2D to illustrate 044 * that we may use the same old graphics capabilities with 045 * Graphics2D that we are used to using with Graphics. 046 **/ 047 public void paint(Graphics g) { 048 //Here is how we used to draw a square with width 049 //of 200, height of 200, and starting at x=50, y=50. 050 g.setColor(Color.red); 051 g.drawRect(50,50,200,200); 052 053 //Let's set the Color to blue and then use the Graphics2D 054 //object to draw a rectangle, offset from the square. 055 //So far, we've not done anything using Graphics2D that 056 //we could not also do using Graphics. (We are actually 057 //using Graphics2D methods inherited from Graphics.) 058 Graphics2D g2d = (Graphics2D)g; 059 g2d.setColor(Color.blue); 060 g2d.drawRect(75,75,300,200); 061 } 062 } public void paint(Graphics g) { 007 g.setColor(Color.red); 008 g.drawRect(50,50,200,200); 009 010 Graphics2D g2d = (Graphics2D)g; 011 g2d.setColor(Color.blue); 012 g2d.drawRect(75,75,300,200); 013 014 //Now, let's draw another rectangle, but this time, let's 015 //use a GeneralPath to specify it segment by segment. 016 //Furthermore, we're going to translate and rotate this 017 //rectangle relative to the Device Space (and thus, to 018 //the first two quadrilaterals) using an AffineTransform. 019 //We also will change its color. 020 GeneralPath path = new GeneralPath(GeneralPath.EVEN_ODD); 021 path.moveTo(0.0f,0.0f); 022 path.lineTo(0.0f,125.0f); 023 path.lineTo(225.0f,125.0f); 024 path.lineTo(225.0f,0.0f); 025 path.closePath(); 026 027 AffineTransform at = new AffineTransform(); 028 at.setToRotation(-Math.PI/8.0); 029 g2d.transform(at); 030 at.setToTranslation(50.0f,200.0f); 031 g2d.transform(at); 032 033 g2d.setColor(Color.green); 034 g2d.fill(path); 035 }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.