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

Collection et Stream Java Discussion :

Récupérer les valeurs dans un tableau


Sujet :

Collection et Stream Java

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Août 2010
    Messages
    2
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 2
    Points : 4
    Points
    4
    Par défaut Récupérer les valeurs dans un tableau
    Bonjour , j'ai créé un tableau en Statique et j'aimerai récuperer les valeurs de mon tableau et effectuer un calcul lorsque je clique sur le bouton Go , mais je ne sais pas comment récuperer les valeurs pour l'instant . Exemple sur la ligne fonction objectif , je souhaiterai récupérer la valeur la plus grande, sois 15.

    voici mon code

    Code : 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
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.Border;
    import javax.swing.border.LineBorder;
     
    public class Main extends JFrame implements ActionListener {
     
    	// déclaration des variables pour les tableaux
    	private int k, j=0;
    	 private TextField t,t2,t3,t4,t5,t6,t7;
    	// déclaration des tableaux
    	private JTable text = new JTable(6,10);
     
    	public Main()
    	{
    		this.setSize(1000,600);
    		this.setTitle("Menus Standard");
    		this.setLayout(new FlowLayout());
     
    		Button go = new Button("Go");
    		go.addActionListener(this);
     
     
    		k=1;
    		text.setValueAt("Fonction Objectif", k, j);
    		k++;
    		text.setValueAt("encre rouge", k, j);
    		k++;
    		text.setValueAt("Encre Verte", k, j);
    		k++;
    		text.setValueAt("Encre Jaune ", k, j);
    		k++;
    		text.setValueAt("Papier", k, j);
    		k++;
    		k=0;
    		j=1;
    		text.setValueAt("x1", k, j);
    		j++;
    		text.setValueAt("x2", k, j);
    		j++;
    		text.setValueAt("x3 ", k, j);
    		j++;
    		text.setValueAt("e1", k, j);
    		j++;
    		text.setValueAt("e2", k, j);
    		j++;
    		text.setValueAt("e3", k, j);
    		j++;
    		text.setValueAt("e4", k, j);
    		j++;
    		text.setValueAt("b", k, j);
    		j++;
     
    		//ligne fonction objectif
     
    		k=1;
    		j=1;
    		text.setValueAt(10, k, j);
    		j++;
    		text.setValueAt(15, k, j);
    		j++;
    		text.setValueAt(12, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt("-B", k, j);
    		j++;
     
     
    ///////////////////////////// Ligne rouge //////////////////////////////
     
    		k=2;
    		j=1;
    		text.setValueAt(500, k, j);
    		j++;
    		text.setValueAt(400, k, j);
    		j++;
    		text.setValueAt(100, k, j);
    		j++;
    		text.setValueAt(1, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(20000, k, j);
    		j++;
    		text.setValueAt("e1", k, j);
    		j++;
     
    ///////////////////////////// Ligne Verte //////////////////////////////
     
    		k=3;
    		j=1;
    		text.setValueAt(700, k, j);
    		j++;
    		text.setValueAt(800, k, j);
    		j++;
    		text.setValueAt(500, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(1, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(18000, k, j);
    		j++;
    		text.setValueAt("e2", k, j);
    		j++;
     
    ///////////////////////////// Ligne Jaune //////////////////////////////
     
    		k=4;
    		j=1;
    		text.setValueAt(200, k, j);
    		j++;
    		text.setValueAt(350, k, j);
    		j++;
    		text.setValueAt(600, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(1, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(15000, k, j);
    		j++;
    		text.setValueAt("e3", k, j);
    		j++;
     
    ///////////////////////////// Papier //////////////////////////////
     
    		k=5;
    		j=1;
    		text.setValueAt(1100, k, j);
    		j++;
    		text.setValueAt(1000, k, j);
    		j++;
    		text.setValueAt(1500, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(0, k, j);
    		j++;
    		text.setValueAt(1, k, j);
    		j++;
    		text.setValueAt(50000, k, j);
    		j++;
    		text.setValueAt("e4", k, j);
    		j++;
     
    		for(j=1;j<13; j++){
     
    			Border bordure = new LineBorder(Color.DARK_GRAY);
    		    text.setBorder(bordure);
    			text.getTableHeader().setBorder(bordure);
    		    text.getColumnModel().getColumn(0).setPreferredWidth(160);
    		    text.getColumnModel().getColumn(1).setPreferredWidth(86);
    		    text.getColumnModel().getColumn(2).setPreferredWidth(86);
    		    text.getColumnModel().getColumn(3).setPreferredWidth(86);
    		    text.getColumnModel().getColumn(4).setPreferredWidth(86);
    		    text.getColumnModel().getColumn(5).setPreferredWidth(86);
    		    text.getColumnModel().getColumn(6).setPreferredWidth(86);
    		    text.getColumnModel().getColumn(7).setPreferredWidth(86);
    		    text.getColumnModel().getColumn(8).setPreferredWidth(86);
    		    text.getColumnModel().getColumn(9).setPreferredWidth(86);
     
    		}
     
    /*
     
    		Label l1 = new Label("Produit 1");
    		Label l2 = new Label("Produit 2");
    		Label l3 = new Label("Produit 3");
    		Label l4 = new Label("Variable 1");
    		Label l5 = new Label("Variable 2");
    		Label l6 = new Label("Variable 3");
    		Label l7 = new Label("Variable 4");
     
    		t = new TextField(6);
    		t2 = new TextField(6);
    		t3 = new TextField(6);
    		t4 = new TextField(6);
    		t5 = new TextField(6);
    		t6 = new TextField(6);
    		t7 = new TextField(1);
    		String saisi = t.getText(); 
     
    		*/
    		this.add(text);
    	/*	add(l1);
    		add(t);
    		add(l2);
    		add(t2);
    		add(l3);
    		add(t3);
    		add(l4);
    		add(t4);
    		add(l5);
    		add(t5);
    		add(l6);
    		add(t6);
    		add(l7);
    		add(t7);
    		*/this.add(go);
     
    		addWindowListener(new Fermer());
    		setVisible(true);	
    	}
     
    	public void actionPerformed(ActionEvent e){
     
    		if((e.getActionCommand()).equals("Go")){
    /////////////////////Calcul avec l'algorithme //////////////////////////
     
    			Label test = new Label("\n le resultat est :");
     
    		}
    	}
    	public static void main(String[] args)
    	{
    		new Main();	
    	}
    }



    Merci beaucoup

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Mai 2009
    Messages
    106
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 106
    Points : 121
    Points
    121
    Par défaut
    Tu dois créer un model pour ta JTable dans lequel tu stockes tes valeurs sous la forme d'un tableau. Cette classe doit étendre AbstractTableModel (ça devrait suffire dans ton cas).

    Pour plus d'informations, je t'invite à lire ceci:

    http://download.oracle.com/javase/tu...able.html#data

    ou bien jeter un oeil dans les tutoriels du site de developpez

Discussions similaires

  1. Réponses: 2
    Dernier message: 28/02/2012, 09h38
  2. Problème récupérer les valeurs dans une Hash
    Par pymouse dans le forum Langage
    Réponses: 4
    Dernier message: 12/07/2007, 17h11
  3. récupérer les valeurs dans recordset
    Par aba_tarn dans le forum VBA Access
    Réponses: 8
    Dernier message: 20/06/2007, 18h49
  4. mettre les valeurs dans une tableau
    Par monphp dans le forum VB.NET
    Réponses: 1
    Dernier message: 01/06/2007, 16h51
  5. Récupérer les valeurs dans une fonction
    Par matmay dans le forum MATLAB
    Réponses: 3
    Dernier message: 04/05/2007, 16h50

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