Advertisement
Guest User

Untitled

a guest
Feb 18th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.78 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package desktopapp;
  7.  
  8. import Client.LoginCl;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import javax.swing.JOptionPane;
  12. import org.json.simple.JSONObject;
  13. import org.json.simple.parser.JSONParser;
  14. import org.json.simple.parser.ParseException;
  15.  
  16. /**
  17. *
  18. * @author pit
  19. */
  20. public class Login extends javax.swing.JFrame {
  21.  
  22. /**
  23. * Creates new form NewJFrame
  24. */
  25. public Login() {
  26. initComponents();
  27. }
  28.  
  29. /**
  30. * This method is called from within the constructor to initialize the form.
  31. * WARNING: Do NOT modify this code. The content of this method is always
  32. * regenerated by the Form Editor.
  33. */
  34. @SuppressWarnings("unchecked")
  35. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  36. private void initComponents() {
  37.  
  38. jTextField1 = new javax.swing.JTextField();
  39. jLabel1 = new javax.swing.JLabel();
  40. jLabel2 = new javax.swing.JLabel();
  41. jPasswordField1 = new javax.swing.JPasswordField();
  42. jButton1 = new javax.swing.JButton();
  43. jLabel3 = new javax.swing.JLabel();
  44. jLabel4 = new javax.swing.JLabel();
  45.  
  46. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  47.  
  48. jTextField1.addActionListener(new java.awt.event.ActionListener() {
  49. public void actionPerformed(java.awt.event.ActionEvent evt) {
  50. jTextField1ActionPerformed(evt);
  51. }
  52. });
  53.  
  54. jLabel1.setText("Username :");
  55.  
  56. jLabel2.setText("Password :");
  57.  
  58. jPasswordField1.addActionListener(new java.awt.event.ActionListener() {
  59. public void actionPerformed(java.awt.event.ActionEvent evt) {
  60. jPasswordField1ActionPerformed(evt);
  61. }
  62. });
  63.  
  64. jButton1.setText("LogIn");
  65. jButton1.addActionListener(new java.awt.event.ActionListener() {
  66. public void actionPerformed(java.awt.event.ActionEvent evt) {
  67. jButton1ActionPerformed(evt);
  68. }
  69. });
  70.  
  71. jLabel3.setFont(new java.awt.Font("Arial", 1, 12)); // NOI18N
  72. jLabel3.setForeground(new java.awt.Color(255, 102, 0));
  73. jLabel3.setText("Login Using your username and password :");
  74.  
  75. jLabel4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/desktopapp/Καταγραφή.PNG"))); // NOI18N
  76. jLabel4.addContainerListener(new java.awt.event.ContainerAdapter() {
  77. public void componentAdded(java.awt.event.ContainerEvent evt) {
  78. jLabel4ComponentAdded(evt);
  79. }
  80. });
  81.  
  82. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  83. getContentPane().setLayout(layout);
  84. layout.setHorizontalGroup(
  85. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  86. .addGroup(layout.createSequentialGroup()
  87. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  88. .addGroup(layout.createSequentialGroup()
  89. .addGap(59, 59, 59)
  90. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  91. .addComponent(jLabel3)
  92. .addGroup(layout.createSequentialGroup()
  93. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  94. .addComponent(jLabel1)
  95. .addComponent(jLabel2))
  96. .addGap(18, 18, 18)
  97. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  98. .addComponent(jPasswordField1)
  99. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
  100. .addGap(18, 18, 18)
  101. .addComponent(jButton1))))
  102. .addGroup(layout.createSequentialGroup()
  103. .addGap(122, 122, 122)
  104. .addComponent(jLabel4)))
  105. .addContainerGap(96, Short.MAX_VALUE))
  106. );
  107. layout.setVerticalGroup(
  108. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  109. .addGroup(layout.createSequentialGroup()
  110. .addGap(5, 5, 5)
  111. .addComponent(jLabel4)
  112. .addGap(18, 18, 18)
  113. .addComponent(jLabel3)
  114. .addGap(32, 32, 32)
  115. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  116. .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  117. .addComponent(jLabel1))
  118. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  119. .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  120. .addComponent(jLabel2)
  121. .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  122. .addComponent(jButton1))
  123. .addContainerGap(50, Short.MAX_VALUE))
  124. );
  125.  
  126. pack();
  127. }// </editor-fold>
  128.  
  129. private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
  130. // TODO add your handling code here:
  131. }
  132.  
  133. private void jPasswordField1ActionPerformed(java.awt.event.ActionEvent evt) {
  134. // TODO add your handling code here:
  135. }
  136.  
  137. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  138. try {
  139. // TODO add your handling code here:
  140. String username = jTextField1.getText();
  141. String password = jPasswordField1.getText();
  142. System.out.println(username+" "+ password);
  143. LoginCl log=new LoginCl();
  144. String paramet=null;
  145. paramet=log.getText(username, password);
  146. System.out.println(paramet);
  147. JSONParser parser = new JSONParser();
  148. Object obj = parser.parse(paramet);
  149. JSONObject jsonObject = (JSONObject) obj;
  150. String role=(String) jsonObject.get("Role");
  151. System.out.println( role);
  152.  
  153. if(role.equals("administrator") || role.equals("secretary")){
  154. Leitourgies welcome = new Leitourgies();
  155. welcome.setVisible(true);
  156. dispose();
  157. }
  158. else{
  159. JOptionPane.showMessageDialog(this,"Invalid Username or Password");
  160. }
  161. } catch (ParseException ex) {
  162. Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
  163. }
  164.  
  165.  
  166. }
  167.  
  168. private void jLabel4ComponentAdded(java.awt.event.ContainerEvent evt) {
  169. // TODO add your handling code here:
  170. }
  171.  
  172. /**
  173. * @param args the command line arguments
  174. */
  175. public static void main(String args[]) {
  176. /* Set the Nimbus look and feel */
  177. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  178. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  179. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  180. */
  181. try {
  182. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  183. if ("Nimbus".equals(info.getName())) {
  184. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  185. break;
  186. }
  187. }
  188. } catch (ClassNotFoundException ex) {
  189. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  190. } catch (InstantiationException ex) {
  191. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  192. } catch (IllegalAccessException ex) {
  193. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  194. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  195. java.util.logging.Logger.getLogger(Login.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  196. }
  197. //</editor-fold>
  198. //</editor-fold>
  199.  
  200. /* Create and display the form */
  201. java.awt.EventQueue.invokeLater(new Runnable() {
  202. public void run() {
  203. new Login().setVisible(true);
  204. }
  205. });
  206. }
  207.  
  208. // Variables declaration - do not modify
  209. private javax.swing.JButton jButton1;
  210. private javax.swing.JLabel jLabel1;
  211. private javax.swing.JLabel jLabel2;
  212. private javax.swing.JLabel jLabel3;
  213. private javax.swing.JLabel jLabel4;
  214. private javax.swing.JPasswordField jPasswordField1;
  215. private javax.swing.JTextField jTextField1;
  216. // End of variables declaration
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement