public MainWindow()
	{
		/**
		 * Initialisation des elements graphiques
		 */

		// Definition de la frame
		frame = new JFrame("Automaton cellular");
		frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		frame.setPreferredSize(new Dimension(1100, 600));
		frame.setMinimumSize(new Dimension(1100, 600));
		frame.setResizable(false);

		// Creation du panel contenant la grille
		backgroundPanel = new JPanel();	
		backgroundPanel.setLayout(new BorderLayout());
		backgroundPanel.setBorder(new EmptyBorder(30,30,30,30));
		backgroundPanel.setPreferredSize(new Dimension(500,500));

		// Panel user interface
		uiPanel = new JPanel();
		uiPanel.setLayout(new GridLayout(5,1,5,5));
		uiPanel.setBorder(new EmptyBorder(30,5,30,5));
		uiPanel.setPreferredSize(new Dimension(500, 600));
		uiPanel.setMinimumSize(new Dimension(500, 600));

		// Panel choix taille grille
		sizePanel = new JPanel();

		// Panel choix obstacles et personnes
		obsAndPersPanel = new JPanel();
		obsAndPersPanel.setLayout(new GridLayout(3,2));

		// Panel choix nombre d'entree
		nbEntryPanel = new JPanel();
		nbEntryPanel.setLayout(new GridLayout(3,2));

		// Panel choix du positionnement des entrees
		posEntryPanel = new JPanel();
		posEntryPanel.setLayout(new GridLayout(0,4));

		// Panel boutons
		buttonsPanel = new JPanel();
		buttonsPanel.setLayout(new GridLayout(3,3,5,5));

		// Boutons
		start = new JButton("start");
		stop = new JButton("stop");
		restart = new JButton("restart");	
		confirm = new JButton("confirm");

		start.setEnabled(false);
		restart.setEnabled(false);
		stop.setEnabled(false);

		buttonsPanel.add(confirm);
		buttonsPanel.add(start);
		buttonsPanel.add(stop);
		buttonsPanel.add(restart);

		fieldNbEntries = new JTextField();
		fieldNbEntries.setText("[1,0]");
		lblNbEntries = new JLabel("Entries: [x,y] ");
		lblNbEntries.setLabelFor(fieldNbEntries);

		NumberFormat percentFormat = NumberFormat.getNumberInstance();
		percentFormat.setMinimumFractionDigits(2);
		fieldLambda = new JFormattedTextField(percentFormat);
		fieldLambda.setValue(lambda);
		lblLambda = new JLabel("Diagonal movements value: ");
		lblLambda.setLabelFor(lblLambda);

		newFigure = new JCheckBox();
		newFigure.setSelected(true);
		newFigure.setEnabled(false);
		lblnewFigure = new JLabel("Open a new chart");
		lblnewFigure.setLabelFor(newFigure);

		nbEntryPanel.add(lblLambda);
		nbEntryPanel.add(fieldLambda);
		nbEntryPanel.add(lblNbEntries);
		nbEntryPanel.add(fieldNbEntries);
		nbEntryPanel.add(lblnewFigure);
		nbEntryPanel.add(newFigure);

		// taille de la grille 
		Integer[] size = new Integer[SIZE_MAX];

		for(int i = 1; i <= SIZE_MAX ; i++) size[i - 1] = i;

		cbNbLigne = new JComboBox(size);
		cbNbCol = new JComboBox(size);
		lblSize = new JLabel("Grid size");
		cbNbLigne.setSelectedIndex(nbLigneGrille-1);
		cbNbCol.setSelectedIndex(nbColGrille-1);

		JLabel lblligne = new JLabel("lines");
		JLabel lblcol = new JLabel("columns");

		sizePanel.add(lblSize);	
		sizePanel.add(cbNbLigne);
		sizePanel.add(lblligne);
		sizePanel.add(cbNbCol);
		sizePanel.add(lblcol);

		// Obstacles et Personnes
		lblObstacles = new JLabel("Obstacles ([xStart,yStart;xEnd,yEnd]");
		lblPersonnes = new JLabel("Persons ([x,y])");
		fieldObstacles = new JTextField();

		fieldObstacles.setText("[2,2;4,2][7,2;8,2][2,4;4,4][7,4;8,4][2,6;4,6][7,6;8,6][5,8;6,8]");	
		fieldObstacles.setMaximumSize(new Dimension(50, 30));
		fieldPersonnes = new JTextField();
		fieldPersonnes.setText("[2,1][3,1][4,1][7,1][8,1][2,3][3,3][4,3][7,3][8,3][2,5][3,5][4,5][7,5][8,5][6,9]");
		lblObstacles.setLabelFor(fieldObstacles);
		lblPersonnes.setLabelFor(fieldPersonnes);

		obsAndPersPanel.add(lblObstacles);
		obsAndPersPanel.add(fieldObstacles);
		obsAndPersPanel.add(lblPersonnes);
		obsAndPersPanel.add(fieldPersonnes);

		uiPanel.add(sizePanel);
		uiPanel.add(obsAndPersPanel);
		uiPanel.add(nbEntryPanel);
		uiPanel.add(posEntryPanel);
		uiPanel.add(buttonsPanel);

		// Ajout du panel a la frame + dessin + affichage
		frame.add("Center",backgroundPanel);
		frame.add("East",uiPanel);

		frame.pack();
		frame.setVisible(true);

		/**
		 * Definition des actions liees aux boutons
		 */

		/**
		 * Permet de confirmer que la grille a creer est bien conforme
		 */
		confirm.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {						

				nbLigneGrille = cbNbLigne.getSelectedIndex() + 1;
				nbColGrille = (Integer) cbNbCol.getItemAt(cbNbCol.getSelectedIndex());

				setEntries();
				setPersonnes();
				setObstacles();
				if(areValidObstacles())
				{
					if(areValidPersonnes())
					{
						if(isValidEntry())
						{					
							posEntryPanel.removeAll();
							if(controlleur != null){
								backgroundPanel.remove(controlleur.getDrawArea());
							}

							lambda = Float.parseFloat(fieldLambda.getText().replace(",","."));

							if(newFigure.isSelected())
							{
								chartline = new ChartLine("Sortie des personnes");
							}
							Grid grille = new Grid(nbLigneGrille, nbColGrille, tabX, tabY, lambda, obstacles);
							controlleur = new Controller(grille, personnes ,chartline);	
							backgroundPanel.add("Center",controlleur.getDrawArea());
							frame.repaint();
							frame.pack();					
							start.setEnabled(true);
						}
						else
						{
							JOptionPane.showMessageDialog(frame, "Entree(s) invalide(s)");
						}
					}else{
						JOptionPane.showMessageDialog(frame, "Personne(s) invalide(s)");
					}
				}else
				{
					JOptionPane.showMessageDialog(frame, "Obstacle(s) invalide(s)");					
				}
			}

		});
		/**
		 * Demarre la simulation
		 */
		start.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {				
				controlleur.startSimulation();
				stop.setEnabled(true);
				start.setEnabled(false);
				restart.setEnabled(true);
				confirm.setEnabled(false);
				newFigure.setEnabled(true);
			}

		});

		/**
		 * Mets en pause la simulation
		 */
		stop.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				controlleur.stopSimulation();
				start.setEnabled(true);
				stop.setEnabled(false);
				confirm.setEnabled(true);
			}

		});

		/**
		 * Re-initialise la grille
		 */
		restart.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {			
				stop.setEnabled(false);				

				backgroundPanel.remove(controlleur.getDrawArea());
				if(newFigure.isSelected())
				{
					chartline = new ChartLine("Sortie des personnes");
				}
				Grid grille = new Grid(nbLigneGrille, nbColGrille, tabX, tabY, lambda, obstacles);
				controlleur = new Controller(grille,personnes,chartline);
				backgroundPanel.add("Center",controlleur.getDrawArea());

				frame.repaint();
				frame.pack();
				start.setEnabled(true);
				confirm.setEnabled(true);
			}

		});

	}