Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Afficher extends JFrame{
- JPanel p1 = new JPanel();
- JLabel space = new JLabel(" ");
- JLabel logo = new JLabel(new ImageIcon("logo.png"));
- JButton fermer = new JButton("Fermer");
- public Afficher(){
- this.setTitle("Inscription Etduiant");
- this.setSize(500,550);
- this.setLocationRelativeTo(null);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setResizable(true);
- JScrollPane scroll = new JScrollPane(p1);
- Box b1 = Box.createHorizontalBox();
- Box b0 = Box.createVerticalBox();
- Box b2 = Box.createHorizontalBox();
- Box res = Box.createHorizontalBox();
- Box nom = Box.createVerticalBox();
- Box prenom = Box.createVerticalBox();
- Box id = Box.createVerticalBox();
- Box sexe = Box.createVerticalBox();
- Box bouttons = Box.createHorizontalBox();
- b1.add(logo);
- b2.add(space);
- bouttons.add(fermer);
- fermer.addActionListener(new boutonF());
- String url = "jdbc:mysql://localhost:8889/Java";
- String login = "root";
- String passwd = "root";
- Connection cn =null;
- Statement st =null;
- ResultSet rs =null;
- try {
- Class.forName("com.mysql.jdbc.Driver");
- cn = DriverManager.getConnection(url, login, passwd);
- st = cn.createStatement();
- String sql = "SELECT * FROM Etudiant";
- rs = st.executeQuery(sql);
- while (rs.next()) {
- JLabel resultati = new JLabel(""+rs.getObject(1)+" ");
- id.add(resultati);
- JLabel resultatn = new JLabel(""+rs.getObject(2)+" ");
- nom.add(resultatn);
- JLabel resultatp = new JLabel(" "+rs.getObject(3)+" ");
- prenom.add(resultatp);
- JLabel resultats = new JLabel(" "+rs.getObject(4)+" ");
- sexe.add(resultats);
- }
- res.add(id);
- res.add(nom);
- res.add(prenom);
- res.add(sexe);
- } catch (SQLException e) {
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- } finally {
- try {
- cn.close();
- st.close();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
- b0.add(b1);
- b0.add(b2);
- b0.add(res);
- b0.add(space);
- b0.add(space);
- b0.add(bouttons);
- this.getContentPane().add(scroll, BorderLayout.CENTER);
- this.getContentPane().add(b0);
- this.setVisible(true);
- }
Add Comment
Please, Sign In to add comment