salut

je cherche à faire si je sélectionne une ligne de la table de la classe minooo puis clic sur le bouton tester de la classe minooo la fenêtre tester s'ouvre et affiche les valeurs de la ligne sélectionnée sur jtextfield 1 et jtextfield2 de la classe tester

je vous montre les deux classes

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
 
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
 
import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.GridBagLayout;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.Vector;
 
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import java.awt.Dimension;
import javax.swing.JButton;
 
public class minooo extends JFrame {
 
	private static final long serialVersionUID = 1L;
 
	private JPanel jContentPane = null;
 
	private JPanel jPanel = null;
 
	private JScrollPane jScrollPane = null;
 
	private JTable jTable = null;
	String nom;
	String prénom;
 
	private JButton jButton = null;
 
	/**
         * This method initializes jPanel       
         *      
         * @return javax.swing.JPanel   
         */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(13, 20, 552, 181));
			jPanel.add(getJScrollPane(), null);
			jPanel.add(getJButton(), null);
		}
		return jPanel;
	}
 
	/**
         * This method initializes jScrollPane  
         *      
         * @return javax.swing.JScrollPane      
         */
	private JScrollPane getJScrollPane() {
		if (jScrollPane == null) {
			jScrollPane = new JScrollPane();
			jScrollPane.setBounds(new Rectangle(55, 20, 190, 99));
			jScrollPane.setViewportView(getJTable());
		}
		return jScrollPane;
	}
 
	/**
         * This method initializes jTable       
         *      
         * @return javax.swing.JTable   
         */
	private JTable getJTable() {
		if (jTable == null) {
			jTable = new JTable();
			Vector columnNames = new Vector();
 
	         Vector data = new Vector();
			   Object[][] data1 = {
				       {"", "",   "","" }, {"", "" }
				   };
 
				   String[] columns1 = { "nom", "prénom"   };
 
 
	   try {
 
			 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance(); 
 
 
			 String url= "jdbc:odbc:test";
	 	 String user = "user"; 
	 String pass = "pass";
	 	Connection connection = DriverManager.getConnection (url, user, pass); 
 
	 	String sql1 = "select * client";
 
 
				   Statement instruction = connection.createStatement();
 
 
		              String sql = "select *  from client " ;
		              ResultSet resultatt = instruction.executeQuery(sql);
		              ResultSetMetaData md = resultatt.getMetaData();
		              int columns = md.getColumnCount();
 
		              //  Get column names
 
		              for (int id = 1; id < columns; id++) {
		                columnNames.addElement(md.getColumnName(id));
		              }
 
		              //  Get row data
 
		              while (resultatt.next()) {
		                Vector row = new Vector(columns);
 
		                for (int j = 1; j <= columns; j++) {
		                  row.addElement(resultatt.getObject(j));
		                }
 
		                data.addElement(row);
 
		              }
 
 
 
		              jTable = new JTable(data, columnNames);
		              System.out.println(jTable.getValueAt(0, 2));
		              jTable.setBackground(Color.green);
		              jTable.setVisible(true);
		              jTable .setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 
 
		              jTable.addMouseListener(new java.awt.event.MouseAdapter() {
		              	public void mouseClicked(java.awt.event.MouseEvent e) {
 
		              		Point p=e.getPoint(); //recup la position de la souris
		                    int row=jTable.rowAtPoint(p); //indice de la ligne a cette position
		                    int col = jTable.columnAtPoint(p); //indice colonne
		                    nom=jTable.getValueAt(row, 0).toString();
		              		 prénom=jTable.getValueAt(row, 1).toString();
 
 
 
		           	}
       });
 
	   }catch (Exception ex) {
				         		System.out.println("jjjjjjjjjjj "+ex.getMessage());
 
								  ex.printStackTrace() ;
							}
		}
		return jTable;
	}
 
	/**
         * This method initializes jButton      
         *      
         * @return javax.swing.JButton  
         */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(323, 118, 118, 45));
			jButton.setText("tester");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					 tester test= new tester();
					 test.setVisible(true);
				}
			});
		}
		return jButton;
	}
 
	/**
         * @param args
         */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				minooo thisClass = new minooo();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}
 
	/**
         * This is the default constructor
         */
	public minooo() {
		super();
		initialize();
	}
 
	/**
         * This method initializes this
         * 
         * @return void
         */
	private void initialize() {
		this.setSize(589, 247);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}
 
	/**
         * This method initializes jContentPane
         * 
         * @return javax.swing.JPanel
         */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJPanel(), null);
		}
		return jContentPane;
	}
 
}  //  @jve:decl-index=0:visual-constraint="10,10"
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
 
 
import javax.swing.SwingUtilities;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JTextField;
import java.awt.Rectangle;
import java.awt.GridBagLayout;
import javax.swing.JLabel;
 
public class tester extends JFrame {
 
	private static final long serialVersionUID = 1L;
 
	private JPanel jContentPane = null;
 
	private JPanel jPanel = null;
 
	private JTextField jTextField = null;
 
	private JLabel jLabel = null;
 
	private JLabel jLabel1 = null;
 
	private JTextField jTextField1 = null;
 
	/**
         * This method initializes jPanel       
         *      
         * @return javax.swing.JPanel   
         */
	private JPanel getJPanel() {
		if (jPanel == null) {
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(28, 64, 72, 30));
			jLabel1.setText("prénom");
			jLabel = new JLabel();
			jLabel.setBounds(new Rectangle(18, 15, 75, 42));
			jLabel.setText("nom");
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.setBounds(new Rectangle(30, 15, 222, 111));
			jPanel.add(getJTextField(), null);
			jPanel.add(jLabel, null);
			jPanel.add(jLabel1, null);
			jPanel.add(getJTextField1(), null);
		}
		return jPanel;
	}
 
	/**
         * This method initializes jTextField   
         *      
         * @return javax.swing.JTextField       
         */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(111, 15, 93, 36));
		}
		return jTextField;
	}
 
	/**
         * This method initializes jTextField1  
         *      
         * @return javax.swing.JTextField       
         */
	private JTextField getJTextField1() {
		if (jTextField1 == null) {
			jTextField1 = new JTextField();
			jTextField1.setBounds(new Rectangle(110, 62, 84, 32));
		}
		return jTextField1;
	}
 
	/**
         * @param args
         */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				tester thisClass = new tester();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}
 
	/**
         * This is the default constructor
         */
	public tester() {
		super();
		initialize();
	}
 
	/**
         * This method initializes this
         * 
         * @return void
         */
	private void initialize() {
		this.setSize(300, 200);
		this.setContentPane(getJContentPane());
		this.setTitle("JFrame");
	}
 
	/**
         * This method initializes jContentPane
         * 
         * @return javax.swing.JPanel
         */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJPanel(), null);
		}
		return jContentPane;
	}
 
}
merci d'avance