public CopyFileToTable() {
    JPanel jPane1 = new JPanel();
    jPane1.setLayout(new BorderLayout());
    jPane1.add(new JLabel("Filename"), BorderLayout.WEST);
    jPane1.add(jbtViewFile, BorderLayout.EAST);
    jPane1.add(jtfFilename, BorderLayout.CENTER);

    JPanel jPane2 = new JPanel();
    jPane2.setLayout(new BorderLayout());
    jPane2.setBorder(new TitledBorder("Source Text File"));
    jPane2.add(jPane1, BorderLayout.NORTH);
    jPane2.add(new JScrollPane(jtaFile), BorderLayout.CENTER);

    JPanel jPane3 = new JPanel();
    jPane3.setLayout(new GridLayout(5, 0));
    jPane3.add(new JLabel("JDBC Driver"));
    jPane3.add(new JLabel("Database URL"));
    jPane3.add(new JLabel("Username"));
    jPane3.add(new JLabel("Password"));
    jPane3.add(new JLabel("Table Name"));

    JPanel jPane4 = new JPanel();
    jPane4.setLayout(new GridLayout(5, 0));
    jcboDriver.setEditable(true);
    jPane4.add(jcboDriver);
    jcboURL.setEditable(true);
    jPane4.add(jcboURL);
    jPane4.add(jtfUsername);
    jPane4.add(jtfPassword);
    jPane4.add(jtfTableName);

    JPanel jPane5 = new JPanel();
    jPane5.setLayout(new BorderLayout());
    jPane5.setBorder(new TitledBorder("Target Database Table"));
    jPane5.add(jbtCopy, BorderLayout.SOUTH);
    jPane5.add(jPane3, BorderLayout.WEST);
    jPane5.add(jPane4, BorderLayout.CENTER);

    add(jlblStatus, BorderLayout.SOUTH);
    add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, jPane2, jPane5), BorderLayout.CENTER);

    jbtViewFile.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            showFile();
          }
        });

    jbtCopy.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            try {
              copyFile();
            } catch (Exception ex) {
              jlblStatus.setText(ex.toString());
            }
          }
        });
  }
Example #2
0
  public AddNewStudent() // constructor
      {
    // initializing buttons
    btnok = new JButton("OK");
    btnok.addActionListener(this);
    btnexit = new JButton("Exit");
    btnexit.addActionListener(this);
    btnaddnew = new JButton("AddNew");
    btnaddnew.addActionListener(this);

    // initializing textfields
    tf1 = new JTextField(12);
    tf2 = new JTextField(12);
    // initializing labels

    lblname = new JLabel("Name:");
    lbladd = new JLabel("Address:");
    lblmsg = new JLabel("", JLabel.CENTER);

    // initializing panels
    p1 = new JPanel();
    p2 = new JPanel();
    p3 = new JPanel();
    psouth = new JPanel();

    // adding buttons and label to panel p1
    // setting flowlayout
    p1.setLayout(new FlowLayout());

    p1.add(btnok);
    p1.add(btnexit);
    p1.add(btnaddnew);
    // adding lblmsg to panel p3
    p3.add(lblmsg);

    // adding both the panels to new panel,psouth
    // settin layout 2:1
    psouth.setLayout(new GridLayout(2, 1));
    psouth.add(p3);
    psouth.add(p1);

    // adding label and textfields to panel p2
    p2.setLayout(new GridLayout(3, 1));
    // setting line and titled border for panel p2
    p2.setBorder(BorderFactory.createLineBorder(Color.red));
    p2.setBorder(BorderFactory.createTitledBorder("Enter Your Details"));
    p2.add(lblname);
    p2.add(tf1);
    p2.add(lbladd);
    p2.add(tf2);

    // adding panel to container
    this.getContentPane().add(p2, "Center");
    this.getContentPane().add(psouth, "South");

    this.setSize(300, 300);
    this.setLocation(100, 200);
    this.show();
  }
Example #3
0
  public AuthDialog(final JFrame parent, String title, boolean modal) {
    super(parent, title, modal);

    // Set up close behaviour
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            if (!okButtonClicked) System.exit(0);
          }
        });

    // Set up OK button behaviour
    JButton okButton = new JButton("OK");
    okButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (getUserName().length() == 0) {
              showMessageDialog(
                  AuthDialog.this, "Please enter a username", "Format Error", ERROR_MESSAGE);
              return;
            }
            if (getDatabasePassword().length() == 0) {
              showMessageDialog(
                  AuthDialog.this, "Please enter a password", "Format Error", ERROR_MESSAGE);
              return;
            }
            okButtonClicked = true;
            setVisible(false);
          }
        });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    // Set up dialog contents
    labelPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 5, 5));
    inputPanel.setBorder(BorderFactory.createEmptyBorder(20, 5, 5, 20));

    labelPanel.setLayout(new GridLayout(2, 1));
    labelPanel.add(new JLabel("User Name: "));
    labelPanel.add(new JLabel("Password:"******"ESCAPE"), "exitAction");
    actionMap.put(
        "exitAction",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            System.exit(0);
          }
        });

    // Pack it all
    pack();

    // Center on the screen
    setLocationRelativeTo(null);
  }
Example #4
0
  /** Create the frame. */
  public SotrudnikDialog() {
    setTitle(
        "\u041D\u043E\u0432\u044B\u0439 \u0441\u043E\u0442\u0440\u0443\u0434\u043D\u0438\u043A");
    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    setBounds(100, 100, 450, 330);
    contentPane = new JPanel();
    contentPane.setBackground(new Color(255, 204, 255));
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel label_familiya = new JLabel("\u0424\u0430\u043C\u0438\u043B\u0438\u044F");
    label_familiya.setBounds(10, 37, 110, 14);
    contentPane.add(label_familiya);

    JLabel label_imya = new JLabel("\u0418\u043C\u044F");
    label_imya.setBounds(10, 62, 110, 14);
    contentPane.add(label_imya);

    JLabel label_otchestvo = new JLabel("\u041E\u0442\u0447\u0435\u0441\u0442\u0432\u043E");
    label_otchestvo.setBounds(10, 87, 110, 14);
    contentPane.add(label_otchestvo);

    textField_otchestvo = new JTextField();
    textField_otchestvo.setBounds(167, 84, 186, 20);
    contentPane.add(textField_otchestvo);
    textField_otchestvo.setColumns(10);

    textField_imya = new JTextField();
    textField_imya.setBounds(167, 58, 186, 20);
    contentPane.add(textField_imya);
    textField_imya.setColumns(10);

    textField_familiya = new JTextField();
    textField_familiya.setBounds(167, 33, 186, 20);
    contentPane.add(textField_familiya);
    textField_familiya.setColumns(10);

    JLabel label_data_priema =
        new JLabel(
            "\u0414\u0430\u0442\u0430 \u043F\u0440\u0438\u0435\u043C\u0430 \u043D\u0430 \u0440\u0430\u0431\u043E\u0442\u0443");
    label_data_priema.setBounds(10, 112, 147, 14);
    contentPane.add(label_data_priema);

    JLabel label_phone = new JLabel("\u0422\u0435\u043B\u0435\u0444\u043E\u043D");
    label_phone.setBounds(10, 137, 134, 14);
    contentPane.add(label_phone);

    JLabel label_doljnost = new JLabel("\u0414\u043E\u043B\u0436\u043D\u043E\u0441\u0442\u044C");
    label_doljnost.setBounds(10, 162, 140, 14);
    contentPane.add(label_doljnost);

    JLabel label_kvalification =
        new JLabel("\u041A\u0432\u0430\u043B\u0438\u0444\u0438\u043A\u0430\u0446\u0438\u044F");
    label_kvalification.setBounds(10, 190, 147, 14);
    contentPane.add(label_kvalification);

    textField_phone = new JTextField();
    textField_phone.setBounds(167, 134, 186, 20);
    contentPane.add(textField_phone);
    textField_phone.setColumns(10);

    textField_date.setBounds(167, 109, 186, 20);
    contentPane.add(textField_date);

    label_id_hidden.setFont(new Font("Tahoma", Font.BOLD, 12));
    label_id_hidden.setBounds(143, 11, 122, 14);
    contentPane.add(label_id_hidden);

    button_insert.setBounds(83, 230, 160, 23);
    contentPane.add(button_insert);

    button_cancel.setBounds(264, 230, 104, 23);
    contentPane.add(button_cancel);

    button_update.setBounds(83, 230, 160, 23);
    contentPane.add(button_update);

    JButton button_plus_doljnost = new JButton("+");
    button_plus_doljnost.addActionListener(
        new ActionListener() {
          @SuppressWarnings("deprecation")
          public void actionPerformed(ActionEvent arg0) {
            DoljnostDialog d = new DoljnostDialog();
            d.setTitle("Добавление должности");
            d.show();
          }
        });
    button_plus_doljnost.setBounds(359, 159, 41, 23);
    contentPane.add(button_plus_doljnost);

    JButton button_plus_kvalification = new JButton("+");
    button_plus_kvalification.addActionListener(
        new ActionListener() {
          @SuppressWarnings("deprecation")
          public void actionPerformed(ActionEvent arg0) {
            KvalificationDialog d = new KvalificationDialog();
            d.setTitle("Добавление квалификации");
            d.show();
          }
        });
    button_plus_kvalification.setBounds(359, 184, 41, 23);
    contentPane.add(button_plus_kvalification);

    JLabel label =
        new JLabel(
            "\u041F\u043E\u043B\u044F, \u043E\u0442\u043C\u0435\u0447\u0435\u043D\u043D\u044B\u0435 ");
    label.setBounds(60, 264, 122, 14);
    contentPane.add(label);

    JLabel label_3 = new JLabel("*");
    label_3.setForeground(Color.RED);
    label_3.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_3.setBounds(186, 264, 12, 14);
    contentPane.add(label_3);

    JLabel label_4 =
        new JLabel(
            "\u043E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u044B  \u0434\u043B\u044F \u0437\u0430\u043F\u043E\u043B\u043D\u0435\u043D\u0438\u044F!");
    label_4.setBounds(197, 264, 203, 14);
    contentPane.add(label_4);

    JLabel label_5 = new JLabel("*");
    label_5.setForeground(Color.RED);
    label_5.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_5.setBounds(356, 37, 12, 14);
    contentPane.add(label_5);

    JLabel label_1 = new JLabel("*");
    label_1.setForeground(Color.RED);
    label_1.setFont(new Font("Tahoma", Font.BOLD, 11));
    label_1.setBounds(356, 62, 12, 14);
    contentPane.add(label_1);

    comboBox_doljnost.setBounds(167, 159, 186, 20);
    contentPane.add(comboBox_doljnost);

    comboBox_kvalification.setBounds(167, 187, 186, 20);
    contentPane.add(comboBox_kvalification);

    // Actions for button "Добавить"
    button_insert.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (!textField_familiya.getText().equals("") && !textField_imya.getText().equals("")) {
              try {
                Sotrudnik s = new Sotrudnik();
                s.setFamiliya(textField_familiya.getText());
                s.setImya(textField_imya.getText());
                s.setOtchestvo(textField_otchestvo.getText());
                s.setData_priema(Date.valueOf(textField_date.getText()));
                s.setPhone(textField_phone.getText());
                Doljnost d = (Doljnost) comboBox_doljnost.getSelectedItem();
                s.setId_doljnosti(d.getId_doljnosti());
                Kvalification k = (Kvalification) comboBox_kvalification.getSelectedItem();
                s.setId_kvalification(k.getId_kvalification());

                DBClass db = new DBClass();
                db.sotrudnikUpsert(s, "INSERT");
                MyFrame.updateList();
                ZakazDialog.updateSotrudnik();
              } catch (SQLException e) {
                e.printStackTrace();
                JOptionPane.showMessageDialog(panelException, e.getMessage());
              } catch (ClassNotFoundException ee) {
                ee.printStackTrace();
                JOptionPane.showMessageDialog(panelException, ee.getMessage());
              } finally {
                dispose();
              }
            } else JOptionPane.showMessageDialog(null, "Введите обязательные параметры!");
          }
        });

    // Actions for button "Отмена"
    button_cancel.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            dispose();
          }
        });

    // Actions for button "Сохранить изменения"
    button_update.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent arg0) {
            if (!textField_familiya.getText().equals("")
                && !textField_imya.getText().equals("")
                && !textField_date.getText().equals("")) {
              if (textField_date.getText().length() == 10) {
                try {
                  Integer.parseInt((textField_date.getText().substring(0, 3)));
                  Integer.parseInt((textField_date.getText().substring(5, 6)));
                  Integer.parseInt((textField_date.getText().substring(8, 9)));

                  Sotrudnik s = new Sotrudnik();
                  s.setId_sotrudnika(Integer.parseInt(label_id_hidden.getText()));
                  s.setFamiliya(textField_familiya.getText());
                  s.setImya(textField_imya.getText());
                  s.setOtchestvo(textField_otchestvo.getText());
                  s.setPhone(textField_phone.getText());

                  Doljnost d = (Doljnost) comboBox_doljnost.getSelectedItem();
                  s.setId_doljnosti(d.getId_doljnosti());

                  Kvalification k = (Kvalification) comboBox_kvalification.getSelectedItem();
                  s.setId_kvalification(k.getId_kvalification());

                  DBClass db = new DBClass();
                  db.sotrudnikUpsert(s, "UPDATE");
                  MyFrame.updateList();
                  dispose();
                } catch (NumberFormatException e) {
                  JOptionPane.showMessageDialog(panelException, e.getMessage());
                } catch (SQLException e) {
                  // e.printStackTrace();
                  JOptionPane.showMessageDialog(panelException, e.getMessage());
                } catch (ClassNotFoundException ee) {
                  // ee.printStackTrace();
                  JOptionPane.showMessageDialog(panelException, ee.getMessage());
                }
              } else JOptionPane.showMessageDialog(null, "Введите дату в правильном формате!");
            } else JOptionPane.showMessageDialog(null, "Введите обязательные параметры!");
          }
        });
  }