Project 6 - { _obj[_index] = new BetterCircle(e.getX(),...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Project 6: Interfaces and Inheritance Garrett Mehlberg October 26 th , 2006
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This Applet Allows you to create circles and squares in either red or blue and either filled or not filled. import java.awt.*; import javax.swing.*; import java.awt.geom.*; public class BetterCircle extends MyCircle implements Paint2DObject { boolean _do_fill; Color _color; public BetterCircle(int x, int y, int r, Color c, boolean fill) { super(x-r/2,y-r/2,r); _color = c; _do_fill = fill; } public void painter(Graphics2D g2) { g2.setColor(_color); if (_do_fill) { super.fill(g2); } else { super.draw(g2); } } } public void mouseExited(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mousePressed(MouseEvent e){} public void mouseClicked(MouseEvent e) { boolean fill=_fill_checkbox.getState(); if (_form == RECTANGLE) { _obj[_index] = new BetterRectangle(e.getX(), e.getY(), 100, 100, _color, fill); _index++;
Background image of page 2
} else if (_form == CIRCLE)
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { _obj[_index] = new BetterCircle(e.getX(), e.getY(), 100, _color, fill); _index++; } repaint(); } } I think this is all I need since its al I changed or made. The questions. a) b)_do-fill is the overriding method and its done in both the BetterCircle and the BetterRectangle. c) Super is an composition and this is aggregation. d) test the code. Paint Applet_____________________ int _form; Color _color; int _index;_______________________ init() Paint() ActionListener() Mouse Event() My Rectangle _________ Rectangle2D.Double _rect; double _width; double _height;_________ move() Draw() Fill() My Circle___ _________ Ellipse2D.Double _circle; double _radius;_________ move() Draw() Fill() Better Circle__ __ _____ Bool _do_fill Color _color Better Circle___________ Painter() Better Rectangle __ _____ Bool _do_fill Color _color Better Rectangle_________ Painter()...
View Full Document

This note was uploaded on 04/30/2008 for the course NOT 001 taught by Professor Notaprofessor during the Spring '08 term at N. Arizona.

Page1 / 4

Project 6 - { _obj[_index] = new BetterCircle(e.getX(),...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online