Public void e circlesaddegetpoint repaint public void

This preview shows page 20 - 26 out of 26 pages.

public void mousePressed(MouseEvent e) { circles.add(e.getPoint()); repaint(); } public void mouseReleased(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mouseClicked(MouseEvent e) {} } Notice that this class uses an object of type CircleCollection to store and display the circles. You need to complete the code for this CircleCollection class. HINTS: You should store the positions of each circle in an array of Point s. You can calculate the radius of each circle based on the y-position of the centre of the circle – there is no need to store this radius. You can assume the maximum number of circles you will need to store is 1000. Complete the code for the CircleCollection class on the following page.
Image of page 20

Subscribe to view the full document.

- 21 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED import java.awt.*; public class CircleCollection { private Point[] pts; private int size; public CircleCollection() { pts = new Point[1000]; size = 0; } public void add(Point p) { pts[size] = p; size++; } public void draw(Graphics g) { for (int i = 0; i < size; i++) { int radius = pts[i].y; g.drawOval(pts[i].x - radius, pts[i].y-radius, radius*2, radius*2); } } (12 marks) }
Image of page 21
- 22 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED OVERFLOW PAGE (If you have used this page, please indicate clearly under the relevant question that you have overflowed to this page)
Image of page 22

Subscribe to view the full document.

- 23 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED OVERFLOW PAGE (If you have used this page, please indicate clearly under the relevant question that you have overflowed to this page)
Image of page 23
- 24 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED OVERFLOW PAGE (If you have used this page, please indicate clearly under the relevant question that you have overflowed to this page)
Image of page 24

Subscribe to view the full document.

- 25 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... CONTINUED ROUGH WORKING (WILL NOT BE MARKED) (You may use this page for rough working)
Image of page 25
- 26 - COMPSCI 101 Question/Answer Sheet ID: ..................................................................... ROUGH WORKING (WILL NOT BE MARKED) (You may use this page for rough working)
Image of page 26
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, English-language films, Following, Subroutine, ........., The Return

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern