|
@@ -12,7 +12,11 @@ import javax.swing.plaf.basic.BasicSliderUI;
|
|
|
import java.awt.*;
|
|
|
import java.awt.event.*;
|
|
|
import java.util.Hashtable;
|
|
|
-
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.ScheduledFuture;
|
|
|
+import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
/**
|
|
|
* This Class represents a Panel where the User can start and stop the
|
|
|
* Simulation. He Can also reset the Simulation and click through every
|
|
@@ -41,6 +45,7 @@ public class TimePanel extends JPanel implements ActionListener{
|
|
|
private final JPanel timeBtnPanel = new JPanel();
|
|
|
private final JPanel iterationsPanel=new JPanel();
|
|
|
private final JPanel timePanel=new JPanel();
|
|
|
+ private ScheduledFuture<?> futureTask;
|
|
|
//private LabelHint iterationsLblHint;
|
|
|
JSlider timeSlider = new JSlider() {
|
|
|
/**
|
|
@@ -290,12 +295,17 @@ public class TimePanel extends JPanel implements ActionListener{
|
|
|
iterationsField.setText(""+cont.getModel().getIterations());
|
|
|
iterationsField.setToolTipText("0-" + MAX_ITERATIONS );
|
|
|
iterationsField.addActionListener(this);
|
|
|
+ ScheduledThreadPoolExecutor s = new ScheduledThreadPoolExecutor(1);
|
|
|
iterationsField.addCaretListener((e)->
|
|
|
{
|
|
|
try{
|
|
|
int a=Integer.parseInt(iterationsField.getText());
|
|
|
iterationsField.setBackground(Color.WHITE);//red stings
|
|
|
//this.actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "like Enter")); that is lagging
|
|
|
+ if(futureTask != null){
|
|
|
+ futureTask.cancel(true);
|
|
|
+ }
|
|
|
+ futureTask = s.schedule((Runnable)() -> updateIterationsInput(), 1, TimeUnit.SECONDS);
|
|
|
hint.setText(" ");
|
|
|
}catch(NumberFormatException n){
|
|
|
iterationsField.setBackground(GUI.PALE_RED);//red stings
|
|
@@ -303,11 +313,10 @@ public class TimePanel extends JPanel implements ActionListener{
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
- iterationsField.addFocusListener(new java.awt.event.FocusAdapter() {
|
|
|
- public void focusLost (java.awt.event.FocusEvent evt) {
|
|
|
- updateIterationsInput();
|
|
|
- }
|
|
|
- });
|
|
|
+ iterationsField.addFocusListener((interfaces.FocusListener)(e) ->{
|
|
|
+ //FocusLost is not defined in interface have to be defined here
|
|
|
+ updateIterationsInput();
|
|
|
+ });
|
|
|
c.gridy = 1;
|
|
|
iterationsPanel.add(iterationsField, c);
|
|
|
c.gridy = 2;
|