Advertisement
Guest User

Untitled

a guest
Nov 21st, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.19 KB | None | 0 0
  1. package principal;
  2.  
  3. import java.awt.BorderLayout;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.FlowLayout;
  7. import java.sql.Connection;
  8. import java.sql.DriverManager;
  9. import java.sql.ResultSet;
  10. import java.sql.SQLException;
  11.  
  12. import javax.swing.Box;
  13. import javax.swing.BoxLayout;
  14. import javax.swing.ImageIcon;
  15. import javax.swing.JButton;
  16. import javax.swing.JFrame;
  17. import javax.swing.JLabel;
  18. import javax.swing.JPanel;
  19. import javax.swing.JTextField;
  20. import javax.swing.JToolBar;
  21.  
  22. import com.mysql.jdbc.Statement;
  23.  
  24.  
  25. class Frame extends JFrame{
  26.     private void CreateDataBase() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
  27.         String url = "jdbc:mysql://localhost:3306/test";
  28.         Statement sql;
  29.         ResultSet rs;
  30.         Class.forName ("com.mysql.jdbc.Driver").newInstance ();
  31.         Connection con = DriverManager.getConnection (url, "root", "root");
  32.         sql = (Statement) con.createStatement();
  33.         rs = sql.executeQuery("select * from persoane");
  34.         while (rs.next())
  35.         System.out.println("id="+rs.getInt("Id")+", nume= " + rs.getString("nume")+ ", varsta="+rs.getInt(3));
  36.        
  37.         con.close();
  38.         sql.close();
  39.         rs.close();
  40.     }
  41.     public Frame(){
  42.         super("DataBase");
  43.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  44.         setSize(500, 500);
  45.         getContentPane().setLayout(new BorderLayout());
  46.         JToolBar myBar=new JToolBar();
  47.        
  48.         JPanel Center = new JPanel();
  49.         Center.setLayout(new FlowLayout());
  50.        
  51.         JPanel Left = new JPanel();
  52.         Left.setLayout(new BoxLayout(Left, BoxLayout.Y_AXIS));
  53.         JLabel Left_id=new JLabel("Id");
  54.         JLabel Left_name=new JLabel("Nume");
  55.         JLabel Left_age=new JLabel("Varsta");
  56.         Left_id.setAlignmentX( Component.RIGHT_ALIGNMENT );
  57.         Left_name.setAlignmentX( Component.RIGHT_ALIGNMENT );
  58.         Left_age.setAlignmentX( Component.RIGHT_ALIGNMENT );
  59.        
  60.         JPanel Right = new JPanel();
  61.         Right.setLayout(new BoxLayout(Right,BoxLayout.Y_AXIS));
  62.         JTextField Right_id = new JTextField();
  63.         JTextField Right_name = new JTextField();
  64.         JTextField Right_age = new JTextField();
  65.         Right_id.setAlignmentX( Component.LEFT_ALIGNMENT );
  66.         Right_name.setAlignmentX( Component.LEFT_ALIGNMENT );
  67.         Right_age.setAlignmentX( Component.LEFT_ALIGNMENT );
  68.         Right_id.setPreferredSize(new Dimension(150,18));
  69.        
  70.         Center.add(Left);
  71.         Center.add(Right);
  72.        
  73.         getContentPane().add(myBar,BorderLayout.NORTH);
  74.         getContentPane().add(Center,BorderLayout.CENTER);
  75.        
  76.        
  77.        
  78.        
  79.         JButton btnFirst=new JButton();
  80.         JButton btnPrevious=new JButton();
  81.         JButton btnNext=new JButton();
  82.         JButton btnLast=new JButton();
  83.         JButton btnAdd=new JButton();
  84.         JButton btnEdit=new JButton();
  85.         JButton btnDelete=new JButton();
  86.         JButton btnFind=new JButton();
  87.         JButton btnSave=new JButton();
  88.         JButton btnBack=new JButton();
  89.         JTextField txtAfis=new JTextField();
  90.        
  91.         btnFirst.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/MoveFirst.png"));
  92.         btnPrevious.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/MovePrevious.png"));
  93.         btnNext.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/MoveNext.png"));
  94.         btnLast.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/MoveLast.png"));
  95.         btnAdd.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/Add.png"));
  96.         btnEdit.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/Edit.png"));
  97.         btnDelete.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/Delete.png"));
  98.         btnFind.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/find.jpg"));
  99.         btnSave.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/save.jpg"));
  100.         btnBack.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/undo.jpg"));
  101.        
  102.         myBar.add(btnFirst);
  103.         myBar.add(btnPrevious);
  104.         myBar.add(txtAfis);
  105.         myBar.add(btnNext);
  106.         myBar.add(btnLast);
  107.         myBar.add(btnAdd);
  108.         myBar.add(btnEdit);
  109.         myBar.add(btnDelete);
  110.         myBar.add(btnFind);
  111.         myBar.add(btnSave);
  112.         myBar.add(btnBack);
  113.        
  114.         Left.add(Left_id);
  115.         Left.add(Box.createVerticalStrut(10));
  116.         Left.add(Left_name);
  117.         Left.add(Box.createVerticalStrut(10));
  118.         Left.add(Left_age);
  119.        
  120.         Right.add(Right_id);
  121.         Left.add(Box.createVerticalStrut(10));
  122.         Right.add(Right_name);
  123.         Left.add(Box.createVerticalStrut(10));
  124.         Right.add(Right_age);
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement