1 / 10

CS12420 – Lecture 5 Interactive Graphics

CS12420 – Lecture 5 Interactive Graphics. Lynda Thomas ltt@aber.ac.uk. In This Lecture. Interactive graphics. First look at a couple of failed attempts. In basic-graphics-withcomments Last time we just printed where the mouse is Need a way to store data as well.

jess
Download Presentation

CS12420 – Lecture 5 Interactive Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS12420 – Lecture 5Interactive Graphics Lynda Thomas ltt@aber.ac.uk

  2. In This Lecture • Interactive graphics

  3. First look at a couple of failed attempts • In basic-graphics-withcomments • Last time we just printed where the mouse is • Need a way to store data as well.

  4. Mouse Project Specification(note this is not on drag but on click) Title Panel 300x300 Mouse pointer left click: add right click: remove position: 137 53 number of clicks: 27 no. of circles: 2 mouse is in component: yes

  5. Look at files in directory • Need to save the circles so can repaint properly • Think about the last version: • Where do you know you need a circle - when you get a click - the MyMouseListener • Where do you need to save the circles – one theory is where you redraw them – the MouseEventPanel

  6. So, need to add a link back from the MyMouseListener to the drawing panel In the Frame: mL = new MyMouseListener(stPanel,mePanel); In the MyMouseListener: MyMouseListener(StatusPanel sp,MouseEventPanel mp) { statusPane = sp; mousePane = mp; } And then when the Mouse is clicked ….

  7. public void mouseClicked(MouseEvent e) { statusPane.incrementClickCount(); if(SwingUtilities.isLeftMouseButton(e)) { mousePane.addCircle(e.getX(),e.getY()); } else { mousePane.removeNearestCircle (e.getX(),e.getY()); } //will have to write the methods for addCircle and remove statusPane.setNoOfCircles(mousePane.getNoOfCircles()); }

  8. VectorOfCircles - circles : Vector<Circle> + addCircle() + removeNearestCircle() + drawAll() + getNoOfCircles() : int SimpleFrame + showIt() MouseEventDriver + main() UML Class Diagram MyMousePositionListener - stPanel : StatusPanel + mouseMoved(e : MouseEvent) StatusPanel - posText …. dummy3 : JLabel - clickCount : int + setCoordinates(x,y : int) + setInOut(s : String) + incrementClickCount() + setNoOfCircles(n : int) MyMouseListener - stPanel : StatusPanel - mePanel : MouseEventPanel + mouseEntered(e : MouseEvent) + mouseExited(e : MouseEvent) + mouseClicked(e : MouseEvent) MouseEventPanel - voc : VectorOfCircles - r : double + paintComponent(g : Graphics) + addCircle(x,y : int) + removeNearestCircle(x,y : int) + getNoOfCircles() : int MouseEventFrame - mePanel : MouseEventPanel - stPanel : StatusPanel Circle - x,y,r : double + draw(g : Graphics) + distanceTo(x,y : double) : double

  9. In This Lecture • Interactive graphics • There is lots more left for you to discover! • Your next mini-assignment (10%) is about this (you are asked to drag a circle around the screen)

More Related