Guest User

Untitled

a guest
Feb 11th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.26 KB | None | 0 0
  1. public class Afficher extends JFrame{
  2.    
  3.     JPanel p1 = new JPanel();
  4.     JLabel space = new JLabel(" ");
  5.     JLabel logo = new JLabel(new ImageIcon("logo.png"));
  6.     JButton fermer = new JButton("Fermer");
  7.    
  8.    
  9.     public Afficher(){
  10.  
  11.        
  12.         this.setTitle("Inscription Etduiant");
  13.         this.setSize(500,550);
  14.         this.setLocationRelativeTo(null);
  15.         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  16.         this.setResizable(true);
  17.        
  18.         JScrollPane scroll = new JScrollPane(p1);
  19.        
  20.         Box b1 = Box.createHorizontalBox();
  21.         Box b0 = Box.createVerticalBox();
  22.         Box b2 = Box.createHorizontalBox();
  23.         Box res = Box.createHorizontalBox();
  24.         Box nom = Box.createVerticalBox();
  25.         Box prenom = Box.createVerticalBox();
  26.         Box id = Box.createVerticalBox();
  27.         Box sexe = Box.createVerticalBox();
  28.         Box bouttons = Box.createHorizontalBox();
  29.        
  30.         b1.add(logo);
  31.         b2.add(space);
  32.        
  33.         bouttons.add(fermer);
  34.        
  35.         fermer.addActionListener(new boutonF());
  36.        
  37.        
  38.         String url = "jdbc:mysql://localhost:8889/Java";
  39.         String login = "root";
  40.         String passwd = "root";
  41.         Connection cn =null;
  42.         Statement st =null;
  43.         ResultSet rs =null;
  44.        
  45.         try {
  46.  
  47.             Class.forName("com.mysql.jdbc.Driver");
  48.  
  49.             cn = DriverManager.getConnection(url, login, passwd);
  50.  
  51.             st = cn.createStatement();
  52.  
  53.             String sql = "SELECT * FROM Etudiant";
  54.  
  55.             rs = st.executeQuery(sql);
  56.  
  57.             while (rs.next()) {
  58.                 JLabel resultati = new JLabel(""+rs.getObject(1)+"  ");
  59.                 id.add(resultati);
  60.                 JLabel resultatn = new JLabel(""+rs.getObject(2)+"  ");
  61.                 nom.add(resultatn);
  62.                 JLabel resultatp = new JLabel("  "+rs.getObject(3)+"  ");
  63.                 prenom.add(resultatp);
  64.                 JLabel resultats = new JLabel("  "+rs.getObject(4)+"  ");
  65.                 sexe.add(resultats);
  66.             }
  67.             res.add(id);
  68.             res.add(nom);
  69.             res.add(prenom);
  70.             res.add(sexe);
  71.         } catch (SQLException e) {
  72.             e.printStackTrace();
  73.         } catch (ClassNotFoundException e) {
  74.             e.printStackTrace();
  75.         } finally {
  76.             try {
  77.                 cn.close();
  78.                 st.close();
  79.             } catch (SQLException e) {
  80.                 e.printStackTrace();
  81.             }
  82.         }
  83.        
  84.        
  85.        
  86.        
  87.         b0.add(b1);
  88.         b0.add(b2);
  89.         b0.add(res);
  90.         b0.add(space);
  91.         b0.add(space);
  92.         b0.add(bouttons);
  93.        
  94.        
  95.         this.getContentPane().add(scroll, BorderLayout.CENTER);
  96.         this.getContentPane().add(b0);
  97.         this.setVisible(true);
  98.        
  99.     }
Add Comment
Please, Sign In to add comment