comment peut on ajouter et récupérer un texte écrie dans un jtextarea dans la base de donnée?
Comment peut peut ajouter la valeur d'un item choisi de la liste déroulante(choice) dans la base de données?
VOICI MON CODE:
package Base_de_données;
import java.awt.*;
import java.io.*;
import java.sql.ResultSet;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
//swing
public class Standard extends JFrame implements ActionListener{
//attributs
private JFrame fenetre;
private JButton boutonD;
private JButton boutonB,boutonC,boutonE,boutonF;
private JLabel texte0, texte1,texte8, texte2,texte3,texte4,texte5,texte6,texte7,texte9,texte10,texte11,texte12,texte13,texte14,texte15;
private JTextField champA, champB,champc,champd,champe,champh,champf,champg,champi,champk,champl,champs,champv,champt,champj;
private Dimension dimension;
private JButton b1;
private JButton b2;
private JButton b3;
private JPanel p3,p5,p4;
private Image image ;
private Choice g,e,c,k,f;
public String s,s1,s2,s3,s4,s5,s6;
private ScrollPane scrollingResult;
public JTextArea echo;
//constructeur
public Standard() {
Font fl = new Font("sansserif",Font.BOLD,19);
Color nv= new Color(50,100,100);
Font f2 = new Font("times new roman",Font.BOLD,14);
Image icon_fen; //icone pour la fenetre
JFrameBackground img_background = new JFrameBackground(); //image de fond
icon_fen=Toolkit.getDefaultToolkit().getImage("C:/Documents and Settings/azerty/Mes documents/Mes images/sans titre.jpg");
this.fenetre=new JFrame("Cabinet Alyssa");
fenetre.setExtendedState(JFrame.MAXIMIZED_BOTH);
java.awt.Toolkit toolkit = java.awt.Toolkit.getDefaultToolkit();
fenetre.setIconImage(icon_fen);
//fond de fenetre
fenetre.setContentPane(img_background);
texte9=new JLabel(" Accés au standard à la base des clients ");
texte9.setFont(fl);
texte9.setForeground(Color.RED);
this.texte1=new JLabel(" Nom ");
texte1.setFont(f2);
texte2=new JLabel(" Adresse_Réel ");
texte2.setFont(f2);
texte3=new JLabel(" Tél_Fixe ");
texte3.setFont(f2);
texte4=new JLabel(" Tél_Mobile ");
texte4.setFont(f2);
texte5=new JLabel(" 1er contact ");
texte5.setFont(f2);
texte6=new JLabel(" Adresse_Mail ");
texte6.setFont(f2);
texte7=new JLabel(" Prénom ");
texte7.setFont(f2);
texte8=new JLabel(" D/N ");
texte8.setFont(f2);
texte10=new JLabel(" Remarques ");
texte10.setFont(f2);
texte11=new JLabel(" Forfait(€) ");
texte11.setFont(f2);
texte12=new JLabel(" Consultation_Privée(€) ");
texte12.setFont(f2);
texte14=new JLabel(" Identifiant ");
texte14.setFont(f2);
texte15=new JLabel(" Nom de la mère ");
texte15.setFont(f2);
texte1.setForeground(Color.WHITE);
texte2.setForeground(Color.WHITE);
texte3.setForeground(Color.WHITE);
texte4.setForeground(Color.WHITE);
texte5.setForeground(Color.WHITE);
texte6.setForeground(Color.WHITE);
texte9.setForeground(Color.WHITE);
texte7.setForeground(Color.WHITE);
texte8.setForeground(Color.WHITE);
texte9.setForeground(Color.WHITE);
texte10.setForeground(Color.WHITE);
texte11.setForeground(Color.WHITE);
texte12.setForeground(Color.WHITE);
texte14.setForeground(Color.WHITE);
texte15.setForeground(Color.WHITE);
Choice c = new Choice();
c.addItem("Permission_Appel");
c.addItem("Oui");
c.addItem("Non");
Choice d = new Choice();
d.addItem("RappelClient/NouveauClient");
d.addItem("RC");
d.addItem("NC");
Choice e = new Choice();
e.addItem("Publicité");
e.addItem("Beur Fm");
e.addItem("Tropiques Fm");
e.addItem("SMS");
e.addItem("Email");
e.addItem("Prospection");
e.addItem("Amie");
e.addItem("Cabinet");
e.addItem("Suisse");
e.addItem("Maxi_astro");
e.addItem("Télé_7jours");
e.addItem("Magazine");
e.addItem("Famille");
e.addItem("Autre");
Choice k = new Choice();
k.addItem("Alyssa");
k.addItem("");
Choice f = new Choice();
f.addItem("Voyant");
f.addItem("Voyant");
f.addItem("Voyant");
f.addItem("Voyant");
f.addItem("Voyant");
f.addItem("Voyant");
Choice g = new Choice();
g.addItem("Numéro poste");
g.addItem("N°2452");
g.addItem("N°2453");
g.addItem("N°2454");
g.addItem("N°2455");
g.addItem("N°2456");
g.addItem("N°2458");
g.addItem("N°2470.1");
g.addItem("N°2470.2");
g.addItem("N°2471.2");
g.addItem("N°2472.1");
g.addItem("N°2472.2");
g.addItem("N°2473.1");
g.addItem("N°2473.2");
g.addItem("N°2474.1");
g.addItem("N°2474.2");
champA=new JTextField(15);
champB=new JTextField(15);
champc=new JTextField(15);
champd=new JTextField(15);
champe=new JTextField(15);
champf=new JTextField(15);
champg=new JTextField(15);
champh=new JTextField(15);
champk=new JTextField(15);
champl=new JTextField(15);
champs=new JTextField(15);
champt=new JTextField(15);
champv=new JTextField(15);
champi=new JTextField(15);
champj=new JTextField(15);
dimension=new Dimension(200,100);
boutonD=new JButton(" Annuler");
boutonD.setSize(5, 10);
boutonC=new JButton(" Ajouter");
b1=new JButton(" Rechercher");
b3=new JButton(" Acceuil");
Container conteneur = fenetre.getContentPane();
JPanel p = new JPanel(new BorderLayout());
GridLayout disposition = new GridLayout(14,3);
p.setLayout(disposition);
p.show();
p.setSize(320,530);
p.setLocation(1, 50);
p.setOpaque(false);
conteneur.add(this.texte9, BorderLayout.NORTH);
conteneur.add(p);
GridLayout boxlayout1 = new GridLayout(10,1);
boxlayout1.setHgap(10);
p.add(this.texte1, BorderLayout.CENTER);
p.add(this.champA, BorderLayout.CENTER);
p.add(this.texte7, BorderLayout.CENTER);
p.add(this.champc, BorderLayout.CENTER);
p.add(this.texte8, BorderLayout.CENTER);
p.add(this.champh, BorderLayout.CENTER);
p.add(this.texte3, BorderLayout.CENTER);
p.add(this.champd, BorderLayout.CENTER);
p.add(this.texte4, BorderLayout.CENTER);
p.add(this.champe, BorderLayout.CENTER);
p.add(this.texte5, BorderLayout.CENTER);
p.add(this.champf, BorderLayout.CENTER);
p.add(this.texte6, BorderLayout.CENTER);
p.add(this.champg, BorderLayout.CENTER);
p.add(this.texte2, BorderLayout.CENTER);
p.add(this.champB, BorderLayout.CENTER);
p.add(this.texte10, BorderLayout.CENTER);
p.add(this.champk, BorderLayout.CENTER);
p.add(this.texte11, BorderLayout.CENTER);
p.add(this.champl, BorderLayout.CENTER);
p.add(this.texte12, BorderLayout.CENTER);
p.add(this.champs, BorderLayout.CENTER);
p.add(this.texte14, BorderLayout.CENTER);
p.add(this.champv, BorderLayout.CENTER);
p.add(this.texte15, BorderLayout.CENTER);
p.add(this.champi, BorderLayout.CENTER);
p5 = new JPanel(new BorderLayout());
GridLayout disposition1 = new GridLayout(9,1);
p5.setLayout(disposition1);
p5.setOpaque(false);
p5.setSize(180,530);
p5.setLocation(330, 50);
p5.add(c);
p5.add(d);
p5.add(e);
p5.add(f);
p5.add(k);
p5.add(g);
p4 = new JPanel(new BorderLayout());
p4.setOpaque(false);
p4.setLocation(22, 600);
p4.setSize(480,30);
GridLayout boxlayout2 = new GridLayout(1,4);
boxlayout2.setHgap(15);
p4.setLayout(boxlayout2);
fenetre.add(p4);
fenetre.add(p5);
texte13=new JLabel(" Observation ");
texte13.setFont(f2);
texte13.setForeground(Color.WHITE);
JTextArea echo = new JTextArea();
echo.setColumns(40);
echo.setRows(20);
echo.setEditable(true);
echo.setBackground(Color.WHITE);
JScrollPane scrollingResult = new JScrollPane(echo);
p5.add(this.texte13);
p5.add(scrollingResult);
String s1 = c.getSelectedItem();
String s2 = d.getSelectedItem();
String s3 = e.getSelectedItem();
String s4 = f.getSelectedItem();
String s5 = k.getSelectedItem();
String s6 = g.getSelectedItem();
p4.add(this.boutonD);
boutonD.addActionListener(this);
p4.add(this.boutonC);
boutonC.addActionListener(this);
p4.add(this.b1);
b1.addActionListener(this);
p4.add(this.b3);
b3.addActionListener(this);
this.fenetre.setBounds(100,100,300,300);
fenetre.setSize(600, 1000);
fenetre.setLocation(360,150);
this.fenetre.setVisible(true);
}
/*public JTextArea getTextArea(){
return echo;
}
public Object getCellEditorValue() {
System.out.println(echo.getText());
return echo.getText();
}*/
//méthode
public void actionPerformed(ActionEvent e){
Container conteneur = fenetre.getContentPane();
//premier changement
if (e.getSource()==boutonD) {
champA.setText("");
champB.setText("");
champc.setText("");
champd.setText("");
champe.setText("");
champf.setText("");
champg.setText("");
champh.setText("");
champk.setText("");
champl.setText("");
champs.setText("");
champt.setText("");
champv.setText("");
champi.setText("");
}
if (e.getSource()==boutonC) {
BasicJDBC c2=new BasicJDBC();
JTextArea echo = new JTextArea();
String contenu = new String();
contenu = echo.getText( );
if(!echo.getText().equals(""));
System.out.println("Message ?");
c2.Ajouter( champA.getText(),champc.getText(),champh.getText(),s4,champf.getText(),champi.getText(),contenu ,champk.getText(),champd.getText(), champe.getText(),champg.getText(),champB.getText(),s2,s3,s1,champl.getText(),champs.getText(),s5,s6);
}if (e.getSource()==b1) {
BasicJDBC c3=new BasicJDBC();
ResultSet rs=c3.Rechercher(champc.getText(),champh.getText());
try{
while (rs!=null && rs.next()){
String Identifiant=""+rs.getObject(1);
String Nom=""+rs.getObject(2);
String Prénom=""+rs.getObject(3);
String DN=""+rs.getObject(4);
//String Voyant= ""+rs.getObject(5);
String _1er_Contact= ""+rs.getObject(6);
String Nom_de_la_mère= ""+rs.getObject(7);
//String Observations= ""+rs.getObject(8);
String Remarques= ""+rs.getObject(9);
String Tél_Fixe= ""+rs.getObject(10);
String Tél_Mobile= ""+rs.getObject(11);
String Adresse_Mail= ""+rs.getObject(12);
String Adresse_Réel= ""+rs.getObject(13);
//String RappelClient_NouveauClient= ""+rs.getObject(14);
//String Publicité= ""+rs.getObject(15);
//String Permission_Appel= ""+rs.getObject(16);
String Forfait= ""+rs.getObject(17);
String Consultation_Privée= ""+rs.getObject(18);
//String Alyssa = ""+rs.getObject(19);
champv.setText(Identifiant);
champA.setText(Nom);
champc.setText(Prénom);
champh.setText(DN);
champf.setText(_1er_Contact);
champi.setText(Nom_de_la_mère);
//echo.setText("Observations");
champk.setText(Remarques);
champd.setText(Tél_Fixe);
champe.setText(Tél_Mobile);
champg.setText( Adresse_Mail);
champB.setText(Adresse_Réel);
champl.setText( Forfait);
champs.setText(Consultation_Privée);
}
}catch(Exception exec)
{
}
}
if (e.getSource()==b3) {
Acceuil cc=new Acceuil();
cc.pack();
}
}
public static void main(String[] args) {
Standard f1 = new Standard();
} }
class JFrameBackground extends JComponent
{
public void paintComponent(Graphics g)
{
g.drawImage(this.toBufferedImage(),0,0,null);
}
private BufferedImage toBufferedImage()
{
Image image = new ImageIcon("C:/Documents and Settings/azerty/Mes documents/Mes images/sans titre.jpg").getImage();
BufferedImage bufferedImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics g = bufferedImage.createGraphics();
g.drawImage(image, 0, 0, this);
//g.dispose();
return bufferedImage;
}
}
c'est trés urgent merci beaucoup!
Afficher la suite