1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226
|
package generique;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Simulation extends JFrame {
private static final long serialVersionUID = 1L;
public JButton start,setup,stop;
public static JPanel carte;
JSlider jsnbfourmi;
JLabel jlnbfourmi,labf;
public boolean boolStop;
public RepetAction repet;
int nbfourmi = 10;
public Simulation() {
setTitle("Simulateur");
setSize(1020, 643);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
carte = getCarte();
getContainer(carte);
setVisible(true);
}
/** creation du bouton start */
public JButton getStart()
{
start = new JButton();
start.setLayout(null);
start.setBounds(40,15,70,20);
start.setText("Début");
// ecouteur du bouton start
start.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
doDebut();
}
}
);
return start;
}
/* creation du bouton setup */
public JButton getSetup()
{
setup = new JButton();
setup.setLayout(null);
setup.setBounds(150,15,70,20);
setup.setText("Setup");
// ecouteur du bouton setup
setup.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
doSetup();
}
}
);
return setup;
}
/** creation du bouton stop */
public JButton getStop()
{
stop = new JButton();
stop.setLayout(null);
stop.setBounds(260,15,70,20);
stop.setText("Arret");
// ecouteur du bouton stop
stop.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e)
{
doFin();
}
}
);
return stop;
}
/** panel contenant les boutons de commande */
public JPanel getJPanelCommande()
{
JPanel panelCom = new JPanel();
panelCom.setLayout(null);
panelCom.setBounds(0, 0, 390, 50);
panelCom.setBackground(Color.PINK);
panelCom.add(getStart());
panelCom.add(getSetup());
panelCom.add(getStop());
return panelCom;
}
/** panel contenant les boutons de paramètrage */
public JPanel getJPanelParametre()
{
JPanel panelParam = new JPanel();
panelParam.setLayout(null);
panelParam.setBounds(0, 70, 390, 550);
panelParam.setBackground(Color.orange);
//nombre de fourmi
JLabel lab1 = new JLabel("Nombre de fourmi");
lab1.setForeground(Color.red);
lab1.setBounds(130,25, 150, 10);
JLabel labf = new JLabel();
labf.setText(""+nbfourmi);
labf.setForeground(Color.black);
labf.setBounds(340,40,200,10);
JSlider jsnbfourmi = new JSlider(1,200,nbfourmi);
jsnbfourmi.setBounds(30, 40, 300, 30);
//jsnbfourmi.putClientProperty("JSlider.isFilled", Boolean.TRUE);
//jsnbfourmi.setSnapToTicks(true);
jsnbfourmi.addChangeListener(new ChangeListener(){
public void stateChanged(ChangeEvent e)
{
jsnbfourmiChange();
}
});
panelParam.add(jsnbfourmi);
panelParam.add(lab1);
panelParam.add(labf);
return panelParam;
}
/** methode qui retourne le panel carte */
public JPanel getCarte() {
JPanel carte = new JPanel();
carte.setLayout(null);
carte.setBounds(398, 0, 602, 602);
carte.setBackground(Color.gray);
carte.repaint();
return carte;
}
/** methode qui ajoute tous les panels dans le container */
public void getContainer(JPanel carte) {
Container cf = this.getContentPane();
cf.setLayout(null);
cf.add(carte);
cf.add(getJPanelCommande());
cf.add(getJPanelParametre());
}
/** clique sur le bouton start */
private void doDebut() {
carte = getCarte();
carte.repaint();
getContainer(carte);
start.setEnabled(false);
setup.setEnabled(false);
repet = new RepetAction(carte);
}
/** clique sur le bouton setup */
protected void doSetup() {
}
/** clique sur le bouton stop */
private void doFin() {
boolStop = true;
}
public void jsnbfourmiChange()
{
nbfourmi = jsnbfourmi.getValue();
labf.setText(""+nbfourmi);
}
public static void main (String[] args) {
new Simulation();
}
} |
Partager