Raizekas

Untitled

Mar 19th, 2021
34
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package gui.formos.paneles;
  2.  
  3. import db.entities.Vartotojas;
  4. import db.veiksmai.DuombazesVeiksmai;
  5.  
  6. import javax.swing.*;
  7. import java.awt.*;
  8. import java.awt.event.ActionEvent;
  9. import java.awt.event.ActionListener;
  10. import java.net.PasswordAuthentication;
  11. import java.sql.Connection;
  12. import java.sql.SQLException;
  13.  
  14. public class LoginPanele extends JPanel
  15. {
  16. private JButton loginButton;
  17. private JTextField loginText;
  18. private JLabel loginLabel;
  19. private JPasswordField pswText;
  20. private JLabel pswLabel;
  21.  
  22. private JFrame mainFrame; // reference/adresas i main frame objekta, kuris yra main programos dalyje
  23. private MeniuPanele meniuPanele; // reference/adresas i meniu panele, kuria iskvies paspaudus mygtuka (jei duomenys yra teisingai ivesti)
  24.  
  25. public LoginPanele()
  26. {
  27. loginButton = new JButton();
  28. loginText = new JTextField();
  29. loginLabel = new JLabel();
  30. pswText = new JPasswordField();
  31. pswLabel = new JLabel();
  32. }
  33.  
  34.  
  35. public void nustatytiPanele()
  36. {
  37. // Mygtuko parametrai
  38. loginButton.setText("Prisijungti");
  39. loginButton.setFont(new Font("Serif", Font.BOLD, 36));
  40. loginButton.addActionListener(new LoginButtonListener());
  41.  
  42.  
  43. // Login labelio parmaetrai
  44. loginLabel.setText("Įveskite savo prisijungimo vardą:");
  45.  
  46. // Slaptažodžio labelio parametrai
  47. pswLabel.setText("Įveskite savo slaptažodį:");
  48.  
  49. // Paneles nustatymai
  50. this.setLayout(new GridBagLayout());
  51. GridBagConstraints c = new GridBagConstraints();
  52.  
  53.  
  54.  
  55. //------------------Layout parametrai--------------
  56. // Login labelio LAYOUT parametrai
  57. c.gridx = 1;
  58. c.gridy = 1;
  59. c.fill = GridBagConstraints.BOTH;
  60. loginLabel.setPreferredSize(new Dimension(100, 30));
  61. this.add(loginLabel, c);
  62.  
  63. // Login texto LAYOUT parametrai
  64. c.gridx = 2;
  65. c.gridy = 1;
  66. c.gridwidth = 2;
  67. c.fill = GridBagConstraints.BOTH;
  68. c.insets = new Insets(0, 0, 20, 0);
  69. loginText.setPreferredSize(new Dimension(300, 30));
  70. this.add(loginText, c);
  71.  
  72.  
  73. // Psw labelio LAYOUR parametrai
  74. c.gridx = 1;
  75. c.gridy = 2;
  76. c.gridwidth = 1;
  77. c.fill = GridBagConstraints.BOTH;
  78. pswLabel.setPreferredSize(new Dimension(100, 30));
  79. this.add(pswLabel, c);
  80.  
  81.  
  82. // Psw teksto LAYOUT parametrai
  83. c.gridx = 2;
  84. c.gridy = 2;
  85. c.gridwidth = 2;
  86. c.fill = GridBagConstraints.BOTH;
  87. this.add(pswText, c);
  88.  
  89.  
  90. // Mygtuko LAYOUT parametrai
  91. c.gridx = 2;
  92. c.gridy = 3;
  93. c.gridwidth = 1;
  94. c.fill = GridBagConstraints.BOTH;
  95. loginButton.setPreferredSize(new Dimension(200, 50));
  96. this.add(loginButton, c);
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104. // Komponentu sudejimas i panele
  105. // this.add(loginLabel);
  106. // this.add(loginText);
  107. // this.add(pswLabel);
  108. // this.add(pswText);
  109. // this.add(loginButton);
  110. }
  111.  
  112. class LoginButtonListener implements ActionListener
  113. {
  114. private int arTinkaVart; // ar tinka ivestas vartotojas paspaudus mygtuka
  115. public LoginButtonListener() {}
  116.  
  117. @Override
  118. public void actionPerformed(ActionEvent e)
  119. {
  120. String login = loginText.getText();
  121. char[] pswChar = pswText.getPassword();
  122. String psw = String.valueOf(pswChar);
  123.  
  124. Vartotojas ivestasVart = new Vartotojas(login, psw);
  125. arTinkaVart = 0;
  126. try
  127. {
  128. Connection jungtis = DuombazesVeiksmai.sukurtiDuombaze();
  129. arTinkaVart = DuombazesVeiksmai.palygintiVartDuomenis(jungtis, ivestasVart);
  130.  
  131. if (arTinkaVart == 1)
  132. {
  133. mainFrame.getContentPane().removeAll();
  134. mainFrame.repaint();
  135.  
  136. meniuPanele.nustatytiPanele();
  137.  
  138. mainFrame.getContentPane().add(meniuPanele);
  139. mainFrame.repaint();
  140. mainFrame.printAll(mainFrame.getGraphics());
  141. }
  142. }
  143. catch (SQLException exc)
  144. {
  145. exc.printStackTrace();
  146. System.out.println("Nepavyko prisijungti prie DB");
  147. }
  148.  
  149. }
  150.  
  151.  
  152. }
  153.  
  154.  
  155.  
  156. //----------------Getteriai setteriai
  157.  
  158.  
  159. public void setMainFrame(JFrame mainFrame)
  160. {
  161. this.mainFrame = mainFrame;
  162. }
  163.  
  164. public void setMeniuPanele(MeniuPanele meniuPanele)
  165. {
  166. this.meniuPanele = meniuPanele;
  167. }
  168. }
  169.  
RAW Paste Data