it-artikel:java:my-solution-on-assignment-2-problem-2
Differences
This shows you the differences between two versions of the page.
— | it-artikel:java:my-solution-on-assignment-2-problem-2 [2022-08-31 12:30] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== My Solution on Assignment 2 - Problem 2 ====== | ||
+ | |||
+ | This is my Solution of Assignment 2 - Problem 2 from the [[http:// | ||
+ | |||
+ | <code java Target.java> | ||
+ | /* | ||
+ | * File: Target.java | ||
+ | * Name: | ||
+ | * Section Leader: | ||
+ | * ----------------- | ||
+ | * This file is the starter file for the Target problem. | ||
+ | * Assignment 2 , Problem 2 | ||
+ | */ | ||
+ | |||
+ | import acm.graphics.*; | ||
+ | import acm.program.*; | ||
+ | import java.awt.*; | ||
+ | |||
+ | import javax.swing.plaf.synth.ColorType; | ||
+ | |||
+ | public class Target extends GraphicsProgram { | ||
+ | |||
+ | public static final int dpi = 72; // 72 dots/pixel per inch is assumed | ||
+ | |||
+ | public void run() { | ||
+ | GetCanvasSizeAndFillVars(); | ||
+ | DrawTargetAt(CanvasX/ | ||
+ | } | ||
+ | |||
+ | public void DrawTargetAt(int X, int Y) { | ||
+ | /* | ||
+ | * This Method draws the " | ||
+ | * LOOK of the Logo and how its build up. | ||
+ | * X and Y define the CENTER POINT of the Logo/Target Sign. | ||
+ | */ | ||
+ | DrawCircleAt(X, | ||
+ | DrawCircleAt(X, | ||
+ | DrawCircleAt(X, | ||
+ | } | ||
+ | |||
+ | public void DrawCircleAt(int CenterX,int CenterY, | ||
+ | /* | ||
+ | * This Method draws a CIRCLE with its Centerpoint at X,Y with the Radius | ||
+ | * given in INCH. Circles are of a SINGLE SOLID COLOR (filled). | ||
+ | * Actual Size on the Screen depends on the Value set by the " | ||
+ | */ | ||
+ | |||
+ | // | ||
+ | double RadiusPixels = RadiusInch * dpi; | ||
+ | // | ||
+ | double X = CenterX - RadiusPixels; | ||
+ | double Y = CenterY - RadiusPixels; | ||
+ | |||
+ | GOval aCircle = new GOval(X, Y, 2*RadiusPixels, | ||
+ | aCircle.setColor( Colour ); // set Outline as same Color | ||
+ | aCircle.setFillColor( Colour ); // set Fill as same Color | ||
+ | aCircle.setFilled(true); | ||
+ | add(aCircle); | ||
+ | } | ||
+ | |||
+ | public void GetCanvasSizeAndFillVars() { | ||
+ | /* | ||
+ | * Get Canvas Sizes and fill in Class Variables | ||
+ | */ | ||
+ | CanvasX = getWidth(); | ||
+ | CanvasY = getHeight(); | ||
+ | } | ||
+ | |||
+ | |||
+ | public int CanvasX, CanvasY; // some public Class Variables | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | --- // | ||
+ | |||
+ | |||
+ | {{tag> | ||