Bloc - Notes

Description

/*
 * @Auteur : Ntoutoume Menzoughe Yannick alias TonyJiste
 * @Date : 01/05/2015
 * @Description : Bloc Notes, mieux que celui de microsoft! :-)
 * @Version : 1.2
 */
package ga.tony.blocnotes;

import java.awt.Color;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.filechooser.FileFilter;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter;
import javax.swing.text.Highlighter;
import javax.swing.text.Highlighter.HighlightPainter;

@SuppressWarnings("serial")
public class Window extends JFrame implements ActionListener,WindowListener{

	private FileFilter texte = new FiltreTexte("Fichier texte",".txt");
	private FileFilter docx = new FiltreTexte("Fichier word",".docx");
	private FileFilter pdf = new FiltreTexte("Fichier pdf",".pdf");
	private JSeparator jp = new JSeparator();
	private JMenuBar jmb = new JMenuBar();
	private JMenu fichier = new JMenu("Fichier");
	private JMenu edition = new JMenu("Edition");
	private JMenu couleur = new JMenu("Couleur");
	private JMenu background = new JMenu("Arrière plan");
	private JMenu texteColor = new JMenu("Couleur du texte");
	private JMenu aide = new JMenu("Aide?");
	private JMenu style = new JMenu("style");
	private JMenu police = new JMenu("police");
	private JMenu tailleTexte = new JMenu("Taille du texte");
	private JMenuItem petit = new JMenuItem("petit");
	private JMenuItem moyen = new JMenuItem("moyen");
	private JMenuItem grand = new JMenuItem("grand");
	private JMenuItem tahoma = new JMenuItem("tahoma");
	private JMenuItem garamond = new JMenuItem("garamond");
	private JMenuItem calibri = new JMenuItem("calibri");
	private JMenuItem arial = new JMenuItem("arial");
	private JMenuItem century = new JMenuItem("century");
	private JMenuItem nouveau = new JMenuItem("Nouveau");
	private JMenuItem ouvrir = new JMenuItem("Ouvrir");
	private JMenuItem enregistrer = new JMenuItem("Enregistrer");
	private JMenuItem effacer = new JMenuItem("Effacer");
	private JMenuItem imprimer = new JMenuItem("Imprimer");
	private JMenuItem rechercher = new JMenuItem("Rechercher");
	private JMenuItem remplacer = new JMenuItem("Remplacer");
	private JMenuItem compter = new JMenuItem("Compter");
	private JMenuItem rouge = new JMenuItem("rouge");
	private JMenuItem bleu = new JMenuItem("bleu");
	private JMenuItem vert = new JMenuItem("vert");
	private JMenuItem jaune = new JMenuItem("jaune");
	private JMenuItem gris = new JMenuItem("gris");
	private JMenuItem orange = new JMenuItem("orange");
	private JMenuItem violet = new JMenuItem("violet");
	private JMenuItem noir = new JMenuItem("noir");
	private JMenuItem blanc = new JMenuItem("blanc");
	private JMenuItem apropos = new JMenuItem("A Propos!");
	private JTextArea zoneTexte = new JTextArea();
	private JScrollPane glisseur = new JScrollPane(zoneTexte);
	private ImageIcon logoBlocNote = new ImageIcon("logoBleuBlocNote.jpg");
	
	protected Window() {
		
		this.setTitle("Bloc Notes");
		this.setSize(630, 360);
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		Image icone = Toolkit.getDefaultToolkit().getImage("ptitlogo.png");
		this.setIconImage(icone);
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.addWindowListener(this);
		fichier.add(nouveau);fichier.add(ouvrir);fichier.add(enregistrer);fichier.addSeparator();fichier.add(imprimer);
		edition.add(rechercher);edition.add(remplacer);edition.add(compter);edition.add(jp);edition.add(effacer);
		texteColor.add(rouge);texteColor.add(bleu);background.add(blanc);texteColor.add(orange);
		texteColor.add(gris);texteColor.add(vert);texteColor.add(jaune);texteColor.add(violet);background.add(noir);
		aide.add(apropos);
		style.add(police);style.addSeparator();style.add(tailleTexte); 
		police.add(arial);police.add(calibri);police.add(century);police.add(garamond);police.add(tahoma);
		tailleTexte.add(petit);tailleTexte.add(moyen);tailleTexte.add(grand);
		couleur.add(texteColor);couleur.add(background);
		jmb.add(fichier);jmb.add(edition);jmb.add(couleur);jmb.add(style);jmb.add(aide);
		jmb.setBackground(new Color(51,63,186));
		fichier.setForeground(Color.blue);fichier.setFont(new Font("Tahoma",Font.BOLD,11));
		edition.setForeground(Color.blue);edition.setFont(new Font("Tahoma",Font.BOLD,11));
		couleur.setForeground(Color.blue);couleur.setFont(new Font("Tahoma",Font.BOLD,11));
		aide.setForeground(Color.blue);aide.setFont(new Font("Tahoma",Font.BOLD,11));
		style.setForeground(Color.blue);style.setFont(new Font("Tahoma",Font.BOLD,11));
		
		fichier.setMnemonic('f');
		edition.setMnemonic('e');
		couleur.setMnemonic('c');
		aide.setMnemonic('a');
		style.setMnemonic('s');
		this.setJMenuBar(jmb);
		this.add(glisseur);
		
		//nouveau.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,KeyEvent.CTRL_DOWN_MASK));
	
		rouge.addActionListener(this);jaune.addActionListener(this);violet.addActionListener(this);noir.addActionListener(this);
		vert.addActionListener(this);blanc.addActionListener(this);orange.addActionListener(this);gris.addActionListener(this);
		bleu.addActionListener(this);apropos.addActionListener(this);
		rechercher.addActionListener(this); compter.addActionListener(this);remplacer.addActionListener(this);effacer.addActionListener(this);
		nouveau.addActionListener(this);ouvrir.addActionListener(this);enregistrer.addActionListener(this);imprimer.addActionListener(this);
		grand.addActionListener(this);moyen.addActionListener(this);century.addActionListener(this);tahoma.addActionListener(this);
		garamond.addActionListener(this);calibri.addActionListener(this);petit.addActionListener(this);
		arial.addActionListener(this);
	    
		try {
	            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	            SwingUtilities.updateComponentTreeUI(this);
	            UIManager.put("OptionPane.background", new Color(252,252,252));
	            UIManager.put("Panel.background", new Color(252,252,252));
	            UIManager.put("OptionPane.messageForeground", Color.BLUE);
	    
	        } catch (ClassNotFoundException ex) {
	            Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
	        } catch (InstantiationException ex) {
	            Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
	        } catch (IllegalAccessException ex) {
	            Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
	        } catch (UnsupportedLookAndFeelException ex) {
	            Logger.getLogger(Window.class.getName()).log(Level.SEVERE, null, ex);
	        }
 }
	protected void showWindow()
	{
		this.setVisible(true);
	}
	protected void ecrireDansFichier(File fichier, String texte)
	{
		try{
			FileWriter fiw =  new FileWriter(fichier);
			BufferedWriter bw = new BufferedWriter(fiw);
			PrintWriter pw = new PrintWriter(bw);
			pw.println(texte);
			pw.close();	
		}catch (FileNotFoundException e) {
			JOptionPane.showMessageDialog(this, "Erreur, fichier non trouvé!!!", "Erreur",JOptionPane.WARNING_MESSAGE );}
    	catch (IOException e) {
    		JOptionPane.showMessageDialog(this, "Erreur lors de la lecture du fichier", "Erreur",JOptionPane.WARNING_MESSAGE );}
	}
	protected void enregistrerFichier(String phrase)
	{
		JFileChooser save = new JFileChooser();
		save.setDialogTitle("Enregistrer");
		save.addChoosableFileFilter(texte);
		save.addChoosableFileFilter(docx);
		save.addChoosableFileFilter(pdf);
		save.setAcceptAllFileFilterUsed(true);
		int enregistre = save.showSaveDialog(this);
		if (enregistre == JFileChooser.APPROVE_OPTION)
		{
			File fichier = save.getSelectedFile();
			if (!fichier.exists())
			{	
				if (!save.getSelectedFile().getAbsolutePath().endsWith(".txt"))
				{
					save.getSelectedFile().getAbsolutePath().concat(".txt");
				}
				ecrireDansFichier(fichier,phrase);
			}
		    else
			{
		    	int resu = JOptionPane.showConfirmDialog(this, "Le fichier existe déja voulez le vous vraiment le remplacer?", "Confirmation", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
				if ( resu == JOptionPane.YES_OPTION)
				{
					ecrireDansFichier(fichier,phrase);
				}
				if (resu == JOptionPane.NO_OPTION)
				{
					save.showSaveDialog(this);
					File nFichier = save.getSelectedFile();
					ecrireDansFichier(nFichier,phrase);
				}
			}
		}
	}
	protected void lireFichier(File fichier)
	{
		try{
			FileInputStream is = new FileInputStream(fichier);
			InputStreamReader isr = new InputStreamReader(is,"ISO8859-15");
			BufferedReader br = new BufferedReader(isr);
			String ligne = null;
			while((ligne = br.readLine()) != null)
			{
				zoneTexte.append(ligne+"n");
			}
			br.close();
		}catch (FileNotFoundException e) {
		JOptionPane.showMessageDialog(this, "Erreur, fichier non trouvé!!!", "Erreur",JOptionPane.WARNING_MESSAGE );}
    	catch (IOException e) {JOptionPane.showMessageDialog(this, "Erreur lors de la lecture du fichier", "Erreur",JOptionPane.WARNING_MESSAGE );}
	}
	@Override
	public void actionPerformed(ActionEvent a) {
		// TODO Auto-generated method stub
		if (a.getSource() == noir)
		{
			if (zoneTexte.getBackground() == Color.black)
			{
				JOptionPane.showMessageDialog(this, "L'arrière plan est déja noir !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setBackground(Color.black);
			}	
		}
		if (a.getSource() == blanc)
		{
			if (zoneTexte.getBackground() == Color.white)
			{
				JOptionPane.showMessageDialog(this, "L'arrière plan est déja blanc !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setBackground(Color.white);
			}
		}
		if (a.getSource() == vert)
		{
			if (zoneTexte.getForeground() == Color.green)
			{
				JOptionPane.showMessageDialog(this, "Le texte est déja de couleur vert !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setForeground(Color.green);
			}
		}
		if (a.getSource() == jaune)
		{
			if (zoneTexte.getForeground() == Color.yellow)
			{
				JOptionPane.showMessageDialog(this, "Le texte est déja de couleur jaune !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setForeground(Color.yellow);
			}
		}
		if (a.getSource() == rouge)
		{
			if (zoneTexte.getForeground() == Color.red)
			{
				JOptionPane.showMessageDialog(this, "Le texte est déja de couleur rouge !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setForeground(Color.red);
			}
		}
		if (a.getSource() == gris)
		{
			if (zoneTexte.getForeground() == Color.gray)
			{
				JOptionPane.showMessageDialog(this, "Le texte est déja de couleur gris !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setForeground(Color.gray);
			}
		}
		if (a.getSource() == violet)
		{
			if (zoneTexte.getForeground() == new Color(163,64,164))
			{
				JOptionPane.showMessageDialog(this, "Le texte est déja de couleur violet !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setForeground(new Color(163,64,164));
			}
		}
		if (a.getSource() == bleu)
		{
			if (zoneTexte.getForeground() == Color.blue)
			{
				JOptionPane.showMessageDialog(this, "Le texte est déja de couleur bleu !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setForeground(Color.blue);
			}
		}
		if (a.getSource() == orange)
		{
			if (zoneTexte.getForeground() == Color.orange)
			{
				JOptionPane.showMessageDialog(this, "Le texte est déja de couleur orange !!!", "Ho lala !!!", JOptionPane.WARNING_MESSAGE);
			}
			else
			{
				zoneTexte.setForeground(Color.orange);
			}
		}
		if (a.getSource() == apropos)
		{
			JOptionPane.showOptionDialog(this,new Object[]{"Bloc Note de Tonyannick Jiste Version 1.3, tous droits réservés ",logoBlocNote,"Ne pas modifier le code source sans l'avertir par mail à l'adresse","stoneyanick@gmail.com, merci de votre compréhension"},"Á propos",JOptionPane.NO_OPTION,JOptionPane.INFORMATION_MESSAGE,null,new String[]{"ok"},null);
		}
		if (a.getSource() == arial)
		{
			zoneTexte.setFont(new Font("Arial",Font.PLAIN,12));
		}
		if (a.getSource() == tahoma)
		{
			zoneTexte.setFont(new Font("Tahoma",Font.PLAIN,12));
		}
		if (a.getSource() == century)
		{
			zoneTexte.setFont(new Font("Century",Font.PLAIN,12));
		}
		if (a.getSource() == calibri)
		{
			zoneTexte.setFont(new Font("Calibri",Font.PLAIN,12));
		}
		if (a.getSource() == garamond)
		{
			zoneTexte.setFont(new Font("Garamond",Font.TYPE1_FONT,12));
		}
		if (a.getSource() == petit)
		{
			zoneTexte.setFont(new Font("zoneTexte.getFont()",Font.PLAIN,9));
		}
		if (a.getSource() == moyen)
		{
			zoneTexte.setFont(new Font("zoneTexte.getFont()",Font.PLAIN,15));
		}
		if (a.getSource() == grand)
		{
			zoneTexte.setFont(new Font("zoneTexte.getFont()",Font.PLAIN,20));
		}
		if (a.getSource() == rechercher)
		{
			JTextField motARechercher = new JTextField();
			if (zoneTexte.getText().isEmpty())
			{
				JOptionPane.showMessageDialog(this,"La zone de texte est vide, donc il n'y rien à rechercher."," Recherche",JOptionPane.INFORMATION_MESSAGE);	
			}
			else
			{
				int choix = JOptionPane.showOptionDialog(this, new Object[]{"Tapez le motif à rechercher ",motARechercher},"Rechercher", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, logoBlocNote, new String[]{"Rechercher","Annuler"},null);
				if (choix == 0)
					{
					if (motARechercher.getText().isEmpty())
					{
						JOptionPane.showMessageDialog(this,"Aie, vous n'avez rien saisie, il faut taper taper un motif à rechercher dans la zone de texte...!!!"," Recherche",JOptionPane.INFORMATION_MESSAGE);
						do{
							 JOptionPane.showOptionDialog(this, new Object[]{"Tapez le motif à rechercher ",motARechercher},"Rechercher", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, logoBlocNote, new String[]{"Rechercher","Annuler"},null);
						  }while(motARechercher.getText().isEmpty());	
					}
					if(!motARechercher.getText().isEmpty())
					{
							Pattern motif = Pattern.compile(motARechercher.getText());
							Matcher macther = motif.matcher(zoneTexte.getText());
							while (macther.find())
							{
								Highlighter lumière = zoneTexte.getHighlighter();
								HighlightPainter colorateur = new DefaultHighlighter.DefaultHighlightPainter(Color.yellow);		
								try { 
									lumière.addHighlight(macther.start(), macther.end(), colorateur);
								}catch(BadLocationException e) {
									JOptionPane.showMessageDialog(this, "Erreur Interne","Erreur",JOptionPane.ERROR_MESSAGE);}
				            }
						}
					}
			}
		}
		if (a.getSource() == compter)
		{
			int compteur = 0;
			JTextField motACompter = new JTextField();
			if (zoneTexte.getText().isEmpty())
			{
				JOptionPane.showMessageDialog(this,"La zone de texte est vide...il n'y rien à compter."," Recherche",JOptionPane.INFORMATION_MESSAGE);	
			}
			else
			{
				int choix = JOptionPane.showOptionDialog(this, new Object[]{"Tapez le motif à compter ",motACompter},"Rechercher", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, logoBlocNote, new String[]{"Compter","Annuler"},null);
				if (choix == JOptionPane.OK_OPTION)
				{
					while (motACompter.getText().isEmpty())
					{
					 JOptionPane.showMessageDialog(this,"Aie, vous n'avez rien saisie, il faut taper taper un motif à rechercher dans la zone de texte...!!!"," Recherche",JOptionPane.INFORMATION_MESSAGE);
					 JOptionPane.showOptionDialog(this, new Object[]{"Tapez le motif à rechercher ",motACompter},"Rechercher", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, logoBlocNote, new String[]{"Rechercher","Annuler"},null);	
					
					}
					if (!motACompter.getText().isEmpty())
					{
						Pattern motif = Pattern.compile(motACompter.getText());
						Matcher macther = motif.matcher(zoneTexte.getText());
						while (macther.find())
						{
							compteur++;	
						}
						if(compteur == 0)
						{
							JOptionPane.showMessageDialog(this, "Aie, le motif : "+motACompter.getText()+" n'apparait pas!!!","Résultat",JOptionPane.INFORMATION_MESSAGE);
						}
						else
						{
							
							JOptionPane.showMessageDialog(this, "Le motif : "+motACompter.getText()+" ; Apparait "+compteur+" fois dans le texte","Résultat de la recherche", JOptionPane.INFORMATION_MESSAGE);
						}
				    }
			   }	
		 }
	 }
	if (a.getSource() == remplacer)
		{
			JTextField replace = new JTextField();
			JTextField remplacant = new JTextField();
			if (zoneTexte.getText().isEmpty())
			{
				JOptionPane.showMessageDialog(this,"La zone de texte est vide, donc il n'y rien à remplacer."," Recherche",JOptionPane.INFORMATION_MESSAGE);	
			}
			else
			{
				int choix = JOptionPane.showOptionDialog(this, new Object[]{"Tapez le motif à remplacer ",replace,"Remplacer par",remplacant},"Remplacer", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, logoBlocNote, new String[]{"Remplacer","Annuler"},null);
				if (choix == 0)
				{	
					while (replace.getText().isEmpty() || remplacant.getText().isEmpty())
					{
					 JOptionPane.showMessageDialog(this,"Aie, vous devez renseigner tous les champs...!!!"," Recherche",JOptionPane.INFORMATION_MESSAGE);
					 JOptionPane.showOptionDialog(this, new Object[]{"Tapez le motif à remplacer ",replace,"Remplacer par",remplacant},"Remplacer", JOptionPane.NO_OPTION, JOptionPane.QUESTION_MESSAGE, logoBlocNote, new String[]{"Remplacer","Annuler"},null); 
					}
					if (!replace.getText().isEmpty() && !remplacant.getText().isEmpty())
					{
						String mot = null;
						Pattern motif = Pattern.compile(replace.getText());
						Matcher macther = motif.matcher(zoneTexte.getText());
						while (macther.find())
						{
							mot = macther.replaceAll(remplacant.getText());
						}
						zoneTexte.setText(mot);
	               }
		      }
		  }
	   }
	if (a.getSource() == effacer)
		{
			int choix = JOptionPane.showConfirmDialog(this, "Voulez vous vraiment tout effacer?","Effacer le texte",JOptionPane.YES_NO_OPTION);
			if ( choix == JOptionPane.YES_OPTION)
			{
				zoneTexte.setText("");
			}	
	   }
	if (a.getSource() == ouvrir)
		{
			String contenu = zoneTexte.getText();
			if (contenu.isEmpty())
			{	
				JFileChooser choose = new JFileChooser();
				choose.setAcceptAllFileFilterUsed(true);
				int selection = choose.showOpenDialog(this);
				if (selection == JFileChooser.APPROVE_OPTION)
				{
					File fichierChoisi = choose.getSelectedFile();
					lireFichier(fichierChoisi);
			    }		
			}
			else
			{
				int res = JOptionPane.showOptionDialog(this,"La zone de  texte n'est pas vide voulez vous  : ","Hum",JOptionPane.NO_OPTION,JOptionPane.INFORMATION_MESSAGE,null,new Object[]{"Enregistrer","Continuer sans enregistrer"},null);
				if (res == 0)
				{
					enregistrerFichier(contenu);
					JFileChooser ouvre = new JFileChooser();
					ouvre.setAcceptAllFileFilterUsed(true);
					ouvre.addChoosableFileFilter(docx);
					ouvre.addChoosableFileFilter(pdf);
					ouvre.addChoosableFileFilter(texte);
					int select = ouvre.showOpenDialog(this);
					if (select == JFileChooser.APPROVE_OPTION)
					{
						zoneTexte.setText("");
						lireFichier(ouvre.getSelectedFile());
					}
					
				}
				if (res == 1)
				{
					JFileChooser ouvre = new JFileChooser();
					ouvre.setAcceptAllFileFilterUsed(true);
					ouvre.addChoosableFileFilter(docx);
					ouvre.addChoosableFileFilter(pdf);
					ouvre.addChoosableFileFilter(texte);
					int select = ouvre.showOpenDialog(this);
					if (select == JFileChooser.APPROVE_OPTION)
					{
						zoneTexte.setText("");
						lireFichier(ouvre.getSelectedFile());
					}
				}
			}
		}
		if (a.getSource() == nouveau)
		{
			String contenu = zoneTexte.getText();
			if (contenu.isEmpty())
			{
				zoneTexte.setText("");
			}
			else
			{
				int res = JOptionPane.showOptionDialog(this,"La zone de  texte n'est pas vide voulez vous  : ","Hum",JOptionPane.NO_OPTION,JOptionPane.INFORMATION_MESSAGE,null,new Object[]{"Enregistrer","Continuer sans enregistrer"},null);
				if (res == 0)
				{
					enregistrerFichier(contenu);
				}
				if (res == 1)
				{
					zoneTexte.setText("");
				}
			}
		}
		if (a.getSource() == enregistrer)
		{
			String contenu = zoneTexte.getText();
			if(contenu.isEmpty())
			{
				JOptionPane.showMessageDialog(this, "Vous n'avez rien saisi(e), donc il n'y a rien à enregistrer", "Hum", JOptionPane.INFORMATION_MESSAGE);
			}
			else
			{
				enregistrerFichier(contenu);		
			}
		 }
				
	}
	@Override
	public void windowActivated(WindowEvent a) {
		// TODO Auto-generated method stub
	}

	@Override
	public void windowClosed(WindowEvent a) {
		// TODO Auto-generated method stub
	}

	@Override
	public void windowClosing(WindowEvent a) {
		// TODO Auto-generated method stub
			if (!zoneTexte.getText().isEmpty())
				{
					int alors = JOptionPane.showOptionDialog(this,"Voulez vous enregistrer les modifications avant de quittez?","Fermeture",JOptionPane.NO_OPTION,JOptionPane.INFORMATION_MESSAGE,null,new Object[]{"enregistrer","Fermer sans enregistrer","Annuler"},null);
					if (alors == 0)
					{
						enregistrerFichier(zoneTexte.getText());
						System.exit(0);
					}
					if (alors == 1)
					{
						System.exit(0);
					}
				}
			else
			{
				System.exit(0);
			}
	}

	@Override
	public void windowDeactivated(WindowEvent a) {
		// TODO Auto-generated method stub
	}

	@Override
	public void windowDeiconified(WindowEvent a) {
		// TODO Auto-generated method stub
	}

	@Override
	public void windowIconified(WindowEvent arg0) {
		// TODO Auto-generated method stub
	}

	@Override
	public void windowOpened(WindowEvent arg0) {
		// TODO Auto-generated method stub
		
	}	
}
		

Codes Sources

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.