TP3
This commit is contained in:
parent
683236b504
commit
9dc29b2cbe
128
DEV 3.1/TP3/Boutons/Butons.java
Normal file
128
DEV 3.1/TP3/Boutons/Butons.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
46
DEV 3.1/TP3/Tableau/Tableau.java
Normal file
46
DEV 3.1/TP3/Tableau/Tableau.java
Normal file
@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user