public class cttitem {
private String Categorie = null;
private String Nom = null;
private String Prenom = null;
private String Adresse = null;
private String CodePostal = null;
private String Pays = null;
private String Ville = null;
private String DateDeNaissance = null;
private String Telephone = null;
private String Mobile = null;
public cttitem(String categorie, String nom, String prenom, String adresse, String codepostal, String pays, String ville, String datedenaissance,
String telephone, String mobile) {
Categorie = categorie;
Nom = nom;
Prenom = prenom;
Adresse = adresse;
CodePostal = codepostal;
Pays = pays;
Ville = ville;
DateDeNaissance = datedenaissance;
Telephone = telephone;
Mobile = mobile;
}
public String getCategorie() {
return Categorie;
}
public String getNom() {
return Nom;
}
public String getPrenom(){
return Prenom;
}
public String getAdresse(){
return Adresse;
}
public String getCodePostal(){
return CodePostal;
}
public String getPays(){
return Pays;
}
public String getVille(){
return Ville;
}
public String getDateDeNaissance(){
return DateDeNaissance;
}
public String getTelephone(){
return Telephone;
}
public String getMobile(){
return Mobile;
}
public String SQLwhere(){
return "SELECT * FROM carnet where Nom='"+Nom+"' and Prenom='"+Prenom+"'";
//Quand que le programme affiche bien la personne sélectionné par Nom et Prénom
}
public String toString() {
return Nom+" "+Prenom;
}
}
Création d’un Item
pour la
Combo Box
import java.util.*;
import java.sql.*;
public class cttlist {
private Vector v = null; //Création d’un Vector ( collectionneur d’information )
boolean Reussite = false;
public cttlist() {
v = new Vector();
//Connexion a la basse
Connection connection = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
DriverManager.registerDriver(new com.microsoft.jdbc.sqlserver.SQLServerDriver());
}
catch (Exception E) {
System.out.println("Unable to load driver.");
return;
}
try {
connection = DriverManager.getConnection(
"jdbc:microsoft:sqlserver://localhost:1433;user=sa;password=;DatabaseName=Carnet_dadresses");
}
catch (Exception E) {
System.out.println("Unable to connect.");
System.out.println(E.getMessage());
return;
}
try {
Statement Stmt = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE );
ResultSet RS = Stmt.executeQuery( "SELECT * from carnet ORDER BY Prenom");
while (RS.next()) {
v.add(new cttitem(RS.getString("Categorie"),RS.getString("Nom"), RS.getString("Prenom"),RS.getString("Adresse"),
RS.getString("CodePostal"),RS.getString("Pays"),RS.getString("Ville"),RS.getString("DateDeNaissance"),
RS.getString("Telephone"),RS.getString("Mobile")));
}
RS.close();
Stmt.close();
}
catch (Exception E) {
System.out.println("Unable to query.");
System.out.println(E.getMessage());
return;
}
try {
connection.close();
}
catch (Exception E) {
System.out.println("Unable to connect.");
System.out.println(E.getMessage());
return;
}
Reussite = true;
}
public Vector getVector() {
return v;
}
//test du programme
public static void main(String[] args) {
cttlist ctt = new cttlist();
for( Iterator it= ctt.getVector().iterator(); it.hasNext(); ) {
cttitem i = (cttitem) it.next();
// i.setAffichage( 1);
System.out.println( i.getNom()+", "+i.toString());
}
}
}
Création d’une Liste
import java.sql.*;
public class carnet extends javax.swing.JFrame {
private cttlist ctt = null;
public carnet() {
ctt = new cttlist();
initComponents();
}
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
jLabel11 = new javax.swing.JLabel();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jTextField3 = new javax.swing.JTextField();
jTextField4 = new javax.swing.JTextField();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jTextField9 = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel12 = new javax.swing.JLabel();
jTextField10 = new javax.swing.JTextField();
jButton2 = new javax.swing.JButton();
jComboBox1 = new javax.swing.JComboBox();
jButton3 = new javax.swing.JButton();
getContentPane().setLayout(null);
setTitle("Carnet d'adresse");
setBackground(new java.awt.Color(255, 255, 255));
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
setIconImage(getIconImage());
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowActivated(java.awt.event.WindowEvent evt) {
formWindowActivated(evt);
}
public void windowClosing(java.awt.event.WindowEvent evt) {
exitForm(evt);
}
});
getAccessibleContext().setAccessibleDescription("");
jLabel1.setFont(new java.awt.Font("Comic Sans MS", 1, 13));
jLabel1.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\baar\\Mes documents\\Mes images\\avatar\\panda\\panda3.gif"));
jLabel1.setText("Carnet d'adresse");
getContentPane().add(jLabel1);
jLabel1.setBounds(90, 0, 250, 102);
jLabel2.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel2.setText("Categorie :");
getContentPane().add(jLabel2);
jLabel2.setBounds(40, 110, 70, 19);
jLabel3.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel3.setText("Nom :");
getContentPane().add(jLabel3);
jLabel3.setBounds(40, 150, 40, 19);
jLabel4.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel4.setText("Pr\u00e9nom :");
getContentPane().add(jLabel4);
jLabel4.setBounds(290, 150, 51, 19);
jLabel5.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel5.setText("Adresse :");
getContentPane().add(jLabel5);
jLabel5.setBounds(40, 190, 57, 19);
jLabel6.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel6.setText("Code Postale :");
getContentPane().add(jLabel6);
jLabel6.setBounds(40, 220, 90, 19);
jLabel7.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel7.setText(" Ville :");
getContentPane().add(jLabel7);
jLabel7.setBounds(40, 260, 39, 19);
jLabel8.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel8.setText("Pays :");
getContentPane().add(jLabel8);
jLabel8.setBounds(290, 220, 35, 19);
jLabel9.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel9.setText("T\u00e9l\u00e9phone Maison :");
getContentPane().add(jLabel9);
jLabel9.setBounds(40, 300, 116, 19);
jLabel10.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel10.setText("Mobile :");
getContentPane().add(jLabel10);
jLabel10.setBounds(290, 300, 49, 19);
jLabel11.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jLabel11.setText("Date de Naissance :");
getContentPane().add(jLabel11);
jLabel11.setBounds(290, 260, 120, 19);
jTextField1.setBorder(null);
jTextField1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField1ActionPerformed(evt);
}
});
jTextField1.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField1FocusLost(evt);
}
});
getContentPane().add(jTextField1);
jTextField1.setBounds(104, 110, 180, 18);
jTextField2.setBorder(null);
jTextField2.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField2FocusLost(evt);
}
});
getContentPane().add(jTextField2);
jTextField2.setBounds(74, 150, 210, 18);
jTextField3.setBorder(null);
getContentPane().add(jTextField3);
jTextField3.setBounds(350, 150, 190, 18);
jTextField4.setBorder(null);
getContentPane().add(jTextField4);
jTextField4.setBounds(100, 190, 440, 20);
jTextField5.setBorder(null);
getContentPane().add(jTextField5);
jTextField5.setBounds(130, 220, 150, 18);
jTextField6.setBorder(null);
getContentPane().add(jTextField6);
jTextField6.setBounds(80, 260, 200, 18);
jTextField7.setBorder(null);
jTextField7.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusLost(java.awt.event.FocusEvent evt) {
jTextField7FocusLost(evt);
}
});
getContentPane().add(jTextField7);
jTextField7.setBounds(330, 220, 210, 18);
jTextField8.setBorder(null);
jTextField8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField8ActionPerformed(evt);
}
});
getContentPane().add(jTextField8);
jTextField8.setBounds(160, 300, 120, 18);
jTextField9.setBorder(null);
getContentPane().add(jTextField9);
jTextField9.setBounds(340, 300, 200, 18);
jButton1.setFont(new java.awt.Font("Comic Sans MS", 0, 13));
jButton1.setText("Good to Go");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
getContentPane().add(jButton1);
jButton1.setBounds(180, 340, 110, 27);
jLabel12.setText("Votre categori (Ami(e), Famille, ou Autre.");
getContentPane().add(jLabel12);
jLabel12.setBounds(290, 110, 250, 18);
jTextField10.setBorder(null);
getContentPane().add(jTextField10);
jTextField10.setBounds(410, 260, 130, 18);
jButton2.setLabel("Effacer");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
getContentPane().add(jButton2);
jButton2.setBounds(330, 340, 80, 27);
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(ctt.getVector()));
getContentPane().add(jComboBox1);
jComboBox1.setBounds(260, 70, 150, 22);
jButton3.setText("S\u00e9lection");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
getContentPane().add(jButton3);
jButton3.setBounds(430, 70, 90, 27);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
setBounds((screenSize.width-609)/2, (screenSize.height-440)/2, 609, 440);
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
1 / 9 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans linterface ou les textes ? Ou savez-vous comment améliorer linterface utilisateur de StudyLib ? Nhésitez pas à envoyer vos suggestions. Cest très important pour nous !