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
| public class box extends javax.swing.JPanel {
/**
* Creates new form box
*/
public box() {
initComponents();
JTextField text = (JTextField) j.getEditor().getEditorComponent();
text.getDocument().addDocumentListener(new DocumentListener() {
public void insertUpdate(DocumentEvent documentEvent) {
updateInputText();
}
public void removeUpdate(DocumentEvent documentEvent) {
updateInputText();
}
public void changedUpdate(DocumentEvent documentEvent) {
updateInputText();
}
private void updateInputText() {
ArrayList a;
a= new ArrayList<String>();
ArrayList f;
f= new ArrayList<String>();
try {
String query =null;
String q =null;
String q1 =null;
String UrlBase = "jdbc:postgresql://localhost/gestion du cms";
String driver="org.postgresql.Driver";
String user = "postgres";
String MDP="*****";
try {
Class.forName("org.postgresql.Driver");
} catch (ClassNotFoundException ex) {
}
Connection conn = DriverManager.getConnection(UrlBase, user, MDP);
Statement state = conn.createStatement();
q =("SELECT nom,prenom,codepatient FROM patientsportif WHERE nom LIKE '"+(((JTextField)box.this.j.getEditor().getEditorComponent()).getText())+"%'");
ResultSet result = state.executeQuery(q );
ResultSetMetaData resultMeta = result.getMetaData();
while(result.next()){
for(int i = 1; i <= resultMeta.getColumnCount(); i++)
a.add(result.getObject(i).toString());
}
for(int i = 0; i <a.size(); i=i+3){
f.add(a.get(i)+" "+a.get(i+1)+" "+a.get(i+2));
}
box.this.j.setModel(new javax.swing.DefaultComboBoxModel(f.toArray()));
result.close();
state.close();
} catch (Exception e) {
e.printStackTrace();
}
box.this.j.setPopupVisible(true); }
});
j.addItemListener(null);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
j = new javax.swing.JComboBox();
l = new javax.swing.JLabel();
setBackground(new java.awt.Color(255, 255, 255));
jLabel1.setText("Nom et prénom ");
j.setEditable(true);
j.setToolTipText("");
j.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
jItemStateChanged(evt);
}
});
j.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(86, 86, 86)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(j, javax.swing.GroupLayout.PREFERRED_SIZE, 258, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
.addComponent(l, javax.swing.GroupLayout.PREFERRED_SIZE, 298, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(73, 73, 73)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(j, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(87, 87, 87)
.addComponent(l, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(92, Short.MAX_VALUE))
);
}// </editor-fold>
private void jActionPerformed(java.awt.event.ActionEvent evt) {
String s;
s=(String) j.getSelectedItem;
l.setText("voici le nom selectionné: "+s);
} |
Partager