From 9dc29b2cbe74df2e17d3d1e87eb9ab1f4b8a7673 Mon Sep 17 00:00:00 2001 From: HORVILLE Ewen Date: Wed, 21 Sep 2022 11:14:37 +0200 Subject: [PATCH] TP3 --- DEV 3.1/TP3/Boutons/Butons.java | 128 +++++++++++++++++++++++++++++++ DEV 3.1/TP3/Tableau/Tableau.java | 46 +++++++++++ 2 files changed, 174 insertions(+) create mode 100644 DEV 3.1/TP3/Boutons/Butons.java create mode 100644 DEV 3.1/TP3/Tableau/Tableau.java diff --git a/DEV 3.1/TP3/Boutons/Butons.java b/DEV 3.1/TP3/Boutons/Butons.java new file mode 100644 index 0000000..d9b0b58 --- /dev/null +++ b/DEV 3.1/TP3/Boutons/Butons.java @@ -0,0 +1,128 @@ +import java.awt.*; +import javax.swing.*; +import java.awt.event.*; + +public class Butons { + + public static void main(String[] args) { + JFrame f = new JFrame(); + GridBagLayout gbl = new GridBagLayout(); + f.setLayout(gbl); + + GridBagConstraints c = new GridBagConstraints(); + + JButton b1 = new JButton("1"); + c.gridx = 1; + c.gridy = 1; + c.gridwidth = 2; + c.gridheight = 1; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.CENTER; + c.insets = new Insets(0, 0, 0, 0); + c.weightx = 1f; + c.weighty = 1f; + f.add(b1, c); + + JButton b2 = new JButton("2"); + c.gridx = 3; + c.gridy = 1; + c.gridwidth = 1; + c.gridheight = 2; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.CENTER; + c.insets = new Insets(0, 0, 0, 0); + c.weightx = 1f; + c.weighty = 1f; + f.add(b2, c); + + JButton b3 = new JButton("3"); + c.gridx = 2; + c.gridy = 3; + c.gridwidth = 2; + c.gridheight = 1; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.CENTER; + c.insets = new Insets(0, 0, 0, 0); + c.weightx = 1f; + c.weighty = 1f; + f.add(b3, c); + + JButton b4 = new JButton("4"); + c.gridx = 1; + c.gridy = 2; + c.gridwidth = 1; + c.gridheight = 2; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.CENTER; + c.insets = new Insets(0, 0, 0, 0); + c.weightx = 1f; + c.weighty = 1f; + f.add(b4, c); + + JButton b5 = new JButton("5"); + b5.setPreferredSize(new Dimension(75, 75)); + c.gridx = 2; + c.gridy = 2; + c.gridwidth = 1; + c.gridheight = 1; + c.fill = GridBagConstraints.BOTH; + c.anchor = GridBagConstraints.CENTER; + c.insets = new Insets(0, 0, 0, 0); + c.weightx = 0f; + c.weighty = 0f; + f.add(b5, c); + + f.addWindowListener(new WindowListener() { + + @Override + public void windowActivated(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowClosed(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowClosing(WindowEvent e) { + int confirm = JOptionPane.showConfirmDialog(f, "Voulez-vous vraiment fermer la fenĂȘtre ?"); + if (confirm == 0) { + f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } else { + f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); + } + } + + @Override + public void windowDeactivated(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowDeiconified(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowIconified(WindowEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void windowOpened(WindowEvent e) { + // TODO Auto-generated method stub + + } + + }); + + f.setSize(225, 225); + f.setVisible(true); + } +} \ No newline at end of file diff --git a/DEV 3.1/TP3/Tableau/Tableau.java b/DEV 3.1/TP3/Tableau/Tableau.java new file mode 100644 index 0000000..237fe2b --- /dev/null +++ b/DEV 3.1/TP3/Tableau/Tableau.java @@ -0,0 +1,46 @@ +import java.sql.*; +import javax.swing.*; +import java.awt.*; + +public class Tableau { + public static void main(String[] args) { + try { + Class.forName("org.mariadb.jdbc.Driver"); + } catch (ClassNotFoundException ex) { + System.err.println("MariaDB driver not found"); + return; + } + + + Connection cnx; + try { + cnx = DriverManager.getConnection("jdbc:mariadb://dwarves.iut-fbleau.fr/horville", "horville", "a5gc95"); + } catch (SQLException ex) { + System.err.println("Unable to access Database."); + return; + } + + try { + PreparedStatement req = cnx.prepareStatement("SELECT Module.code, Champ.code FROM Champ JOIN Module ON Champ.id = Module.id ORDER BY Module.code ASC;"); + req.executeUpdate(); + ResultSet rs = req.executeQuery(); + + while (rs.next()) { + System.out.println(rs.getString(1) + " " + rs.getString(2)); + } + + rs.close(); + req.close(); + + } catch (SQLException ex) { + System.err.println("SQL Request exception."); + System.err.println (ex); + } + + try { + cnx.close(); + } catch (SQLException ex) { + System.err.println("Unable to close connection."); + } + } +}