Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkg;
- import java.awt.Color;
- import java.awt.EventQueue;
- import java.awt.Font;
- import java.awt.SystemColor;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.Calendar;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JSpinner;
- import javax.swing.JTextField;
- import javax.swing.SpinnerDateModel;
- import javax.swing.UIManager;
- import javax.swing.border.EmptyBorder;
- import javax.swing.border.TitledBorder;
- import com.toedter.calendar.JDateChooser;
- import javax.swing.JTextArea;
- import javax.swing.JTable;
- import javax.swing.JComboBox;
- import javax.swing.DefaultComboBoxModel;
- import javax.swing.JRadioButton;
- import java.sql.*;
- public class Supplier extends JFrame {
- private JPanel contentPane;
- private JTextField txtSupplierId;
- private JTextField txtSupplierName;
- private JTextField txtSupplierSurname;
- private JTextField txtPhone;
- private JTextField txtCompanyName;
- private JTextField txtBRN;
- private JTextField txtVAT;
- private JTextArea txtAddress;
- private Connection con;
- private ResultSet rs;
- private Statement stt;
- String url = "jdbc:mysql://localhost:3306/java";
- String user = "root";
- String pw = "";
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Supplier frame = new Supplier();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- public Supplier() {
- super("Supplier Details");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 1100, 766);
- contentPane = new JPanel();
- contentPane.setBackground(SystemColor.inactiveCaptionBorder);
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JLabel lblNewLabel = new JLabel("New label");
- lblNewLabel.setIcon(new ImageIcon(Supplier.class.getResource("/Images/Main-Banner.jpg")));
- lblNewLabel.setBounds(0, 0, 1084, 100);
- contentPane.add(lblNewLabel);
- JLabel lblAppointmentHandling = new JLabel("SUPPLIER DETAILS");
- lblAppointmentHandling.setFont(new Font("Proxima Nova", Font.BOLD, 22));
- lblAppointmentHandling.setBounds(41, 111, 342, 42);
- contentPane.add(lblAppointmentHandling);
- JPanel panel = new JPanel();
- panel.setBackground(SystemColor.inactiveCaptionBorder);
- panel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Supplier ID", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
- panel.setBounds(41, 164, 226, 73);
- contentPane.add(panel);
- panel.setLayout(null);
- JLabel lblTime = new JLabel("ID");
- lblTime.setBounds(30, 29, 27, 15);
- panel.add(lblTime);
- lblTime.setFont(new Font("Tahoma", Font.PLAIN, 12));
- txtSupplierId = new JTextField();
- txtSupplierId.setEnabled(false);
- txtSupplierId.setBounds(67, 27, 86, 20);
- panel.add(txtSupplierId);
- txtSupplierId.setColumns(10);
- JPanel panel_3 = new JPanel();
- panel_3.setBackground(SystemColor.inactiveCaptionBorder);
- panel_3.setLayout(null);
- panel_3.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Operations", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
- panel_3.setBounds(295, 164, 736, 73);
- contentPane.add(panel_3);
- JButton btnDelete = new JButton("Delete");
- btnDelete.setIcon(new ImageIcon(Supplier.class.getResource("/Images/cross.png")));
- btnDelete.setBounds(303, 26, 129, 36);
- panel_3.add(btnDelete);
- try{
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(url, user, pw);
- stt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
- rs = stt.executeQuery("SELECT * FROM supplier");
- }catch(Exception ee){
- ee.printStackTrace();
- }
- btnDelete.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- Connection con = DriverManager.getConnection(url, user, pw);
- String del = "DELETE FROM supplier WHERE SupplierID = ?";
- PreparedStatement pstmt = con.prepareStatement(del);
- int id = Integer.parseInt(txtSupplierId.getText());
- pstmt.setInt(1, id);
- pstmt.execute();
- JOptionPane.showMessageDialog(null, "Deleted");
- } catch (Exception err) {
- JOptionPane.showMessageDialog(Supplier.this, err.getMessage());
- }
- }
- });
- JButton btnMainMenu = new JButton("Back");
- btnMainMenu.setBounds(591, 26, 129, 36);
- panel_3.add(btnMainMenu);
- btnMainMenu.setIcon(new ImageIcon(Supplier.class.getResource("/Images/gtk-go-back-ltr.png")));
- btnMainMenu.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent arg0) {
- /* frame.dispose();
- MainMenu window = new MainMenu();
- window.setVisible(true);
- *
- *
- *
- */
- }
- });
- JButton btnAdd = new JButton("Add");
- btnAdd.setBounds(15, 26, 129, 36);
- panel_3.add(btnAdd);
- btnAdd.setIcon(new ImageIcon(Supplier.class.getResource("/Images/add.png")));
- btnAdd.addMouseListener(new MouseAdapter(){
- public void mouseClicked(MouseEvent e){
- try{
- txtSupplierId.setText("");
- txtSupplierName.setText("");
- txtSupplierSurname.setText("");
- txtPhone.setText("");
- txtAddress.setText("");
- txtCompanyName.setText("");
- txtBRN.setText("");
- }catch(Exception q){
- JOptionPane.showMessageDialog(null, q);
- }
- }
- });
- JButton btnSave = new JButton("Save");
- btnSave.setBounds(159, 26, 129, 36);
- panel_3.add(btnSave);
- btnSave.setIcon(new ImageIcon(Supplier.class.getResource("/Images/Save.png")));
- btnSave.addMouseListener(new MouseAdapter() {@Override
- public void mouseClicked(MouseEvent e) {
- try{
- Class.forName("com.mysql.jdbc.Driver");
- con = DriverManager.getConnection(url, user, pw);
- String fName = txtSupplierName.getText();
- String lName = txtSupplierSurname.getText();
- String comName = txtCompanyName.getText();
- String add = txtAddress.getText();
- String phone = txtPhone.getText();
- String brn = txtBRN.getText();
- PreparedStatement ptt = con.prepareStatement("INSERT INTO supplier (SupplierName, SupplierSurname, "
- + "PhoneNumber, Address, CompanyName, BRN) values (?,?,?,?,?,?)");
- ptt.setString(1, fName);
- ptt.setString(2, lName);
- ptt.setString(3, comName);
- ptt.setString(4, add);
- ptt.setString(5, phone);
- ptt.setString(6, brn);
- ptt.execute();
- JOptionPane.showMessageDialog(null, "Supplier Added Successfully");
- }catch(Exception e1){
- e1.printStackTrace();
- }
- }
- });
- JButton btnCancel = new JButton("Cancel");
- btnCancel.setIcon(new ImageIcon(Supplier.class.getResource("/Images/trash_delete.png")));
- btnCancel.setBounds(447, 26, 129, 36);
- panel_3.add(btnCancel);
- JPanel panel_6 = new JPanel();
- panel_6.setBounds(41, 261, 990, 434);
- contentPane.add(panel_6);
- panel_6.setLayout(null);
- panel_6.setForeground(SystemColor.inactiveCaptionBorder);
- panel_6.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Supplier Details", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
- panel_6.setBackground(SystemColor.inactiveCaptionBorder);
- JLabel lblFirstName = new JLabel("First Name");
- lblFirstName.setBounds(52, 52, 74, 14);
- panel_6.add(lblFirstName);
- JLabel lblLastName = new JLabel("Last Name");
- lblLastName.setBounds(52, 111, 74, 14);
- panel_6.add(lblLastName);
- txtSupplierName = new JTextField();
- txtSupplierName.setColumns(10);
- txtSupplierName.setBounds(144, 52, 161, 26);
- panel_6.add(txtSupplierName);
- txtSupplierSurname = new JTextField();
- txtSupplierSurname.setColumns(10);
- txtSupplierSurname.setBounds(144, 105, 161, 26);
- panel_6.add(txtSupplierSurname);
- JLabel lblAddress = new JLabel("Address");
- lblAddress.setBounds(52, 220, 74, 14);
- panel_6.add(lblAddress);
- txtAddress = new JTextArea();
- txtAddress.setBounds(147, 215, 235, 65);
- panel_6.add(txtAddress);
- JPanel panel_1 = new JPanel();
- panel_1.setLayout(null);
- panel_1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Navigate", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
- panel_1.setBackground(SystemColor.inactiveCaptionBorder);
- panel_1.setBounds(753, 26, 205, 93);
- panel_6.add(panel_1);
- JButton btnPrevious = new JButton("");
- btnPrevious.setIcon(new ImageIcon(Supplier.class.getResource("/Images/previous.png")));
- btnPrevious.setBounds(42, 26, 56, 36);
- panel_1.add(btnPrevious);
- btnPrevious.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- try{
- if (rs.previous()) {
- Integer supID = rs.getInt("SupplierID");
- String SupName = rs.getString("SupplierName");
- String supSurname = rs.getString("SupplierSurname");
- String phone = rs.getString("PhoneNumber");
- String add = rs.getString("Address");
- String comp = rs.getString("CompanyName");
- String brn = rs.getString("BRN");
- txtSupplierId.setText(supID.toString());
- txtSupplierName.setText(SupName);
- txtSupplierSurname.setText(supSurname);
- txtPhone.setText(phone);
- txtAddress.setText(add);
- txtCompanyName.setText(comp);
- txtBRN.setText(brn);
- } else {
- rs.next();
- JOptionPane.showMessageDialog(Supplier.this, "End of file");
- }
- } catch(Exception p){
- }
- }
- });
- JButton btnNext = new JButton("");
- btnNext.setIcon(new ImageIcon(Supplier.class.getResource("/Images/br_next.png")));
- btnNext.setBounds(108, 26, 56, 36);
- panel_1.add(btnNext);
- btnNext.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- try {
- if (rs.next()) {
- Integer supID = rs.getInt("SupplierID");
- String SupName = rs.getString("SupplierName");
- String supSurname = rs.getString("SupplierSurname");
- String phone = rs.getString("PhoneNumber");
- String add = rs.getString("Address");
- String comp = rs.getString("CompanyName");
- String brn = rs.getString("BRN");
- txtSupplierId.setText(supID.toString());
- txtSupplierName.setText(SupName);
- txtSupplierSurname.setText(supSurname);
- txtPhone.setText(phone);
- txtAddress.setText(add);
- txtCompanyName.setText(comp);
- txtBRN.setText(brn);
- } else {
- rs.previous();
- JOptionPane.showMessageDialog(Supplier.this, "End of file");
- }
- } catch (SQLException err) {
- JOptionPane.showMessageDialog(Supplier.this, err.getMessage());
- }
- }
- });
- txtPhone = new JTextField();
- txtPhone.setColumns(10);
- txtPhone.setBounds(144, 314, 161, 26);
- panel_6.add(txtPhone);
- JLabel lblPhoneNum = new JLabel("Phone Num.");
- lblPhoneNum.setBounds(52, 320, 74, 14);
- panel_6.add(lblPhoneNum);
- JLabel lblCompanyName = new JLabel("Company Name");
- lblCompanyName.setBounds(52, 166, 87, 14);
- panel_6.add(lblCompanyName);
- txtCompanyName = new JTextField();
- txtCompanyName.setColumns(10);
- txtCompanyName.setBounds(144, 160, 161, 26);
- panel_6.add(txtCompanyName);
- JLabel lblBrn = new JLabel("BRN");
- lblBrn.setBounds(390, 58, 87, 14);
- panel_6.add(lblBrn);
- txtBRN = new JTextField();
- txtBRN.setColumns(10);
- txtBRN.setBounds(482, 52, 161, 26);
- panel_6.add(txtBRN);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement