gann-cdf /
graphics
| 1 | package example.bubbleSortVisualization; |
||
| 2 | |||
| 3 | import org.gannacademy.cdf.graphics.curriculum.VisualSort; |
||
| 4 | import org.gannacademy.cdf.graphics.ui.AppWindow; |
||
| 5 | |||
| 6 | import java.awt.event.MouseEvent; |
||
| 7 | import java.awt.event.MouseListener; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Display a VisualSort visualization of Bubble Sort (click to start) |
||
| 11 | */ |
||
| 12 | public class Visualizer extends AppWindow implements MouseListener { |
||
| 13 | private VisualSort bubbleSort; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 14 | private boolean started; |
||
| 15 | |||
| 16 | protected void setup() { |
||
| 17 | bubbleSort = new BubbleSort(getDrawingPanel()); |
||
| 18 | started = false; |
||
| 19 | getDrawingPanel().addMouseListener(this); |
||
| 20 | getDrawingPanel().requestFocus(); |
||
| 21 | } |
||
| 22 | |||
| 23 | @Override |
||
| 24 | protected void loop() { |
||
| 25 | bubbleSort.update(); |
||
| 26 | sleep(1); |
||
| 27 | } |
||
| 28 | |||
| 29 | public static void main(String[] args) { |
||
| 30 | new Visualizer(); |
||
| 31 | } |
||
| 32 | |||
| 33 | @Override |
||
| 34 | public void mouseClicked(MouseEvent e) { |
||
|
0 ignored issues
–
show
|
|||
| 35 | } |
||
| 36 | |||
| 37 | @Override |
||
| 38 | public void mousePressed(MouseEvent e) { |
||
| 39 | if (!started) { |
||
| 40 | started = true; |
||
| 41 | bubbleSort.begin(); |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | @Override |
||
| 46 | public void mouseReleased(MouseEvent e) { |
||
|
0 ignored issues
–
show
|
|||
| 47 | } |
||
| 48 | |||
| 49 | @Override |
||
| 50 | public void mouseEntered(MouseEvent e) { |
||
|
0 ignored issues
–
show
|
|||
| 51 | } |
||
| 52 | |||
| 53 | @Override |
||
| 54 | public void mouseExited(MouseEvent e) { |
||
|
0 ignored issues
–
show
|
|||
| 55 | } |
||
| 56 | } |
||
| 57 |