Traitement sur les boutons
mono2011
-
KX Messages postés 19031 Statut Modérateur -
KX Messages postés 19031 Statut Modérateur -
Bonjour, je develope sur jdeveloper 11g et swing pour ma fenêtre PRODUIT
permet a un utilisateur d'effectuer certains opérations en clikant sur des boutons tels que:
-lajouter(permet a l'utilisateur de saisir un nouveau produit);
-afficher(pour afficher tous les produits stockés dans la table produit)
-supprimer(pour supprimer un produit dans la table produit)
aider moi svp!
j'éssai mes je ne me retrouve pas,mais voici mon code:
private void jbInit() throws Exception {
this.getContentPane().setLayout( null );
this.setSize(new Dimension(866, 381));
this.setTitle( "OPERATIONS SUR LES PRODUITS" );
jajouter.setText("AJOUTER");
jajouter.setBounds(new Rectangle(5, 325, 140, 25));
jajouter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ajouter_actionPerformed(e);
}
});
jenregistrer.setText("ENREGISTRER");
jenregistrer.setBounds(new Rectangle(150, 330, 125, 20));
jenregistrer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
enregistrer_actionPerformed(e);
}
});
jButton3.setText("SUPPRIMER");
jButton3.setBounds(new Rectangle(285, 330, 125, 20));
/*jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
supprimer_actionPerformed(e);
}
});*/
jafficher.setText("AFFICHER");
jafficher.setBounds(new Rectangle(415, 330, 125, 20));
jafficher.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
afficher_actionPerformed(e);
}
});
jButton5.setText("FERMER");
jButton5.setBounds(new Rectangle(550, 325, 105, 25));
jButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fermer_actionPerformed(e);
}
});
jref.setBounds(new Rectangle(165, 20, 170, 20));
jref.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ref_actionPerformed(e);
}
});
jdesigne.setBounds(new Rectangle(160, 75, 350, 20));
jdesigne.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
designation_actionPerformed(e);
}
});
jprix.setBounds(new Rectangle(160, 130, 180, 20));
jprix.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
prix_actionPerformed(e);
}
});
jLabel1.setText("REFERENCE");
jLabel1.setBounds(new Rectangle(5, 20, 140, 20));
jLabel1.setFont(new Font("Tahoma", 1, 18));
jLabel2.setText("DESIGNATION");
jLabel2.setBounds(new Rectangle(5, 75, 150, 20));
jLabel2.setFont(new Font("Tahoma", 1, 18));
jLabel3.setText("PRIX");
jLabel3.setBounds(new Rectangle(10, 135, 60, 15));
jLabel3.setFont(new Font("Tahoma", 1, 18));
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jprix, null);
this.getContentPane().add(jdesigne, null);
this.getContentPane().add(jref, null);
this.getContentPane().add(jButton5, null);
this.getContentPane().add(jafficher, null);
this.getContentPane().add(jButton3, null);
this.getContentPane().add(jenregistrer, null);
this.getContentPane().add(jajouter, null);
//connexion base de données
Connection conn=null;
ResultSet rs=null;
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql:/127.0.0.1/BD_PRODUIT?user=root";
// Class.forName("org.gjt.mm.mysql.Driver");
conn=DriverManager.getConnection(url);
}
public void jajouter(String r,String designe,double p) throws SQLException, ClassNotFoundException {
if(conn==null){
try{
String requete="insert into produit values('"+r+"','"+designe+"',p)";
Statement st=conn.createStatement();
st.executeUpdate(requete);
}
catch(SQLException ex){
ex.printStackTrace();
}
finally{
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
}
}
public void jafficher(){
Frm_produit produit=null;
if(conn==null)
try{
String requete = "select* from produit";
st =conn.createStatement();
rs = st.executeQuery(requete);
while(rs.next()){
produit=new Produit();
produit.ref=ref.getString("ref");
produit.designation=designation.getString("designation");
prodtuit.prix=prix.getDouble("prix");
//System.out.println("ref:" +rs.getString("ref")+ "designation:"+rs.getString("designation")+ "prix:"+rs.getDouble("prix"));
}
//System.out.println(rs.getString("ref")+" "+rs.getString("designation")+" "+rs.getDouble("prix") );
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Impossible de se connecter","Erreur",JOptionPane.ERROR_MESSAGE);
}
return produit;
}
private void ajouter_actionPerformed(ActionEvent e) {
}
permet a un utilisateur d'effectuer certains opérations en clikant sur des boutons tels que:
-lajouter(permet a l'utilisateur de saisir un nouveau produit);
-afficher(pour afficher tous les produits stockés dans la table produit)
-supprimer(pour supprimer un produit dans la table produit)
aider moi svp!
j'éssai mes je ne me retrouve pas,mais voici mon code:
private void jbInit() throws Exception {
this.getContentPane().setLayout( null );
this.setSize(new Dimension(866, 381));
this.setTitle( "OPERATIONS SUR LES PRODUITS" );
jajouter.setText("AJOUTER");
jajouter.setBounds(new Rectangle(5, 325, 140, 25));
jajouter.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ajouter_actionPerformed(e);
}
});
jenregistrer.setText("ENREGISTRER");
jenregistrer.setBounds(new Rectangle(150, 330, 125, 20));
jenregistrer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
enregistrer_actionPerformed(e);
}
});
jButton3.setText("SUPPRIMER");
jButton3.setBounds(new Rectangle(285, 330, 125, 20));
/*jButton3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
supprimer_actionPerformed(e);
}
});*/
jafficher.setText("AFFICHER");
jafficher.setBounds(new Rectangle(415, 330, 125, 20));
jafficher.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
afficher_actionPerformed(e);
}
});
jButton5.setText("FERMER");
jButton5.setBounds(new Rectangle(550, 325, 105, 25));
jButton5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fermer_actionPerformed(e);
}
});
jref.setBounds(new Rectangle(165, 20, 170, 20));
jref.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
ref_actionPerformed(e);
}
});
jdesigne.setBounds(new Rectangle(160, 75, 350, 20));
jdesigne.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
designation_actionPerformed(e);
}
});
jprix.setBounds(new Rectangle(160, 130, 180, 20));
jprix.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
prix_actionPerformed(e);
}
});
jLabel1.setText("REFERENCE");
jLabel1.setBounds(new Rectangle(5, 20, 140, 20));
jLabel1.setFont(new Font("Tahoma", 1, 18));
jLabel2.setText("DESIGNATION");
jLabel2.setBounds(new Rectangle(5, 75, 150, 20));
jLabel2.setFont(new Font("Tahoma", 1, 18));
jLabel3.setText("PRIX");
jLabel3.setBounds(new Rectangle(10, 135, 60, 15));
jLabel3.setFont(new Font("Tahoma", 1, 18));
this.getContentPane().add(jLabel3, null);
this.getContentPane().add(jLabel2, null);
this.getContentPane().add(jLabel1, null);
this.getContentPane().add(jprix, null);
this.getContentPane().add(jdesigne, null);
this.getContentPane().add(jref, null);
this.getContentPane().add(jButton5, null);
this.getContentPane().add(jafficher, null);
this.getContentPane().add(jButton3, null);
this.getContentPane().add(jenregistrer, null);
this.getContentPane().add(jajouter, null);
//connexion base de données
Connection conn=null;
ResultSet rs=null;
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql:/127.0.0.1/BD_PRODUIT?user=root";
// Class.forName("org.gjt.mm.mysql.Driver");
conn=DriverManager.getConnection(url);
}
public void jajouter(String r,String designe,double p) throws SQLException, ClassNotFoundException {
if(conn==null){
try{
String requete="insert into produit values('"+r+"','"+designe+"',p)";
Statement st=conn.createStatement();
st.executeUpdate(requete);
}
catch(SQLException ex){
ex.printStackTrace();
}
finally{
try{
conn.close();
}
catch(SQLException ex){
ex.printStackTrace();
}
}
}
}
public void jafficher(){
Frm_produit produit=null;
if(conn==null)
try{
String requete = "select* from produit";
st =conn.createStatement();
rs = st.executeQuery(requete);
while(rs.next()){
produit=new Produit();
produit.ref=ref.getString("ref");
produit.designation=designation.getString("designation");
prodtuit.prix=prix.getDouble("prix");
//System.out.println("ref:" +rs.getString("ref")+ "designation:"+rs.getString("designation")+ "prix:"+rs.getDouble("prix"));
}
//System.out.println(rs.getString("ref")+" "+rs.getString("designation")+" "+rs.getDouble("prix") );
}
catch(Exception e){
JOptionPane.showMessageDialog(null,"Impossible de se connecter","Erreur",JOptionPane.ERROR_MESSAGE);
}
return produit;
}
private void ajouter_actionPerformed(ActionEvent e) {
}
A voir également:
- Traitement sur les boutons
- Reconsidérer le traitement de vos informations à des fins publicitaires - Accueil - Réseaux sociaux
- A quoi servent les boutons de couleur sur une telecommande - Guide
- Comment réinitialiser un téléphone avec les boutons - Guide
- Traitement de texte gratuit - Guide
- Ce logiciel gratuit et léger est parfait pour remplacer Word, même sur un vieux PC - Guide