Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
1804 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Souci avec un JDialog lors d'une sauvegarde ...

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Souci avec un JDialog lors d'une sauvegarde ...

n°1375990
mikekine
Posté le 27-05-2006 à 15:28:30  profilanswer
 

Salut !
 
 
Dans le cadre d'un programme de sudoku, j'ai un souci avec les sauvegardes.
 
 

  • Dès lors qu'une partie est terminée et la grille correctement remplie, un message apparait :

http://users.skynet.be/mickcauw/Ephec/su1.JPG
 

  • Si la personne a résolu la grille dans un temps qui est parmi les 10 meilleurs, on demande son nom :

http://users.skynet.be/mickcauw/Ephec/su2.JPG
 
 
 
 
Là où se trouve mon problème, c'est que si l'utilisateur a précédement procédé à une sauvegarde (que ce soit cette partie là ou bien une autre), voilà ce que j'obtiens comme boite de dialogue :
 
http://users.skynet.be/mickcauw/Ephec/su3.JPG
 
Elle est bien là, mais il n'y plus rien dedans ...
 
 
Voici le code de ma classe Findejeu :
 

Code :
  1. public class Findejeu implements Observer,java.io.Serializable {
  2.    
  3.     private static final long serialVersionUID = -8647092533022968631L;
  4.    
  5.     private Pgrmsudoku pgrm;
  6.     Saisienom saisienom;
  7.    
  8.     public Findejeu(Pgrmsudoku pgrm){
  9.         this.pgrm = pgrm;
  10.         pgrm.getJeu().getSudomodele().addObserver(this);
  11.         saisienom = new Saisienom(pgrm, this);
  12.         saisienom.pack();
  13.     }
  14.    
  15.     public void updateObserver() {
  16.         if (pgrm.getJeu().getSudomodele().getSequencefin()==1){             
  17.             if (pgrm.getJeu().getSudomodele().isGagne()==true) {               
  18.                 JOptionPane.showMessageDialog(pgrm,"Félicitations !\nVous avez correctement rempli la grille\n","Fin du Jeu",JOptionPane.INFORMATION_MESSAGE);
  19.                 if (pgrm.getJeu().getSudomodele().isAidecalcul()==false){
  20.                     if (pgrm.getJeu().getSudomodele().isTopten()==false){
  21.                         JOptionPane.showMessageDialog(pgrm,"Désolé, vous ne figurez pas parmi les 10 meilleurs temps ...","Pas assez rapide !",JOptionPane.INFORMATION_MESSAGE);                   
  22.                     }
  23.                     else {
  24.                         saisienom.setLocationRelativeTo(pgrm);
  25.                         saisienom.setVisible(true);
  26.                         String s = saisienom.getValidatedText();
  27.                         if (s != null) {                   
  28.                             pgrm.getJeu().getSudomodele().setNomtemp(s);
  29.                         }               
  30.                     }
  31.                 }
  32.             }
  33.         }
  34.     }
  35. }

 
 
 
Voici celui de ma classe Saisienom :
 

Code :
  1. public class Saisienom extends JDialog implements ActionListener,PropertyChangeListener{
  2.    
  3.     private static final long serialVersionUID = 4566591878787558919L;
  4.    
  5.     private String typedText = null;
  6.     private JTextField textField;   
  7.     private JOptionPane optionPane;   
  8.     private String btnString1 = "OK";
  9.     private String btnString2 = "Annuler";
  10.    
  11.     public Saisienom(Pgrmsudoku pgrm, Findejeu parent) {
  12.         super(pgrm, true);   
  13.         setTitle("Identité" );       
  14.         textField = new JTextField(10);       
  15.         String msgString1 = "Veuillez entrer votre nom :";               
  16.         Object[] array = {msgString1, textField};       
  17.         Object[] options = {btnString1, btnString2};
  18.         optionPane = new JOptionPane(array,JOptionPane.QUESTION_MESSAGE,JOptionPane.YES_NO_OPTION, null, options, options[0]);
  19.         setContentPane(optionPane);   
  20.         addComponentListener(new ComponentAdapter() {
  21.             public void componentShown(ComponentEvent ce) {
  22.                 textField.requestFocusInWindow();
  23.             }
  24.         });
  25.         textField.addActionListener(this);               
  26.         optionPane.addPropertyChangeListener(this);
  27.     }   
  28.    
  29.     public String getValidatedText() {
  30.         return typedText;
  31.     }   
  32.    
  33.     public void actionPerformed(ActionEvent e) {
  34.         optionPane.setValue(btnString1);
  35.     }   
  36.    
  37.     public void propertyChange(PropertyChangeEvent e) {
  38.         int i=0;
  39.         boolean test=true;
  40.         String prop = e.getPropertyName();
  41.         if (isVisible()    && (e.getSource() == optionPane) && (JOptionPane.VALUE_PROPERTY.equals(prop) || JOptionPane.INPUT_VALUE_PROPERTY.equals(prop))) {
  42.             Object value = optionPane.getValue();           
  43.             if (value == JOptionPane.UNINITIALIZED_VALUE) {               
  44.                 return;
  45.             }
  46.             optionPane.setValue(JOptionPane.UNINITIALIZED_VALUE);           
  47.             if (btnString1.equals(value)) {
  48.                 typedText = textField.getText();
  49.                 String ucText = typedText.toUpperCase();   
  50.                 if (ucText.equals("" )) test=false;
  51.                 while (i<ucText.length() && test==true){
  52.                     if (ucText.charAt(i)<'A' || ucText.charAt(i)>'Z') test=false;
  53.                     i++;
  54.                 }               
  55.                 if (test==true) clearAndHide();
  56.                 else {                   
  57.                     textField.selectAll();
  58.                     JOptionPane.showMessageDialog(Saisienom.this, "Désolé, \" " + typedText + " \" " + "n'est pas un nom valide.\n"
  59.                             + "Réessayez ! ", "Saisie incorrecte", JOptionPane.ERROR_MESSAGE);
  60.                     typedText = null;
  61.                     textField.requestFocusInWindow();
  62.                 }
  63.             }
  64.             else {               
  65.                 typedText = "";
  66.                 clearAndHide();
  67.             }
  68.         }
  69.     }   
  70.    
  71.     public void clearAndHide() {
  72.         textField.setText(null);
  73.         setVisible(false);
  74.     }   
  75. }

 
 
 
Et enfin, celui de la classe sauvegarde :
 

Code :
  1. public void sauvegarde(){       
  2.         pgrm.getJeu().getSudomodele().setTempsinter(System.currentTimeMillis()-pgrm.getJeu().getSudomodele().getTempsdebut());           
  3.        try {
  4.             FileOutputStream fichier = new FileOutputStream("sudomi.jeu" );
  5.             ObjectOutputStream oos = new ObjectOutputStream(fichier);
  6.             oos.writeObject(pgrm.getJeu().getSudomodele());   
  7.             oos.flush();
  8.             oos.close();
  9.         }
  10.         catch (java.io.IOException e) {
  11.             e.printStackTrace();
  12.         }               
  13.     }

 
 
Est-ce que vous y comprenez qqch ?


Message édité par mikekine le 27-05-2006 à 15:53:53
mood
Publicité
Posté le 27-05-2006 à 15:28:30  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Souci avec un JDialog lors d'une sauvegarde ...

 

Sujets relatifs
IN / NOT IN sur Tris Liste -> Souci![swing] sauvegarde
[VB \ Client serveur\ Excel] Sauvegarde sur clientun tit souci de pointeur
Petit souci de suppression de repertoire en PHP....Fichier de sauvegarde c++
[RESOLU] Passer des infos d'une JDialog à une JFramesouci concepteur WinForms
HELP jdialog ou JOptionPaneaffichage, sauvegarde etc.. d'une map 2D
Plus de sujets relatifs à : Souci avec un JDialog lors d'une sauvegarde ...


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR