瀏覽代碼

reset when you click on the slider

Kevin Trometer 8 年之前
父節點
當前提交
c7eddef8e2
共有 1 個文件被更改,包括 11 次插入2 次删除
  1. 11 2
      src/ui/view/TimePanel.java

+ 11 - 2
src/ui/view/TimePanel.java

@@ -5,6 +5,8 @@ import java.awt.Color;
 import java.awt.Image;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
 
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
@@ -94,6 +96,13 @@ public class TimePanel extends JPanel {
 			}
 		});
 
+		timeSlider.addMouseListener(new MouseAdapter() {
+			@Override
+			public void mousePressed(MouseEvent e) {
+				controller.resetSimulation();
+			}
+		});
+
 		// Panel
 		timeBtnPanel.setBorder(null);
 		timeBtnPanel.setBackground(Color.WHITE);
@@ -134,7 +143,7 @@ public class TimePanel extends JPanel {
 			public void actionPerformed(ActionEvent ae) {
 				timeSlider.setValue(timeSlider.getMinimum());
 				controller.setCurIteration(timeSlider.getValue());
-				//controller.calculateStateForCurrentTimeStep();
+				// controller.calculateStateForCurrentTimeStep();
 				controller.resetSimulation();
 			}
 		});
@@ -170,7 +179,7 @@ public class TimePanel extends JPanel {
 		/*
 		 * the backwards button isnt used anymore
 		 */
-		//timeBtnPanel.add(timeBackwardBtn);
+		// timeBtnPanel.add(timeBackwardBtn);
 		timeBtnPanel.add(timeForwardBtn);
 
 		this.add(timeBtnPanel, BorderLayout.WEST);