Package GUI

Source Code of GUI.ZFenetre

package GUI;


import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.File;
import java.io.IOException;

import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
import javax.swing.UIManager;

import javax.swing.UnsupportedLookAndFeelException;


public class ZFenetre extends JFrame implements KeyListener {

  private static final long serialVersionUID = 1L;
 

  private ConteneurSchema pan_schema;
  private ConteneurLecture pan_lecture;
  private ConteneurNeurone pan_neurone;
  private StatBars pan_caracteristiques;
  private ConteneurReconnaissance pan_reconnaissance;
  private ConteneurVide pan_vide;

  private GestionReseau gr;



  public ZFenetre(){
   
    this.setTitle("Reseau de Neurones Artificiel");
    this.setResizable(false);
    //TODO : ATTENTION, l'instruction precedente est commentee car elle fait bugger le programme sous Mac.
   
   
    this.pack();
    JFrame.setDefaultLookAndFeelDecorated(true);
    this.setExtendedState(ZFenetre.MAXIMIZED_BOTH);
   
    this.setVisible(true);
   
    if(getWidth() <= 800 || getHeight()<=700) {
      JLabel p = new JLabel("Votre r�solution ne permet pas le fonctionnement de notre logiciel");
      p.setBounds(0,0,600,100);
      this.add(p);
    }
     
    else
    {
      gr = new GestionReseau();   
 
      pan_schema = new ConteneurSchema(gr);
      pan_neurone = new ConteneurNeurone(gr);
      pan_vide = new ConteneurVide(gr);
      pan_lecture = new ConteneurLecture(gr);
      pan_caracteristiques = new StatBars(gr);
      pan_reconnaissance = new ConteneurReconnaissance(gr);
 
      gr.setPanSchema(pan_schema);
      gr.setPanNeurone(pan_neurone);
      gr.setPanCaracteristiques(pan_caracteristiques);
      gr.setPanReconnaissance(pan_reconnaissance);
      gr.setPanLecture(pan_lecture);
      gr.setPanFenetre(this);
 
     
      pan_schema.setBounds(0,0,this.getWidth()/2,this.getHeight()*50/100);
      pan_lecture.setBounds(0,this.getHeight()*50/100,this.getWidth()/2,this.getHeight()*10/100);
      pan_neurone.setBounds(this.getWidth()/2,0,this.getWidth()/2,this.getHeight()*50/100);
      pan_caracteristiques.setBounds(0,this.getHeight()*60/100,this.getWidth()/2,this.getHeight()*40/100);
      pan_reconnaissance.setBounds(this.getWidth()/2,this.getHeight()*50/100,this.getWidth()/2,this.getHeight()*50/100);
     
      pan_vide.setBounds(0,0,this.getWidth(),this.getHeight());
 
      this.getContentPane().add(pan_schema);
      this.getContentPane().add(pan_vide);
      this.getContentPane().add(pan_neurone);
      this.getContentPane().add(pan_lecture);
      this.getContentPane().add(pan_caracteristiques);
      this.getContentPane().add(pan_reconnaissance);
 
      pan_vide.set();

      pan_schema.setVisible(false);
      pan_lecture.setVisible(false);
      pan_neurone.setVisible(false);
      pan_caracteristiques.setVisible(false);
      pan_reconnaissance.setVisible(false);
     
      this.addKeyListener(this);
     
      this.initMenu();
     
    }
   
    this.setLayout(null);
   
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  }
 
  private void initMenu() {
   
    JMenuBar menuBar = new JMenuBar();
    JMenu fichier = new JMenu("Fichier");
    JMenu edition = new JMenu("Actions");
    JMenu affichage = new JMenu("Affichage");
    JMenu aide = new JMenu("Aide");
   
      JMenuItem charger_sequence_apprentissage = new JMenuItem("Charger sequence apprentissage (C)");
      JMenuItem charger_sequence_test = new JMenuItem("Charger sequence test (T)");
      JMenuItem editeur = new JMenuItem("Editeur (E)");
      JMenuItem quitter = new JMenuItem("Quitter");
     
      JMenuItem suivant = new JMenuItem("Neurone suivant (Q)");
      JMenuItem nextimg = new JMenuItem("Image suivante (S)");
      JMenuItem nextseq = new JMenuItem("Sequence suivante (D)");
      JMenuItem golast = new JMenuItem("Passer l'apprentissage (F)");

      JCheckBoxMenuItem infos = new JCheckBoxMenuItem("Afficher informations");
     
      JMenuItem aide_en_ligne = new JMenuItem("Aide en ligne");
      JMenuItem a_propos = new JMenuItem("A propos");

      infos.setState(true);
      gr.setInfos(true);
     
    fichier.add(charger_sequence_apprentissage);
    fichier.add(charger_sequence_test);
    fichier.add(editeur);
    fichier.add(quitter);
   
    edition.add(suivant);
    edition.add(nextimg);
    edition.add(nextseq);
    edition.add(golast);
   
    affichage.add(infos);

    aide.add(aide_en_ligne);
    aide.add(a_propos);
   
    menuBar.add(fichier);
    menuBar.add(edition);
    menuBar.add(affichage);
    menuBar.add(aide);
    setJMenuBar(menuBar);
   
   
    quitter.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        System.exit(0);
      }
    });
   
   
    charger_sequence_apprentissage.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        gr.chargerFichierXML();
      }
    });
   
    charger_sequence_test.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        gr.chargerReseauDefaut();
      }
    });
   
    suivant.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        gr.suivant();
      }
    });
 
      nextimg.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        gr.nextimg();
      }
    });

      nextseq.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        gr.nextseq();
      }
    });
     
      golast.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        gr.golast();
      }
    });
   
    infos.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        gr.invInfos();
      }
    });
   
    editeur.addActionListener(new ActionListener(){
      public void actionPerformed(ActionEvent event){
        try {
              Runtime.getRuntime().exec("java -jar editeur.jar");
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    });
  }

  public File chargerFileChooser(){
    JFileChooser dialogue = new JFileChooser(System.getProperty("user.dir"));
    File fichier = null;
    if(dialogue.showOpenDialog(null)== JFileChooser.APPROVE_OPTION) {
      fichier = dialogue.getSelectedFile();
      if(fichier.getName().endsWith(".xml")) {
        charger();
        return fichier;
      }
    }
    return null;
  }
 
  public void charger() {
   
    new Thread() { public void run () {
      afficher_chargement();
      pan_vide.setVisible(false);
      pan_schema.setVisible(true);
      pan_neurone.setVisible(true);
      pan_lecture.setVisible(true);
      pan_reconnaissance.setVisible(true);
      pan_caracteristiques.setVisible(true);
    }}.start();
         

  }
 
  public static void main(String[] args) {
    UIManager.installLookAndFeel("Mac","ch.randelshofer.quaqua");
    try {
      UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (InstantiationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
        ZFenetre fenetre = new ZFenetre();
        fenetre.setVisible(true);
  }

  @Override
  public void keyPressed(KeyEvent arg0) {
   
  }

  @Override
  public void keyReleased(KeyEvent arg0) {
   
  }

  @Override
  public void keyTyped(KeyEvent arg0) {
    switch(arg0.getKeyChar()) {
   
    case 'c' :
      gr.chargerFichierXML();
      break;
     
    case 'q' :
      gr.suivant();
      break;
     
    case 's' :
      gr.nextimg();
      break;
     
    case 'd' :
      gr.nextseq();
      break;
     
    case 'f' :
      gr.golast();
      break;
     
    case 'e' :
      try {
            Runtime.getRuntime().exec("java -jar editeur.jar");
      } catch (IOException e) {
        e.printStackTrace();
      }
      break;
     
    case 't' :
      gr.chargerReseauDefaut();
      break;
    }   
  }
 
  private void afficher_chargement() {
   

    JWindow window = new JWindow();
    window.setSize(new Dimension(this.getWidth(),this.getHeight()-48));//On lui donne une taille pour qu'on puisse la voir
    window.setLocationRelativeTo(this);
    window.setLocation(0,48);
    JPanel pane = new JPanel();
    pane.setLayout(new FlowLayout());
    pane.setBackground(Color.RED);
    JLabel label = new JLabel("Loading Neuronux ...");
    JProgressBar b = new JProgressBar(JProgressBar.HORIZONTAL,0,100);
    pane.add(label);
    pane.add(b);
    pane.setBounds(this.getWidth(), this.getHeight(), 350, 35);
    this.add(pane);
    window.setContentPane(pane);
    window.setAlwaysOnTop(true);
    window.setVisible(true);//On la rend visible
    for (int i = 0; i < 100; i++){
    b.setValue(i);
    try {
      Thread.sleep(10);
    } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    }
    this.remove(pane);
    window.dispose();//On la detruit
  }
}
TOP

Related Classes of GUI.ZFenetre

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.