Explorar el Código

Adds Error PopUps to SimulationConfigurationPanel

Andreas T. Meyer-Berg hace 6 años
padre
commit
6baaf8bfe9

+ 25 - 10
src/main/java/de/tu_darmstadt/tk/SmartHomeNetworkSim/view/SimulationConfigurator.java

@@ -4,6 +4,7 @@ import javax.swing.JFrame;
 import javax.swing.JProgressBar;
 import javax.swing.JButton;
 import javax.swing.JLabel;
+import javax.swing.JOptionPane;
 import javax.swing.JTextField;
 import javax.swing.Timer;
 
@@ -109,13 +110,24 @@ public class SimulationConfigurator extends JFrame {
 	
 	private void startStopButtonAction(){
 		if(timer == null){
-			timer = new Timer(0, a->simulateTimeStep());
-			currentTime = Long.parseLong(tfStartTimeLong.getText());
-			endTime = Long.parseLong(tfEndTimeLong.getText());
-			startTime = Long.parseLong(tfStartTimeLong.getText());
-			duration = Long.parseLong(tfStepDuration.getText());
-			progressBar.setValue(0);
-			lbCurrentTimeShow.setText(currentTime+" ms");
+			try {
+				timer = new Timer(0, a->simulateTimeStep());
+				currentTime = Long.parseLong(tfStartTimeLong.getText());
+				endTime = Long.parseLong(tfEndTimeLong.getText());
+				startTime = Long.parseLong(tfStartTimeLong.getText());
+				duration = Long.parseLong(tfStepDuration.getText());
+				progressBar.setValue(0);
+				lbCurrentTimeShow.setText(currentTime+" ms");				
+			} catch (Exception e) {
+				JOptionPane.showMessageDialog(this,
+					    "Following Error occured: "+e.toString(),
+					    "Error while configuring simulation ",
+					    JOptionPane.ERROR_MESSAGE);
+				//Don't start the timer
+				timer.stop();
+				timer = null;
+				return;
+			}
 		}
 		if(timer.isRunning()){
 			timer.stop();
@@ -125,8 +137,6 @@ public class SimulationConfigurator extends JFrame {
 	}
 	
 	private void resetAction(){
-		if(timer == null)return;
-		timer.stop();
 		try {
 			currentTime = Long.parseLong(tfStartTimeLong.getText());
 			endTime = Long.parseLong(tfEndTimeLong.getText());
@@ -135,8 +145,13 @@ public class SimulationConfigurator extends JFrame {
 			progressBar.setValue(0);
 			lbCurrentTimeShow.setText(currentTime+" ms");
 		} catch (Exception e) {
-			// TODO: handle exception
+			JOptionPane.showMessageDialog(this,
+				    "Following Error occured:\n"+e.toString(),
+				    "Error while configuring simulation ",
+				    JOptionPane.ERROR_MESSAGE);
 		}
+		if(timer == null)return;
+		timer.stop();
 	}
 	
 	private void simulateTimeStep(){