diff --git a/DEV/DEV3.1/TP01/Exercise1/Database.java b/DEV/DEV3.1/TP01/Exercise1/Database.java new file mode 100644 index 0000000..d20035b --- /dev/null +++ b/DEV/DEV3.1/TP01/Exercise1/Database.java @@ -0,0 +1,65 @@ +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +public class Database { + + //Countries + public static String COUNTRY_ID = "id"; + public static String COUNTRY_NAME = "name"; + + //Votes table + public static String VOTES_COMPETITOR_ID = "competitor_id"; + public static String VOTES_VOTER_ID = "voter_id"; + public static String VOTES_POINTS = "points"; + + private Connection connection; + + public Database() { + try { + Class.forName("org.mariadb.jdbc.Driver"); + + this.connection = DriverManager.getConnection( + "jdbc:mariadb://dwarves.iut-fbleau.fr/baudrier", + "baudrier", + "baudrier" + ); + } catch(ClassNotFoundException exception) { + System.err.println("Class 'org.mariadb.jdbc.Driver' not found."); + } catch(SQLException exception) { + System.err.println("Error while trying to connect to the database"); + } + } + + public ResultSet getVotesFromCompetitor(String country) { + try { + PreparedStatement query = this.connection.prepareStatement( + "SELECT Countries.name, Countries.points FROM Votes INNER JOIN Countries ON Votes.competitor_id = Countries.id WHERE Votes.competitor_id = Countries.id" + ); + + ResultSet result = query.executeQuery(); + + try { + query.close(); + } catch(SQLException exception) { + System.err.println("Error while trying to close the query."); + } + + return result; + } catch(SQLException exception) { + System.err.println("Error while trying to prepare or execute the query."); + } + + return null; + } + + public void close() { + try { + this.connection.close(); + } catch(SQLException exception) { + System.err.println("Error while trying to close the connection."); + } + } +} diff --git a/DEV/DEV3.1/TP01/Exercise1/Main.java b/DEV/DEV3.1/TP01/Exercise1/Main.java new file mode 100644 index 0000000..5b54983 --- /dev/null +++ b/DEV/DEV3.1/TP01/Exercise1/Main.java @@ -0,0 +1,26 @@ +import java.sql.ResultSet; +import java.sql.SQLException; + +public class Main { + + public static void main(String[] args) { + Database database = new Database(); + + String country = "France"; + ResultSet result = database.getVotesFromCompetitor(country); + + try { + while(result.next()) { + System.out.println(country + " -> " + result.getString("name") + " : " + result.getInt("points")); + } + } catch(SQLException exception) { + System.err.println("Error while read the data from the result."); + } + + try { + result.close(); + } catch(SQLException exception) { + System.err.println("Error while trying to close the result."); + } + } +} diff --git a/DEV/DEV3.1/TP01/Exercise1/data.sql b/DEV/DEV3.1/TP01/Exercise1/data.sql new file mode 100644 index 0000000..de38ba4 --- /dev/null +++ b/DEV/DEV3.1/TP01/Exercise1/data.sql @@ -0,0 +1,23 @@ +CREATE TABLE Countries ( + id INT PRIMARY KEY, + name VARCHAR(30) +); + +CREATE TABLE Votes ( + id INT PRIMARY KEY AUTO_INCREMENT, + competitor_id INT REFERENCES Countries(id), + voter_id INT REFERENCES Countries(id), + points INT NOT NULL, + UNIQUE (competitor_id, voter_id) +) + +INSERT INTO Countries VALUES (1, "France"); +INSERT INTO Countries VALUES (2, "Pays-Bas"); +INSERT INTO Countries VALUES (3, "Albanie"); +INSERT INTO Countries VALUES (4, "Italie"); +INSERT INTO Countries VALUES (5, "Russie"); +INSERT INTO Votes VALUES (2, 4, 5); +INSERT INTO Votes VALUES (2, 5, 5); +INSERT INTO Votes VALUES (4, 2, 16); +INSERT INTO Votes VALUES (5, 2, 5); +INSERT INTO Votes VALUES (5, 4, 8); \ No newline at end of file diff --git a/DEV/DEV3.1/TP01/Exercise1/start.sh b/DEV/DEV3.1/TP01/Exercise1/start.sh new file mode 100755 index 0000000..884b328 --- /dev/null +++ b/DEV/DEV3.1/TP01/Exercise1/start.sh @@ -0,0 +1,2 @@ +javac Main.java; +java -cp "/export/documents/mariadb-client.jar" Main; \ No newline at end of file diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java b/DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java new file mode 100644 index 0000000..09c8cb8 --- /dev/null +++ b/DEV/DEV3.1/TP02/Exercise1/Part1/ClickSwapImageEvent.java @@ -0,0 +1,20 @@ +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; + +public class ClickSwapImageEvent extends MouseAdapter { + + private ImageWindow window; + + public ClickSwapImageEvent(ImageWindow window) { + this.window = window; + } + + public void mouseClicked(MouseEvent event) { + if(event.getX() > this.window.getWidth() / 2) { + this.window.nextImage(); + return; + } + + this.window.lastImage(); + } +} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java b/DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java new file mode 100644 index 0000000..415cc91 --- /dev/null +++ b/DEV/DEV3.1/TP02/Exercise1/Part1/ImageWindow.java @@ -0,0 +1,87 @@ +import java.io.File; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; + +public class ImageWindow extends JFrame { + + private ImageIcon[] images; + private int cursor; + + private JLabel label; + + public ImageWindow() { + this.setSize(1024, 1024); + this.setLocationRelativeTo(null); + this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + File resourcesDirectory = new File("../resources/"); + + if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) { + File[] files = resourcesDirectory.listFiles(); + + if(files != null) { + this.images = new ImageIcon[files.length]; + this.cursor = 0; + + for(File file : files) { + this.images[this.cursor] = new ImageIcon(file.getPath()); + this.cursor++; + } + } + } + + this.addMouseListener(new ClickSwapImageEvent(this)); + + this.cursor = 0; + + this.nextImage(); + } + + public void nextImage() { + if(this.images.length == 0) return; + + if(this.label != null) { + this.remove(this.label); + } + + this.label = new JLabel(this.images[cursor]); + this.label.setVerticalAlignment(JLabel.CENTER); + this.label.setHorizontalAlignment(JLabel.CENTER); + + if(this.cursor + 1 >= this.images.length) { + this.cursor = 0; + } else { + this.cursor++; + } + + System.out.println(this.cursor); + + this.add(label); + this.revalidate(); + } + + public void lastImage() { + if(this.images.length == 0) return; + + if(this.label != null) { + this.remove(this.label); + } + + this.label = new JLabel(this.images[cursor]); + this.label.setVerticalAlignment(JLabel.CENTER); + this.label.setHorizontalAlignment(JLabel.CENTER); + + if(this.cursor - 1 < 0) { + this.cursor = this.images.length - 1; + } else { + this.cursor--; + } + + System.out.println(this.cursor); + + this.add(label); + this.revalidate(); + } +} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part1/Main.java b/DEV/DEV3.1/TP02/Exercise1/Part1/Main.java new file mode 100644 index 0000000..49e2da6 --- /dev/null +++ b/DEV/DEV3.1/TP02/Exercise1/Part1/Main.java @@ -0,0 +1,7 @@ +public class Main { + + public static void main(String[] args) { + ImageWindow window = new ImageWindow(); + window.setVisible(true); + } +} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java b/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java new file mode 100644 index 0000000..998a2ee --- /dev/null +++ b/DEV/DEV3.1/TP02/Exercise1/Part2/ClickSwapImageEvent.java @@ -0,0 +1,5 @@ +package Part2; + +public class ClickSwapImageEvent { + +} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java b/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java new file mode 100644 index 0000000..b210479 --- /dev/null +++ b/DEV/DEV3.1/TP02/Exercise1/Part2/ImageWindow.java @@ -0,0 +1,26 @@ +import java.io.File; + +import java.awt.CardLayout; + +import javax.swing.ImageIcon; +import javax.swing.JFrame; + +public class ImageWindow extends JFrame { + + private CardLayout card; + + public ImageWindow() { + this.card = new CardLayout(); + + File resourcesDirectory = new File("../resources/"); + + if(resourcesDirectory.exists() && resourcesDirectory.isDirectory()) { + File[] files = resourcesDirectory.listFiles(); + + if(files != null) { + for(File file : files) { + } + } + } + } +} diff --git a/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java b/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java new file mode 100644 index 0000000..57f8e1d --- /dev/null +++ b/DEV/DEV3.1/TP02/Exercise1/Part2/Main.java @@ -0,0 +1,5 @@ +package Part2; + +public class Main { + +} diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg b/DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg new file mode 100644 index 0000000..9619f77 Binary files /dev/null and b/DEV/DEV3.1/TP02/Exercise1/resources/dice.jpg differ diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/frog.png b/DEV/DEV3.1/TP02/Exercise1/resources/frog.png new file mode 100644 index 0000000..f3c8c99 Binary files /dev/null and b/DEV/DEV3.1/TP02/Exercise1/resources/frog.png differ diff --git a/DEV/DEV3.1/TP02/Exercise1/resources/random.jpg b/DEV/DEV3.1/TP02/Exercise1/resources/random.jpg new file mode 100644 index 0000000..7f1e47c Binary files /dev/null and b/DEV/DEV3.1/TP02/Exercise1/resources/random.jpg differ