IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Agents de placement/Fenêtres Java Discussion :

Double JFrame et enregistrer des String dans un fichier .txt


Sujet :

Agents de placement/Fenêtres Java

  1. #1
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2014
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Polynésie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2014
    Messages : 48
    Points : 62
    Points
    62
    Par défaut Double JFrame et enregistrer des String dans un fichier .txt
    Bonjours. J'ai deux problèmes.
    Le premier, je n'arrive pas/ je vois pas comment empêcher l'ouverture d'une deuxième JFrame lorsque j'appuie sur le MenuItem enregistrer.
    Le deuxième c'est que lorsque j’appuie sur enregistrer je n'ai pas ce que je souhaite, c'est à dire récupérer les donner (String) entrer dans les JTextfield.

    Ligne 404

    voici le code:
    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
     
    package Fichier;
     
    import java.awt.Color;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
     
    import javax.swing.JButton;
    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.JTextField;
     
    public class GestClientUI extends JFrame implements ActionListener, MouseListener
    {
     
    	private static final long serialVersionUID = 1L;
     
    	String nom,prenom,adreese1,code_postal,ville,pays,tel,mel; 
     
    	private JFrame jframe;
    	private JMenu fichier;
    	private JMenuBar jmenubar;
    	private JMenuItem ouvrir,fermer,nouveau,enregistrer,quitter ;
    	private JMenuItem premier,dernier,millieu,suivant,precedant,numero;
    	private JLabel label_nom,label_prenom,label_adresse,label_code,label_ville,label_pays,label_tel,label_mail;
    	JTextField text_nom,text_prenom,text_adresse,text_code,text_ville,text_pays,text_tel,text_mail;
    	private JButton button_premier,button_precedant,button_millieu,button_suivant,button_dernier;
     
     
    	GestClientUI()
    	{
    				//JFrame
    				jframe = new JFrame();
    				jframe.setTitle("Fiche client");
    				jframe.setSize(500,500);
    				jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
    				//Menubar
    				jmenubar= new JMenuBar();
    				jframe.setJMenuBar(jmenubar);
     
    				//Menu Fichier
    				fichier = new JMenu("Fichier");
    				jmenubar.add(fichier);
     
    				ouvrir      = new JMenuItem("ouvrir")     ;
    				fermer      = new JMenuItem("fermer")     ;
    				nouveau     = new JMenuItem("nouveau")    ;
    				enregistrer = new JMenuItem("enregistrer");
    				quitter     = new JMenuItem("quitter")    ;
     
    				fichier.add(ouvrir)     ;
    				fichier.add(fermer)     ;
    				fichier.add(nouveau)    ;
    				fichier.add(enregistrer);
    				fichier.add(quitter)    ;
     
    				ouvrir.addActionListener(this);
    				fermer.addActionListener(this);
    				nouveau.addActionListener(this);
    				enregistrer.addActionListener(this);
    				quitter.addActionListener(this);
     
    				//Menu Client
    				JMenu client = new JMenu("Client");
    				jmenubar.add(client);
     
    				premier   = new JMenuItem("premier")  ;
    				dernier   = new JMenuItem("dernier")  ;
    				millieu   = new JMenuItem("millieu")  ;
    				suivant   = new JMenuItem("suivant")  ;
    				precedant = new JMenuItem("precedant");
    				numero    = new JMenuItem("numero")   ;
     
    				client.add(premier)  ;
    				client.add(dernier)  ;
    				client.add(millieu)  ;
    				client.add(suivant)  ;
    				client.add(precedant);
    				client.add(numero)   ;
     
    				premier.addActionListener(this);
    				dernier.addActionListener(this);
    				millieu.addActionListener(this);
    				suivant.addActionListener(this);
    				precedant.addActionListener(this);
    				numero.addActionListener(this);
     
    				mon_paneau();
     
    	}
     
     
    	public void mon_paneau()
    	{
    		label_nom     = new JLabel("Nom:")          ;
    		label_prenom  = new JLabel("Prenom:")       ;
    		label_adresse = new JLabel("Adresse (rue):");
    		label_code    = new JLabel("Code Postal:")  ;
    		label_ville   = new JLabel("Ville:")        ;
    		label_pays    = new JLabel("Pays:")         ;
    		label_tel     = new JLabel("Tel:")          ;
    		label_mail    = new JLabel("Mail:")         ;
     
    		text_nom     = new JTextField();
    		text_prenom  = new JTextField();
    		text_adresse = new JTextField();
    		text_code    = new JTextField();
    		text_ville   = new JTextField();
    		text_pays    = new JTextField();
    		text_tel     = new JTextField();
    		text_mail    = new JTextField();
     
    		button_premier   = new JButton("<<");
    		button_precedant = new JButton("<");
    		button_millieu   = new JButton("[...]");
    		button_suivant   = new JButton(">");
    		button_dernier   = new JButton(">>");
     
    		button_premier.addActionListener(this);
    		button_precedant.addActionListener(this);
    		button_millieu.addActionListener(this);
    		button_suivant.addActionListener(this);
    		button_dernier.addActionListener(this);
     
    		//Jpanel
     
    		JPanel panel = new JPanel();
    		panel.setBackground(Color.yellow);
    		jframe.setContentPane(panel);
     
    		panel.setLayout(new GridBagLayout());
     
    		//definition taille des bouttons
    		//okButton.setPreferredSize(cancelButton.getPreferredSize());
    		//okButton.setMinimumSize(cancelButton.getMinimumSize());
     
     
    		GridBagConstraints gbc = new GridBagConstraints();
     
     
    		gbc.gridx = 0;
    		gbc.gridy = 0;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		panel.add(label_nom,gbc);
     
    		gbc.gridx = 1;
    		gbc.gridy = 0; 
    		gbc.gridwidth = GridBagConstraints.REMAINDER; 
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.HORIZONTAL;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(0, 15, 0, 10);
    		panel.add(text_nom,gbc);
     
     
    		gbc.gridx = 0;
    		gbc.gridy = 1;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		panel.add(label_prenom,gbc);
     
    		gbc.gridx = 1;
    		gbc.gridy = 1; 
    		gbc.gridwidth = GridBagConstraints.REMAINDER; 
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.HORIZONTAL;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(0, 15, 0, 10);
    		panel.add(text_prenom,gbc);
     
    		gbc.gridx = 0;
    		gbc.gridy = 2;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		panel.add(label_adresse,gbc);
     
    		gbc.gridx = 1;
    		gbc.gridy = 2; 
    		gbc.gridwidth = GridBagConstraints.REMAINDER; 
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.HORIZONTAL;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(0, 15, 0, 10);
    		panel.add(text_adresse,gbc);
     
    		gbc.gridx = 0;
    		gbc.gridy = 3;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		panel.add(label_code,gbc);
     
    		gbc.gridx = 1;
    		gbc.gridy = 3; 
    		gbc.gridwidth = GridBagConstraints.REMAINDER; 
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.HORIZONTAL;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(0, 15, 0, 10);
    		panel.add(text_code,gbc);	
     
    		gbc.gridx = 0;
    		gbc.gridy = 4;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		panel.add(label_ville,gbc);
     
    		gbc.gridx = 1;
    		gbc.gridy = 4; 
    		gbc.gridwidth = GridBagConstraints.REMAINDER; 
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.HORIZONTAL;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(0, 15, 0, 10);
    		panel.add(text_ville,gbc);
     
    		gbc.gridx = 0;
    		gbc.gridy = 5;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		panel.add(label_pays,gbc);
     
    		gbc.gridx = 1;
    		gbc.gridy = 5; 
    		gbc.gridwidth = GridBagConstraints.REMAINDER; 
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.HORIZONTAL;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(0, 15, 0, 10);
    		panel.add(text_pays,gbc);
     
    		gbc.gridx = 0;
    		gbc.gridy = 6;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		panel.add(label_tel,gbc);
     
    		gbc.gridx = 1;
    		gbc.gridy = 6; 
    		gbc.gridwidth = GridBagConstraints.REMAINDER; 
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.HORIZONTAL;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(0, 15, 0, 10);
    		panel.add(text_tel,gbc);
     
    		gbc.gridx = 0;
    		gbc.gridy = 7;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.insets = new Insets(10, 15, 0, 0);
    		panel.add(label_mail,gbc);
     
    		gbc.gridx = 1;
    		gbc.gridy = 7; 
    		gbc.gridwidth = GridBagConstraints.REMAINDER; 
    		gbc.gridheight = 1;
    		gbc.fill = GridBagConstraints.HORIZONTAL;
    		gbc.anchor = GridBagConstraints.BASELINE;
    		gbc.insets = new Insets(0, 15, 0, 10);
    		panel.add(text_mail,gbc);
     
    		gbc.gridx = 1; 
    		gbc.gridy = 8; 
    		gbc.weightx = 0.5;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.insets = new Insets(10, 15, 10, 10);
    		panel.add(button_premier, gbc);
     
    		gbc.gridx = 2; 
    		gbc.gridy = 8; 
    		gbc.weightx = 0.5;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.insets = new Insets(10, 15, 10, 10);
    		panel.add(button_precedant, gbc);
     
    		gbc.gridx = 3; 
    		gbc.gridy = 8; 
    		gbc.weightx = 0.5;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.insets = new Insets(10, 15, 10, 10);
    		panel.add(button_millieu, gbc);
     
    		gbc.gridx = 4; 
    		gbc.gridy = 8; 
    		gbc.weightx = 0.5;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.insets = new Insets(10, 15, 10, 10);
    		panel.add(button_suivant, gbc);
     
    		gbc.gridx = 5; 
    		gbc.gridy = 8; 
    		gbc.weightx = 0.5;
    		gbc.gridwidth = 1;
    		gbc.gridheight = 1;
    		gbc.anchor = GridBagConstraints.BASELINE_LEADING;
    		gbc.fill = GridBagConstraints.NONE;
    		gbc.insets = new Insets(10, 15, 10, 10);
    		gbc.insets = new Insets(10, 15, 10, 10);
    		panel.add(button_dernier, gbc);
     
    		jframe.setVisible(true);	
    	}
     
    	public static void main(String[] args)
    	{
    		new GestClientUI();
    	}
     
    	@Override
    	public void mouseClicked(MouseEvent e) 
    	{
     
    	}
     
    	@Override
    	public void mouseEntered(MouseEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void mouseExited(MouseEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void mousePressed(MouseEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void mouseReleased(MouseEvent arg0) {
    		// TODO Auto-generated method stub
     
    	}
     
    	@Override
    	public void actionPerformed(ActionEvent e) 
    	{
    		Object source = e.getSource();
     
    		if(source == ouvrir)
    		{
     
    		}
     
    		else if(source == fermer)
    		{
     
    		}
     
    		else if(source == nouveau)
    		{
    			mon_paneau();
    		}
     
    		else if(source == enregistrer)
    		{
    			NavigatorClientFic client = new NavigatorClientFic();
    			client.fiche_client_sauvegarder();
    		}
     
    		else if(source == quitter)
    		{
    			System.exit(0);
    		}
     
    		else if(source == premier || source == button_premier)
    		{
     
    		}
     
    		else if(source == dernier || source == button_dernier)
    		{
     
    		}
     
    		else if(source == millieu || source == button_millieu)
    		{
     
    		}
     
    		else if(source == suivant || source == button_suivant)
    		{
     
    		}
     
    		else if(source == precedant || source == button_precedant )
    		{
     
    		}
     
    		else if(source == numero)
    		{
     
    		}
     
    	}
    }

    la deuxième classe

    Code Java : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    package Fichier;
     
    import java.io.BufferedOutputStream;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
     
    public class NavigatorClientFic extends GestClientUI 
    {
     
    	private static final long serialVersionUID = 1L;
     
    	String nom,prenom,adresse,code,ville,pays,tel,mail; 
     
    	public void fiche_client_sauvegarder()
    	{	
    		ArrayList<String> les_clients = new ArrayList<String>();
     
    		nom     = text_nom.getText();
    		prenom  = text_prenom.getText();
    		adresse = text_adresse.getText();
    		code    = text_code.getText();
    		ville   = text_ville.getText();
    		pays    = text_pays.getText();
    		tel     = text_tel.getText();
    		mail    = text_mail.getText();
     
    		les_clients.add(nom);
    		les_clients.add(prenom);
    		les_clients.add(adresse);
    		les_clients.add(code);
    		les_clients.add(ville);
    		les_clients.add(pays);
    		les_clients.add(tel);
    		les_clients.add(mail);
     
     
    	    ObjectOutputStream oos;
     
    	    try 
    	    {
    				oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(new File("FicheClient.txt"))));
     
    			    for(int i = 0; i < les_clients.size(); i++)
    			    {
    			    	oos.writeObject(les_clients.get(i));
    			    }
     
    				oos.close();
     
    	    }
     
        	catch (FileNotFoundException e)
    	    {
    	      e.printStackTrace();
    	    } 
     
    	    catch (IOException e)
    	    {
    	      e.printStackTrace();
    	    }     	
     
        }
    	/*
    	public void fiche_client_afficher()
    	{	
    	    ObjectInputStream ois;
     
    		ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream(new File("FicheClient.txt"))));
     
    		try 
    		{
    			System.out.println(((Game)ois.readObject()).toString());
    			System.out.println(((Game)ois.readObject()).toString());
    			System.out.println(((Game)ois.readObject()).toString());
    		}
     
    		catch (ClassNotFoundException e)
    		{
    			e.printStackTrace();
    		}
     
    		ois.close();     	
    	}*/
     
    }

    Merci d'avance.

  2. #2
    Modérateur
    Avatar de joel.drigo
    Homme Profil pro
    Ingénieur R&D - Développeur Java
    Inscrit en
    Septembre 2009
    Messages
    12 430
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 54
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Ingénieur R&D - Développeur Java
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2009
    Messages : 12 430
    Points : 29 131
    Points
    29 131
    Billets dans le blog
    2
    Par défaut
    Salut,

    Ta classe NavigatorClientFic étend GestClientUI qui étend une JFrame, et dont l'ouverture est faite dans son constructeur, donc c'est normal que tu aies une seconde JFrame qui s'ouvre lorsque tu instancies NavigatorClientFic (son constructeur appelle le constructeur de sa classe parente). Et c'est normal que tu ne récupères pas les valeurs des champs de ta fenêtre d'origine, parce que ça récupère les valeurs dans les champs de la seconde frame, qui n'est pas la première.

    Pas besoin que NavigatorClientFic étende GestClientUI, si ce n'est pas une frame. Ensuite, il faut transmettre à la méthode fiche_client_sauvegarder de quoi lui permettre d'accèder aux champs contenus dans GestClientUI. Comme tes 2 classes sont dans le même package, NavigatorClientFic peut accèder aux variables private de GestClientUI (ce ne sera pas toujours le cas, et il vaudrait mieux que la collecte de données soit faite dans GestClientUI dans une classe dédiée (une classe avec des setters et des getters pour chaque propriété, qui représente ton objet à sauvegarder, ou charger, ou faire autre chose...) et transmise à la méthode de sauvegarder pour le cas général), donc pour faire simple tu peux écrire :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    public class NavigatorClientFic /* j'ai commenté pour l'exemple, mais tu peux supprimer cette partie : extends GestClientUI*/{
     
    	private static final long serialVersionUID = 1L;
     
    	String nom,prenom,adresse,code,ville,pays,tel,mail; 
     
    	public void fiche_client_sauvegarder(GestClientUI frame) {	
    		ArrayList<String> les_clients = new ArrayList<String>();
     
    		nom     = frame.text_nom.getText();
    		prenom  = frame.text_prenom.getText();
     
                    ...
    Et modifier le code d'appel, pour passer l'instance de GestClientUI :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    ...
    else if(source == enregistrer) {
        NavigatorClientFic client = new NavigatorClientFic();
        client.fiche_client_sauvegarder(this);
    }
    ...
    Par ailleurs, je te déconseille d'utiliser ObjectOutputStream pour stocker tes data : cette classe est plutôt prévu pour la sérialisation d'instances de classe. Elle pose le problème de gestion de compatibilité de version et tu risques de ne plus pouvoir charger facilement des données sauvegardées. Utilises soit un format portable indépendant (genre XML), soit un simple fichier properties (voir classe Properties), ou un fichier binaire portable (avec la classe DataOutputStream), ou une base de données, etc...
    L'expression "ça marche pas" ne veut rien dire. Indiquez l'erreur, et/ou les comportements attendus et obtenus, et donnez un Exemple Complet Minimal qui permet de reproduire le problème.
    La plupart des réponses à vos questions sont déjà dans les FAQs ou les Tutoriels, ou peut-être dans une autre discussion : utilisez la recherche interne.
    Des questions sur Java : consultez le Forum Java. Des questions sur l'EDI Eclipse ou la plateforme Eclipse RCP : consultez le Forum Eclipse.
    Une question correctement posée et rédigée et vous aurez plus de chances de réponses adaptées et rapides.
    N'oubliez pas de mettre vos extraits de code entre balises CODE (Voir Mode d'emploi de l'éditeur de messages).
    Nouveau sur le forum ? Consultez Les Règles du Club.

  3. #3
    Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2014
    Messages
    48
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Polynésie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Août 2014
    Messages : 48
    Points : 62
    Points
    62
    Par défaut
    Super, merci une fois de plus !
    Pour les geters et les seters l'idée m'a traversé l'esprit, mais j'ai voulu faire mon feignant... Mais merci, vraiment.

    Bonne journée cordialement.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Enregistrement des coordonnées dans un fichier txt
    Par nanouchg dans le forum Images
    Réponses: 6
    Dernier message: 11/01/2011, 14h16
  2. Réponses: 6
    Dernier message: 05/02/2008, 22h52
  3. Enregistrer un string dans un fichier txt
    Par florent64 dans le forum MATLAB
    Réponses: 4
    Dernier message: 08/06/2007, 21h27
  4. [VB6]enregistrer des données dans un fichier
    Par tchinette42 dans le forum VB 6 et antérieur
    Réponses: 6
    Dernier message: 19/04/2006, 18h55
  5. Comment enregistrer une string dans un fichier
    Par Dnx dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 23/09/2005, 14h52

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo