package agh.cs.project1.animation;
import agh.cs.project1.simulation.Parameters;
import agh.cs.project1.simulation.SimulationEngine;
import javax.swing.*;
import java.awt.event.*;
private final Timer timer
;
private final MapPanel mapPanel;
private final SimulationEngine engine1;
private final SimulationEngine engine2;
private final JButton stopSimulationButton
;
private final JButton resumeSimulationButton
;
private final JButton showAnimalsWithDominantGenotype
;
public Main(SimulationEngine engine1,SimulationEngine engine2, Parameters params){
int delay = params.getDelay();
this.
timer = new Timer(delay,
this);
this.engine1 = engine1;
this.engine2 = engine2;
this.mapPanel = new MapPanel(engine1,engine2, params);
this.
stopSimulationButton = new JButton("Stop simulation");
this.
resumeSimulationButton = new JButton("Resume simulation");
this.
showAnimalsWithDominantGenotype = new JButton("Show animals with dominant genotype");
stopSimulationButton.addActionListener(this);
resumeSimulationButton.addActionListener(this);
showAnimalsWithDominantGenotype.addActionListener(this);
mapPanel.add(stopSimulationButton);
mapPanel.add(resumeSimulationButton);
mapPanel.add(showAnimalsWithDominantGenotype);
@Override
super.mouseClicked(e);
mapPanel.findClickedAnimal(e.getPoint().x,e.getPoint().y);
}
});
frame.setVisible(true);
frame.add(mapPanel);
}
@Override
if (engine1.allAnimalsDead() && engine2.allAnimalsDead())
timer.stop();
Object source
= e.
getSource();
if (source == stopSimulationButton) {
timer.stop();
}
else if (source == resumeSimulationButton)
timer.start();
else if (source == showAnimalsWithDominantGenotype) {
mapPanel.repaint();
mapPanel.setShowDominant(true);
}
else {
mapPanel.repaint();
engine1.nextDay();
engine2.nextDay();
}
}
public void run(){
timer.start();
}
}
{"html5":"htmlmixed","css":"css","javascript":"javascript","php":"php","python":"python","ruby":"ruby","lua":"text\/x-lua","bash":"text\/x-sh","go":"go","c":"text\/x-csrc","cpp":"text\/x-c++src","diff":"diff","latex":"stex","sql":"sql","xml":"xml","apl":"apl","asterisk":"asterisk","c_loadrunner":"text\/x-csrc","c_mac":"text\/x-csrc","coffeescript":"text\/x-coffeescript","csharp":"text\/x-csharp","d":"d","ecmascript":"javascript","erlang":"erlang","groovy":"text\/x-groovy","haskell":"text\/x-haskell","haxe":"text\/x-haxe","html4strict":"htmlmixed","java":"text\/x-java","java5":"text\/x-java","jquery":"javascript","mirc":"mirc","mysql":"sql","ocaml":"text\/x-ocaml","pascal":"text\/x-pascal","perl":"perl","perl6":"perl","plsql":"sql","properties":"text\/x-properties","q":"text\/x-q","scala":"scala","scheme":"text\/x-scheme","tcl":"text\/x-tcl","vb":"text\/x-vb","verilog":"text\/x-verilog","yaml":"text\/x-yaml","z80":"text\/x-z80"}