Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package principal;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import javax.swing.Box;
- import javax.swing.BoxLayout;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import javax.swing.JToolBar;
- import com.mysql.jdbc.Statement;
- class Frame extends JFrame{
- private void CreateDataBase() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
- String url = "jdbc:mysql://localhost:3306/test";
- Statement sql;
- ResultSet rs;
- Class.forName ("com.mysql.jdbc.Driver").newInstance ();
- Connection con = DriverManager.getConnection (url, "root", "root");
- sql = (Statement) con.createStatement();
- rs = sql.executeQuery("select * from persoane");
- while (rs.next())
- System.out.println("id="+rs.getInt("Id")+", nume= " + rs.getString("nume")+ ", varsta="+rs.getInt(3));
- con.close();
- sql.close();
- rs.close();
- }
- public Frame(){
- super("DataBase");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setSize(500, 500);
- getContentPane().setLayout(new BorderLayout());
- JToolBar myBar=new JToolBar();
- JPanel Center = new JPanel();
- Center.setLayout(new FlowLayout());
- JPanel Left = new JPanel();
- Left.setLayout(new BoxLayout(Left, BoxLayout.Y_AXIS));
- JLabel Left_id=new JLabel("Id");
- JLabel Left_name=new JLabel("Nume");
- JLabel Left_age=new JLabel("Varsta");
- Left_id.setAlignmentX( Component.RIGHT_ALIGNMENT );
- Left_name.setAlignmentX( Component.RIGHT_ALIGNMENT );
- Left_age.setAlignmentX( Component.RIGHT_ALIGNMENT );
- JPanel Right = new JPanel();
- Right.setLayout(new BoxLayout(Right,BoxLayout.Y_AXIS));
- JTextField Right_id = new JTextField();
- JTextField Right_name = new JTextField();
- JTextField Right_age = new JTextField();
- Right_id.setAlignmentX( Component.LEFT_ALIGNMENT );
- Right_name.setAlignmentX( Component.LEFT_ALIGNMENT );
- Right_age.setAlignmentX( Component.LEFT_ALIGNMENT );
- Right_id.setPreferredSize(new Dimension(150,18));
- Center.add(Left);
- Center.add(Right);
- getContentPane().add(myBar,BorderLayout.NORTH);
- getContentPane().add(Center,BorderLayout.CENTER);
- JButton btnFirst=new JButton();
- JButton btnPrevious=new JButton();
- JButton btnNext=new JButton();
- JButton btnLast=new JButton();
- JButton btnAdd=new JButton();
- JButton btnEdit=new JButton();
- JButton btnDelete=new JButton();
- JButton btnFind=new JButton();
- JButton btnSave=new JButton();
- JButton btnBack=new JButton();
- JTextField txtAfis=new JTextField();
- btnFirst.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/MoveFirst.png"));
- btnPrevious.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/MovePrevious.png"));
- btnNext.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/MoveNext.png"));
- btnLast.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/MoveLast.png"));
- btnAdd.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/Add.png"));
- btnEdit.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/Edit.png"));
- btnDelete.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/Delete.png"));
- btnFind.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/find.jpg"));
- btnSave.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/save.jpg"));
- btnBack.setIcon(new ImageIcon("C:/Users/student/Desktop/Imagini/undo.jpg"));
- myBar.add(btnFirst);
- myBar.add(btnPrevious);
- myBar.add(txtAfis);
- myBar.add(btnNext);
- myBar.add(btnLast);
- myBar.add(btnAdd);
- myBar.add(btnEdit);
- myBar.add(btnDelete);
- myBar.add(btnFind);
- myBar.add(btnSave);
- myBar.add(btnBack);
- Left.add(Left_id);
- Left.add(Box.createVerticalStrut(10));
- Left.add(Left_name);
- Left.add(Box.createVerticalStrut(10));
- Left.add(Left_age);
- Right.add(Right_id);
- Left.add(Box.createVerticalStrut(10));
- Right.add(Right_name);
- Left.add(Box.createVerticalStrut(10));
- Right.add(Right_age);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement