Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Graphics2D;
- import java.awt.Rectangle;
- import java.awt.geom.Ellipse2D;
- import java.awt.geom.Line2D;
- import java.awt.geom.Point2D;
- /**
- A Target shape that can be positioned anywhere on the screen.
- */
- public class Target
- {
- private int xLeft;
- private int yTop;
- /**
- * Constructs a Target with a given top left corner.
- * @param x the x-coordinate of the top-left corner
- * @param y the y-coordinate of the top-left corner
- */
- public Target(int x, int y)
- {
- xLeft = x;
- yTop = y;
- }
- /**
- * Draws the Target.
- * @param g2 the graphics context
- */
- public void draw(Graphics2D g2)
- {
- Ellipse2D.Double Target1 = new Ellipse2D.Double(xLeft + 69, yTop + 69, 666, 666);
- Ellipse2D.Double Target2 = new Ellipse2D.Double(xLeft + 220, yTop + 220, 333, 333);
- g2.draw(Target1);
- g2.draw(Target2);
- }
- import javax.swing.JFrame;
- public class TargetViewer
- {
- public static void main(String[] args)
- {
- JFrame frame = new JFrame();
- frame.setSize(300, 400);
- frame.setTitle("Two Targets");
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- TargetComponent component = new TargetComponent();
- frame.add(component);
- frame.setVisible(true);
- }
- }
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import javax.swing.JComponent;
- /**
- This component draws two Target shapes.
- */
- public class TargetComponent extends JComponent
- {
- public void paintComponent(Graphics g)
- {
- Graphics2D g2 = (Graphics2D) g;
- Target target1 = new Target(0, 0);
- int x = getWidth() - 60;
- int y = getHeight() - 30;
- Target target2 = new Target(x, y);
- target1.draw(g2);
- target2.draw(g2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement