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

Composants Java Discussion :

JTable - Resultset - sur même page que formulaire


Sujet :

Composants Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    210
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Juin 2011
    Messages : 210
    Par défaut JTable - Resultset - sur même page que formulaire
    Bonjour,

    J'ai un Jframe dans lequel il y a un formulaire de recherche composé de JTextfield et de JCombobox. Lorsque j'appuie sur le bouton "rechercher", je souhaiterai que le résultat apparaisse dans un Jtable en dessous du formulaire (après le bouton de recherche). J'ai plusieurs essaie depuis 2 jours mais mon Jtable n'apparaît pas bien q'en faisant un system.out.println du row (ligne de résultat), la recherche est bien éxécutée. Voici mon code et merci de votre aide.

    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
    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
     
    package sentalents.apps;
     
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.table.DefaultTableModel;
     
    import java.awt.Toolkit;
     
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.JComboBox;
    import javax.swing.LayoutStyle.ComponentPlacement;
    import javax.swing.JTable;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
     
    import sentalents.db.ConnectionManager;
    import sentalents.db.ResultsSearch;
     
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import java.util.Vector;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import javax.swing.JInternalFrame;
    import javax.swing.JScrollPane;
     
    @SuppressWarnings("serial")
    public class CVtheque extends JFrame {
     
    	private JPanel contentPane;
    	private JTextField motCle;
    	private JComboBox<?> comboNiveau;
    	private JComboBox<String> comboLocal;
    	private JComboBox<String> comboPays;
    	private JComboBox<String> comboSecteur;
    	private JLabel lblPaysDeNaissance;
    	private JLabel lblSecteurDeTravail;
    	private JTable table_1;
     
     
    	public CVtheque() {
    		setIconImage(Toolkit.getDefaultToolkit().getImage(CVtheque.class.getResource("/sentalents/images/images/request.png")));
    		setResizable(false);
    		setTitle("Sentalents Apps - CVth\u00E8que");
    		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		setBounds(100, 100, 992, 633);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
     
    		JLabel lblNewLabel = new JLabel("Cette section vous permet de faire vos recherches et de trouver les candidats succeptibles de vous int\u00E9resser.");
     
    		JLabel lblMotsCls = new JLabel("Mot(s) cl\u00E9(s) :");
     
    		JLabel lblNiveauDeDiplme = new JLabel("Niveau de Dipl\u00F4me :");
     
    		JLabel lblLocalisationActuelle = new JLabel("Localisation Actuelle :");
     
    		motCle = new JTextField();
    		motCle.setColumns(10);
     
    		String[] choices = {"", "Licence - Bachelor", "Master - Master", "Doctorat - Doctorate, Ph.D."};
    		comboNiveau = new JComboBox<Object>(choices);
     
     
    		comboLocal = new JComboBox<String>();
    		localisation(comboLocal);
     
    		comboPays = new JComboBox<String>();
    		paysnaiss(comboPays);
     
    		comboSecteur = new JComboBox<String>();
    		secteurlist(comboSecteur);
     
     
    		table_1 = new JTable();
    		final String motcle = motCle.getText();
    		final Object level = comboNiveau.getSelectedItem();
    		final Object localis = comboLocal.getSelectedItem();
    		final Object pays = comboPays.getSelectedItem();
    		final Object secteur = comboSecteur.getSelectedItem();
     
    		JButton btnRechercher = new JButton("Rechercher");
    		btnRechercher.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
     
    				new ResultsSearch(motcle, level, localis, pays, secteur, table_1);
     
    			}
    		});
     
     
    		JLabel lblNewLabel_1 = new JLabel("");
    		lblNewLabel_1.setIcon(new ImageIcon(CVtheque.class.getResource("/sentalents/images/images/monitor.gif")));
     
    		lblPaysDeNaissance = new JLabel("Pays de Naissance :");
     
    		lblSecteurDeTravail = new JLabel("Secteur de Travail :");
     
    		JScrollPane scrollPane = new JScrollPane();
     
     
    		GroupLayout gl_contentPane = new GroupLayout(contentPane);
    		gl_contentPane.setHorizontalGroup(
    			gl_contentPane.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_contentPane.createSequentialGroup()
    					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addContainerGap()
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    								.addComponent(lblNewLabel)
    								.addGroup(gl_contentPane.createSequentialGroup()
    									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblMotsCls)
    											.addGap(47)
    											.addComponent(motCle, GroupLayout.PREFERRED_SIZE, 258, GroupLayout.PREFERRED_SIZE))
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblPaysDeNaissance)
    											.addGap(18)
    											.addComponent(comboPays, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblSecteurDeTravail)
    											.addGap(18)
    											.addComponent(comboSecteur, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblLocalisationActuelle)
    											.addPreferredGap(ComponentPlacement.UNRELATED)
    											.addComponent(comboLocal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblNiveauDeDiplme)
    											.addGap(18)
    											.addComponent(comboNiveau, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
    									.addPreferredGap(ComponentPlacement.RELATED, 329, Short.MAX_VALUE)
    									.addComponent(lblNewLabel_1))))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(232)
    							.addComponent(btnRechercher))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(501)
    							.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addContainerGap()
    							.addComponent(table_1, GroupLayout.PREFERRED_SIZE, 634, GroupLayout.PREFERRED_SIZE)))
    					.addContainerGap())
    		);
    		gl_contentPane.setVerticalGroup(
    			gl_contentPane.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_contentPane.createSequentialGroup()
    					.addContainerGap()
    					.addComponent(lblNewLabel)
    					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(27)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblMotsCls)
    								.addComponent(motCle, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(18)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblNiveauDeDiplme)
    								.addComponent(comboNiveau, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(18)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblLocalisationActuelle)
    								.addComponent(comboLocal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(24)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblPaysDeNaissance)
    								.addComponent(comboPays, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(24)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblSecteurDeTravail)
    								.addComponent(comboSecteur, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(12)
    							.addComponent(btnRechercher))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(18)
    							.addComponent(lblNewLabel_1)))
    					.addPreferredGap(ComponentPlacement.RELATED, 139, Short.MAX_VALUE)
    					.addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
    					.addPreferredGap(ComponentPlacement.RELATED)
    					.addComponent(table_1, GroupLayout.PREFERRED_SIZE, 313, GroupLayout.PREFERRED_SIZE))
    		);
    		contentPane.setLayout(gl_contentPane);
    	}
    /***************************************************
     * 
     * Cette partie permet d'avoir les pays dans le JComboBox
     */
    	private void localisation(JComboBox<String> Jc) {
     
    		Connection conn = ConnectionManager.getInstance().getConnection();
    		String sqloc = "SELECT CONCAT_WS(' - ',fr,en) AS world FROM pays_world ORDER BY `rowid`";
     
    		try {
     
    			Statement stmt = conn.createStatement();
    			ResultSet rs = stmt.executeQuery(sqloc);
     
     
    			while (rs.next()) {
     
    				String i = rs.getString("world");
    				Jc.addItem(i);
    				//System.out.println(i);
     
    			}
    		}
    		catch (Exception e) {
     
    			ConnectionManager.getInstance().close();
    		}
    	}
     
    	/***************************************************
             * 
             * Cette partie permet d'avoir les pays dans le JComboBox
             */
    	@SuppressWarnings({ "unchecked", "rawtypes" })
    	private void paysnaiss(JComboBox Jc) {
     
    		Connection conn = ConnectionManager.getInstance().getConnection();
    		String sqloc = "SELECT CONCAT_WS(' - ',fr,en) AS world FROM pays_world ORDER BY `rowid`";
     
    		try {
     
    			Statement stmt = conn.createStatement();
    			ResultSet rs = stmt.executeQuery(sqloc);
     
     
    			while (rs.next()) {
     
    				String i = rs.getString("world");
    				Jc.addItem(i);
    				//System.out.println(i);
     
    			}
    		}
    		catch (Exception e) {
     
    			ConnectionManager.getInstance().close();
    		}
    	}
    	/***************************************************
             * 
             * Cette partie permet d'avoir les secteurs dans le JComboBox
             */
     
    	@SuppressWarnings({ "rawtypes", "unchecked" })
    	private void secteurlist(JComboBox Jc) {
     
    		Connection conn = ConnectionManager.getInstance().getConnection();
    		String sqloc = "SELECT CONCAT_WS(' - ',secteur_fr,secteur_en) AS sector FROM secteur_en, secteur_fr WHERE secteur_en.id = secteur_fr.id ORDER BY secteur_en.id";
     
    		try {
     
    			Statement stmt = conn.createStatement();
    			ResultSet rs = stmt.executeQuery(sqloc);
     
     
    			while (rs.next()) {
     
    				String i = rs.getString("sector");
    				Jc.addItem(i);
    				//System.out.println(i);
     
    			}
    		}
    		catch (Exception e) {
     
    			ConnectionManager.getInstance().close();
    		}
    	}
    }
    Voici la fonction ResultsSearch

    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
     
    package sentalents.db;
     
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
     
    import java.util.Vector;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    //import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.TableColumn;
     
    /*import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.TableColumn;*/
     
     
    public class ResultsSearch {
     
    	public  ResultsSearch(String a, Object b, Object c, Object d, Object e, JTable t) {
    		//public ResultsSearch(String a) {
    		Connection conn = ConnectionManager.getInstance().getConnection();
    		//String sql = "SELECT id, email, nom, prenom, niveau, localisation, pays, CONCAT_WS(' ',secteur1, secteur2, secteur3) AS sector, secteur1, secteur2, secteur3, photo, titre_cv1, titre_cv2, titre_cv3, cv1, cv2, cv3, langue_cv1, langue_cv2, langue_cv3 FROM infos WHERE niveau LIKE '%"+b+"%' AND  localisation LIKE '%"+c+"%' AND pays LIKE '%"+d+"%' AND secteur1 LIKE '%"+e+"%' AND MATCH(titre_cv1) AGAINST ('"+a+"')";
    		//String sql = "SELECT id, email, nom, prenom, niveau, localisation, pays, CONCAT_WS(' ',secteur1, secteur2, secteur3) AS sector, secteur1, secteur2, secteur3, photo, titre_cv1, titre_cv2, titre_cv3, cv1, cv2, cv3, langue_cv1, langue_cv2, langue_cv3 FROM infos WHERE niveau = '"+b+"'";
    		//String sql = "SELECT * FROM infos WHERE titre_cv1 LIKE '%"+a+"%'";
    		String sql = "SELECT nom, prenom, niveau, localisation, pays, secteur1, secteur2, secteur3, photo, cv1, cv2, cv3, langue_cv1, langue_cv2, langue_cv3 FROM infos WHERE (niveau ='"+b+"' AND  localisation = '"+c+"' AND pays = '"+d+"' AND secteur1 = '"+e+"') OR CONCAT_WS(' ',titre_cv1, titre_cv2, titre_cv3) LIKE '%"+a+"%'";
     
     
    		Vector<String> columnNames = new Vector<String>();
    		Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    		/*JFrame frame = new JFrame();
    		frame.setTitle("Application");
    		JPanel panel = new JPanel();*/
     
     
    		try {
    			PreparedStatement stmt = conn.prepareStatement(sql);
    			ResultSet rs = stmt.executeQuery();
    			ResultSetMetaData metaData = rs.getMetaData();
    			int columns = metaData.getColumnCount();
     
    			//if (rs.next()) {
    			for (int i = 1; i <= columns; i++) {
    				columnNames.addElement(metaData.getColumnName(i));
     
    				if (rs.next()) {
     
    					Vector<Object> row = new Vector<Object>(columns);
     
    					for (int j = 1; j <= columns; j++) {
    						row.addElement(rs.getObject(j));
    					} data.addElement(row);
    					System.out.println(row);
    				} 
    			} 
     
     
    		} catch (Exception e1) {
    			System.err.println(e1);
    		}
     
    		t = new JTable(data, columnNames);
    		t.setSize(150, 150);
    		t.setVisible(true);
    		TableColumn column;
    		for (int i = 0; i < t.getColumnCount(); i++) {
    			column = t.getColumnModel().getColumn(i);
    			column.setMaxWidth(250);
     
    		}
     
    		//JScrollPane scrollPane = new JScrollPane(t);
    		//scrollPane.setBounds(40, 40, 100, 100);
    		//f.getContentPane().add(scrollPane); 
    		//p.add(scrollPane);
    		//p.setVisible(true);
    		//f.add(p); //adding panel to the frame
    		//f.setSize(500, 500); //setting frame size
    		//f.setVisible(true); //setting visibility true*/
     
    		ConnectionManager.getInstance().close();
     
    	}
     
    }

  2. #2
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    210
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Juin 2011
    Messages : 210
    Par défaut
    Y a-t-il quelqu'un svp ???

  3. #3
    Membre émérite Avatar de fraco
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    750
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juin 2006
    Messages : 750
    Par défaut
    Salut !

    En résumé la question serait "comment faire apparaître un jTable sur mon écran" ?

  4. #4
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2011
    Messages
    210
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Finance

    Informations forums :
    Inscription : Juin 2011
    Messages : 210
    Par défaut
    Bonjour,

    J'ai pu résoudre mon problème.
    Merci beaucoup.

    Voici le 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
    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
     
    package sentalents.apps;
     
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EmptyBorder;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.table.TableColumn;
     
    import java.awt.Toolkit;
     
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextField;
    import javax.swing.JComboBox;
    import javax.swing.LayoutStyle.ComponentPlacement;
    import javax.swing.JTable;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
     
    import sentalents.db.ConnectionManager;
    import sentalents.db.ResultsSearch;
    import sentalents.db.ResultsSearchKeywords;
     
    import java.sql.Connection;
     
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.ResultSetMetaData;
    import java.sql.Statement;
    import java.util.Vector;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.event.InputMethodListener;
    import java.awt.event.InputMethodEvent;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
     
    @SuppressWarnings("serial")
    public class CVtheque extends JFrame {
     
    	private JPanel contentPane;
    	private JTextField motCle;
    	private JComboBox<?> comboNiveau;
    	private JComboBox<String> comboLocal;
    	private JComboBox<String> comboPays;
    	private JComboBox<String> comboSecteur;
    	private JLabel lblPaysDeNaissance;
    	private JLabel lblSecteurDeTravail;
    	private JTable table_1;
     
     
    	public CVtheque() {
    		setIconImage(Toolkit.getDefaultToolkit().getImage(CVtheque.class.getResource("/sentalents/images/images/request.png")));
    		setResizable(false);
    		setTitle("Sentalents Apps - CVth\u00E8que");
    		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    		setBounds(100, 100, 918, 673);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
     
    		JLabel lblNewLabel = new JLabel("Cette section vous permet de faire vos recherches et de trouver les candidats succeptibles de vous int\u00E9resser.");
     
    		JLabel lblMotsCls = new JLabel("Mot(s) cl\u00E9(s) :");
     
    		JLabel lblNiveauDeDiplme = new JLabel("Niveau de Dipl\u00F4me :");
     
    		JLabel lblLocalisationActuelle = new JLabel("Localisation Actuelle :");
     
     
    		motCle = new JTextField();
    		motCle.setColumns(10);
     
    		String[] choices = {"", "Licence - Bachelor", "Master - Master", "Doctorat - Doctorate, Ph.D."};
    		comboNiveau = new JComboBox<Object>(choices);
     
     
    		comboLocal = new JComboBox<String>();
    		localisation(comboLocal);
     
    		comboPays = new JComboBox<String>();
    		paysnaiss(comboPays);
     
    		comboSecteur = new JComboBox<String>();
    		secteurlist(comboSecteur);
    		/*final String a = motCle.getText();
    		final Object b = comboNiveau.getSelectedItem();
    		final Object c = comboLocal.getSelectedItem();
    		final Object d = comboPays.getSelectedItem();
    		final Object e = comboSecteur.getSelectedItem();*/
     
    		final Vector<String> columnNames = new Vector<String>();
    		final Vector<Vector<Object>> data = new Vector<Vector<Object>>();
    		table_1 = new JTable();
    		contentPane.add(new JScrollPane(table_1));
     
    		JButton btnRechercher = new JButton("Rechercher");
    		btnRechercher.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
     
    				//new ResultsSearch(a, b, c, d, e, table_1, columnNames, data);
    				//new ResultsSearch(a, table_1, columnNames, data);
     
    				columnNames.removeAllElements();
    				data.removeAllElements();
     
    				Connection conn = ConnectionManager.getInstance().getConnection();
    				//String sql = "SELECT nom, prenom, niveau, localisation, pays, secteur1, secteur2, secteur3, photo, cv1, cv2, cv3, langue_cv1, langue_cv2, langue_cv3 FROM infos WHERE niveau ='"+b+"' AND  localisation = '"+c+"' AND pays = '"+d+"' AND secteur1 = '"+e+"' AND titre_cv1 LIKE '%"+a+"%'";
    				//String sql = "SELECT nom, prenom, niveau, localisation, pays FROM infos WHERE (niveau ='"+b+"' AND  localisation = '"+c+"' AND pays = '"+d+"' AND secteur1 = '"+e+"') OR CONCAT_WS(' ',titre_cv1, titre_cv2, titre_cv3) LIKE '%"+a+"%'";
    				//String sql = "SELECT nom, prenom, niveau, localisation, pays FROM infos WHERE titre_cv1 = '"+a+"' AND niveau ='"+b+"' AND  localisation = '"+c+"' AND pays = '"+d+"' AND secteur1 = '"+e+"'";
    				//String sql = "SELECT nom, prenom, niveau, localisation, pays FROM infos WHERE (niveau =? AND  localisation = ? AND pays = ? AND secteur1 = ?) OR CONCAT_WS(' ',titre_cv1, titre_cv2, titre_cv3) LIKE '%?%'";
    				//String sql = "SELECT nom, prenom, niveau, localisation, pays FROM infos WHERE niveau = '"+b+"'";
    				//String sql = "SELECT * FROM infos";
    				//String sql = "SELECT nom, prenom, niveau, localisation, pays, secteur1 FROM infos WHERE niveau LIKE '%"+b+"%' AND  localisation LIKE '%"+c+"%' AND pays LIKE '%"+d+"%' AND secteur1 LIKE '%"+e+"%' AND (MATCH (titre_cv1) AGAINST ('"+a+"' IN BOOLEAN MODE))";
    				//System.out.println(sql);
     
    				try {
    					String sql = "SELECT nom, prenom, niveau, localisation, pays, secteur1 FROM infos WHERE (niveau LIKE ? AND  localisation LIKE ? AND pays LIKE ? AND secteur1 LIKE ?) OR (MATCH (titre_cv1, titre_cv2, titre_cv3) AGAINST (? IN BOOLEAN MODE))";
    					//String sql = "SELECT nom, prenom, niveau, localisation, pays, secteur1 FROM infos WHERE MATCH (titre_cv1, titre_cv2, titre_cv3) AGAINST (?,?,?,?,? IN BOOLEAN MODE)";
    					//String sql = "SELECT nom, prenom, niveau, localisation, pays, secteur1 FROM infos WHERE titre_cv1 LIKE ?";
     
     
    					PreparedStatement stmt = conn.prepareStatement(sql);
    					stmt.setObject(1, ""+comboNiveau.getSelectedItem()+"");
    					stmt.setObject(2, ""+comboLocal.getSelectedItem()+"");
    					stmt.setObject(3, ""+comboPays.getSelectedItem()+"");
    					stmt.setObject(4, ""+comboSecteur.getSelectedItem()+"");
    					stmt.setString(5, ""+motCle.getText()+"");
     
    					ResultSet rs = stmt.executeQuery();
    					ResultSetMetaData metaData = rs.getMetaData();
     
    					int columns = metaData.getColumnCount();
     
    					for (int i = 1; i <= columns; i++) {
    						columnNames.addElement(metaData.getColumnName(i));
     
    						while (rs.next()) {
     
    							Vector<Object> row = new Vector<Object>(columns);
     
    							for (int j = 1; j <= columns; j++) {
    								row.addElement(rs.getObject(j));
    							} 
    							data.addElement(row);
    							System.out.println(row);
     
    						} 
     
    					} 
     
    				} catch (Exception e1) {
    					System.err.println(e1);
    				}
     
    				DefaultTableModel model = new DefaultTableModel(data, columnNames);
    				table_1.setModel(model);
    				ConnectionManager.getInstance().close();
     
    			}
    		});
     
    		JLabel lblNewLabel_1 = new JLabel("");
    		lblNewLabel_1.setIcon(new ImageIcon(CVtheque.class.getResource("/sentalents/images/images/monitor.gif")));
     
    		lblPaysDeNaissance = new JLabel("Pays de Naissance :");
     
    		lblSecteurDeTravail = new JLabel("Secteur de Travail :");
     
     
     
    		GroupLayout gl_contentPane = new GroupLayout(contentPane);
    		gl_contentPane.setHorizontalGroup(
    			gl_contentPane.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_contentPane.createSequentialGroup()
    					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addContainerGap()
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    								.addComponent(lblNewLabel)
    								.addGroup(gl_contentPane.createSequentialGroup()
    									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblMotsCls)
    											.addGap(47)
    											.addComponent(motCle, GroupLayout.PREFERRED_SIZE, 258, GroupLayout.PREFERRED_SIZE))
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblPaysDeNaissance)
    											.addGap(18)
    											.addComponent(comboPays, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblSecteurDeTravail)
    											.addGap(18)
    											.addComponent(comboSecteur, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblLocalisationActuelle)
    											.addPreferredGap(ComponentPlacement.UNRELATED)
    											.addComponent(comboLocal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    										.addGroup(gl_contentPane.createSequentialGroup()
    											.addComponent(lblNiveauDeDiplme)
    											.addGap(18)
    											.addComponent(comboNiveau, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
    									.addPreferredGap(ComponentPlacement.RELATED, 240, Short.MAX_VALUE)
    									.addComponent(lblNewLabel_1)
    									.addPreferredGap(ComponentPlacement.RELATED))))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(232)
    							.addComponent(btnRechercher))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addContainerGap()
    							.addComponent(table_1, GroupLayout.PREFERRED_SIZE, 689, GroupLayout.PREFERRED_SIZE)))
    					.addContainerGap(25, GroupLayout.PREFERRED_SIZE))
    		);
    		gl_contentPane.setVerticalGroup(
    			gl_contentPane.createParallelGroup(Alignment.LEADING)
    				.addGroup(gl_contentPane.createSequentialGroup()
    					.addContainerGap()
    					.addComponent(lblNewLabel)
    					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(27)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblMotsCls)
    								.addComponent(motCle, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(18)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblNiveauDeDiplme)
    								.addComponent(comboNiveau, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(18)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblLocalisationActuelle)
    								.addComponent(comboLocal, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(24)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblPaysDeNaissance)
    								.addComponent(comboPays, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(24)
    							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
    								.addComponent(lblSecteurDeTravail)
    								.addComponent(comboSecteur, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
    							.addGap(12)
    							.addComponent(btnRechercher))
    						.addGroup(gl_contentPane.createSequentialGroup()
    							.addGap(18)
    							.addComponent(lblNewLabel_1)))
    					.addPreferredGap(ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
    					.addComponent(table_1, GroupLayout.PREFERRED_SIZE, 320, GroupLayout.PREFERRED_SIZE)
    					.addContainerGap())
    		);
    		contentPane.setLayout(gl_contentPane);
    	}
    /***************************************************
     * 
     * Cette partie permet d'avoir les pays dans le JComboBox
     */
    	private void localisation(JComboBox<String> Jc) {
     
    		Connection conn = ConnectionManager.getInstance().getConnection();
    		String sqloc = "SELECT CONCAT_WS(' - ',fr,en) AS world FROM pays_world ORDER BY `rowid`";
     
    		try {
     
    			Statement stmt = conn.createStatement();
    			ResultSet rs = stmt.executeQuery(sqloc);
     
     
    			while (rs.next()) {
     
    				String i = rs.getString("world");
    				Jc.addItem(i);
    				//System.out.println(i);
     
    			}
    		}
    		catch (Exception e) {
     
    			ConnectionManager.getInstance().close();
    		}
    	}
     
    	/***************************************************
             * 
             * Cette partie permet d'avoir les pays dans le JComboBox
             */
    	@SuppressWarnings({ "unchecked", "rawtypes" })
    	private void paysnaiss(JComboBox Jc) {
     
    		Connection conn = ConnectionManager.getInstance().getConnection();
    		String sqloc = "SELECT CONCAT_WS(' - ',fr,en) AS world FROM pays_world ORDER BY `rowid`";
     
    		try {
     
    			Statement stmt = conn.createStatement();
    			ResultSet rs = stmt.executeQuery(sqloc);
     
     
    			while (rs.next()) {
     
    				String i = rs.getString("world");
    				Jc.addItem(i);
    				//System.out.println(i);
     
    			}
    		}
    		catch (Exception e) {
     
    			ConnectionManager.getInstance().close();
    		}
    	}
    	/***************************************************
             * 
             * Cette partie permet d'avoir les secteurs dans le JComboBox
             */
     
    	@SuppressWarnings({ "rawtypes", "unchecked" })
    	private void secteurlist(JComboBox Jc) {
     
    		Connection conn = ConnectionManager.getInstance().getConnection();
    		String sqloc = "SELECT CONCAT_WS(' - ',secteur_fr,secteur_en) AS sector FROM secteur_en, secteur_fr WHERE secteur_en.id = secteur_fr.id ORDER BY secteur_en.id";
     
    		try {
     
    			Statement stmt = conn.createStatement();
    			ResultSet rs = stmt.executeQuery(sqloc);
     
     
    			while (rs.next()) {
     
    				String i = rs.getString("sector");
    				Jc.addItem(i);
    				//System.out.println(i);
     
    			}
    		}
    		catch (Exception e) {
     
    			ConnectionManager.getInstance().close();
    		}
    	}
     
    }

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

Discussions similaires

  1. JTable - Resultset - sur même page que formulaire
    Par lemzo84 dans le forum Composants
    Réponses: 6
    Dernier message: 15/05/2013, 17h36
  2. Ouvrir l'iframe sur la même page que ma page principale
    Par beegees dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 02/10/2008, 17h52
  3. [footnote] Affichage du n° sur la même page que la note
    Par Panthère Bleue dans le forum Mise en forme
    Réponses: 3
    Dernier message: 19/06/2008, 15h28
  4. Réponses: 1
    Dernier message: 25/02/2008, 23h05
  5. Réponses: 1
    Dernier message: 28/10/2004, 21h27

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