Question: import imagePackage.RasterImage; import java.awt.Color; import java.awt.Graphics2D; public class Exercise03 { public static RasterImage image = new RasterImage(300,300); public static Graphics2D gfx = image.getGraphics2D(); public static
import imagePackage.RasterImage;
import java.awt.Color; import java.awt.Graphics2D;
public class Exercise03 {
public static RasterImage image = new RasterImage(300,300); public static Graphics2D gfx = image.getGraphics2D(); public static Color imageCol = Color.BLUE;
public static void main(String[] args) { /* * Exercise: Drawing some graphics primitives * * Copy and paste the code from the second exercise here. * * Now use the appropriate accessor (method) to obtain a reference to the * picture's Graphics2D object. */
/* * Now we know from the previous exercise that if we draw on the * Graphics2D object, the pen color will be white. When we printed the * value of the paint attribute, the result was as follows: * * java.awt.Color[r=255,g=255,b=255] * * Since the background of our RasterImage is also white, anything that * is drawn on the RasterImage will not be perceivable. Use the mutator * of Graphics2D to change the paint colour from white to red. */
/* * Now you will use the draw(Shape) method of the Graphics2D object to * draw an ellipse. * * To use this method, you will need to provide a reference to a Shape * object as the parameter value. * * To create an Ellipse object (which IS-A Shape, a child type of * Shape), use the Ellipse2D.Double(double x, double y, double w, double * h) constructor (see the API for this class in java.awt.geom). * * The class name Ellipse2D.Double is perhaps unusual because it has a * dot in the middle (this is called an inner class); this is perfectly * fine. * * Look in the API for this class in java.awt.geom in order to determine * the meaning of each of the four parameters. When you have this * figured out, create one ellipse to be a circle (same width and * height). The upper-left hand (x,y) anchor point of the circle should * be the upper left-hand corner of the picture. The diameter should be * one-quarter of the picture's width. */
/* * Now draw a second ellipse. * * Create the second ellipse to have a width that is one half of the * picture's width. The height should be half the width. The upper-left * hand (x,y) anchor point of the circle should be the center of the * image. * * Now draw a line. * * The line should start at the first ellipse's anchor point and end at * the second ellipse's anchor point. Once you have mastered this, then * modify the line so that the start and end points are the centers of * the respective ellipses. * * Use the services of the class Point to represent the points. * */
/* * Now draw a line. You can construct the Line object using the * following constructor * * Line2D.Double(Point2D, Point2D) * * the API can be found here: * http://docs.oracle.com/javase/8/docs/api/java * /awt/geom/Line2D.Double.html * * The line should start at the first ellipse's anchor point and end at * the second ellipse's anchor point. Once you have mastered this, then * modify the line so that the start and end points are the centers of * the respective ellipses. * * Use the services of the class Point2D.Double to represent the points. */ image.show(); image.setTitle("Lab02"); gfx.setColor(imageCol); gfx.fillRect(0, 0, 300, 300); System.out.println(gfx.getStroke().toString()); System.out.println(gfx.getFontRenderContext().toString()); System.out.println(gfx.getPaint().toString()); System.out.println(gfx.getFont().toString()); System.out.println(gfx.getTransform().toString()); System.out.println(gfx.getComposite().toString());
} }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
