Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.swing.*;
- import java.awt.event.*;
- import java.sql.*;
- import com.mysql.jdbc.*;
- public class SuiviPoids extends JFrame{
- private JCheckBox muscu;
- private JCheckBox footing;
- private JTextField poids;
- private JTextArea observation;
- public SuiviPoids(){
- super();
- init();
- JPanel principal = new JPanel();
- creerInterface(principal);
- add(principal);
- }
- private void init(){
- setTitle("Suivi du poids");
- setSize(265,200);
- setLocationRelativeTo(null);
- //setResizable(false);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- }
- private void creerInterface(JPanel p){
- // Création des éléments d'interface
- muscu = new JCheckBox();
- JLabel lMuscu = new JLabel("Muscu");
- footing = new JCheckBox();
- JLabel lFooting = new JLabel("Footing");
- poids = new JTextField(5);
- JLabel lPoids = new JLabel("Poids");
- observation = new JTextArea(3,20);
- JLabel lObservation = new JLabel("Observation");
- JButton envoyer = new JButton("Envoyer");
- envoyer.addActionListener(new EnvoiDonnees());
- JLabel feedback = new JLabel("");
- // Placement des éléments d'interface
- p.setLayout(new FlowLayout());
- p.add(lPoids);
- p.add(poids);
- p.add(lMuscu);
- p.add(muscu);
- p.add(lFooting);
- p.add(footing);
- p.add(lObservation);
- p.add(observation);
- p.add(envoyer);
- p.add(feedback);
- }
- private class EnvoiDonnees implements ActionListener{
- public void actionPerformed(ActionEvent e){
- // Connexion bdd
- String dbname="ccc";
- String login="cccc";
- String mdp="ccc";
- String host="cccccc.com";
- String port="3306";
- try {
- Class.forName("com.mysql.jdbc.Driver");
- String connectionUrl = "jdbc:mysql://"+host+":"+port+"/"+dbname+"?user="+login+"&password="+mdp;
- java.sql.Connection con = (java.sql.Connection) DriverManager.getConnection(connectionUrl);
- }
- catch (ClassNotFoundException cE) {
- System.out.println("Class Not Found Exception: "+ cE.toString());
- }
- catch (SQLException sqle) {
- System.out.println("SQL Exception: "+ sqle.toString());
- }
- // Préparation requete
- String requete = "INSERT INTO Poids VALUES(0,?,?,?,?)";
- /*try{
- PreparedStatement pst = (PreparedStatement) bdd.prepareStatement(requete);
- pst.setDate(1, getCurrentJavaSqlDate());
- pst.setFloat(2, Float.parseFloat(poids.getText()));
- Byte b;
- b = (muscu.isSelected())?new Integer(1).byteValue():new Integer(0).byteValue();
- pst.setByte(3, b);
- b = (footing.isSelected())?new Integer(1).byteValue():new Integer(0).byteValue();
- pst.setByte(4, b);
- // Envoi données
- //int numRowsChanged = pst.executeUpdate();
- pst.close();
- }catch(SQLException sqle){sqle.printStackTrace();}
- */
- // Envoi feedback
- /*
- System.out.println(muscu.isSelected());
- System.out.println(footing.isSelected());
- System.out.println(getCurrentJavaSqlDate());
- System.out.println(poids.getText());
- */
- }
- }
- public static java.sql.Date getCurrentJavaSqlDate() {
- java.util.Date today = new java.util.Date();
- return new java.sql.Date(today.getTime());
- }
- public static void main(String[] args){
- new SuiviPoids();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement