Advertisement
Guest User

Untitled

a guest
Jan 8th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.75 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 Interface;
  7.  
  8. import Functions.Connect;
  9. import java.awt.Color;
  10. import static java.awt.SystemColor.text;
  11. import java.io.FileNotFoundException;
  12. import java.io.PrintWriter;
  13. import java.util.logging.Level;
  14. import java.util.logging.Logger;
  15.  
  16. public class Main extends javax.swing.JFrame {
  17.  
  18. /**
  19. * Creates new form Main
  20. */
  21. public Main() {
  22. initComponents();
  23. }
  24.  
  25. /**
  26. * This method is called from within the constructor to initialize the form.
  27. * WARNING: Do NOT modify this code. The content of this method is always
  28. * regenerated by the Form Editor.
  29. */
  30. @SuppressWarnings("unchecked")
  31. // <editor-fold defaultstate="collapsed" desc="Generated Code">
  32. private void initComponents() {
  33.  
  34. jPanel1 = new javax.swing.JPanel();
  35. labelDatabase = new javax.swing.JLabel();
  36. labelUsername = new javax.swing.JLabel();
  37. labelPassword = new javax.swing.JLabel();
  38. txtHost = new javax.swing.JTextField();
  39. txtUsername = new javax.swing.JTextField();
  40. btnConnect = new javax.swing.JButton();
  41. jLabel4 = new javax.swing.JLabel();
  42. jSeparator1 = new javax.swing.JSeparator();
  43. txtPassword = new javax.swing.JPasswordField();
  44. jCheckBox1 = new javax.swing.JCheckBox();
  45. jCheckBox2 = new javax.swing.JCheckBox();
  46. jCheckBox3 = new javax.swing.JCheckBox();
  47. FrameError = new javax.swing.JLabel();
  48. txtIP = new javax.swing.JTextField();
  49. jCheckBox4 = new javax.swing.JCheckBox();
  50. labelIP = new javax.swing.JLabel();
  51.  
  52. setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  53.  
  54. jPanel1.setBackground(new java.awt.Color(204, 204, 204));
  55.  
  56. labelDatabase.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\Host.png")); // NOI18N
  57. labelDatabase.setText("Data: *");
  58.  
  59. labelUsername.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\User.png")); // NOI18N
  60. labelUsername.setText("User: *");
  61.  
  62. labelPassword.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\Password.png")); // NOI18N
  63. labelPassword.setText("Pass:");
  64.  
  65. btnConnect.setText("Login");
  66. btnConnect.addMouseListener(new java.awt.event.MouseAdapter() {
  67. public void mouseClicked(java.awt.event.MouseEvent evt) {
  68. btnConnectMouseClicked(evt);
  69. }
  70. });
  71.  
  72. jLabel4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\Logo.png")); // NOI18N
  73.  
  74. jCheckBox1.setText("Save");
  75.  
  76. jCheckBox2.setText("Save");
  77.  
  78. jCheckBox3.setText("Save");
  79.  
  80. FrameError.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
  81. FrameError.setText("Welcome to Global Database");
  82. FrameError.setToolTipText("Error");
  83. FrameError.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
  84.  
  85. jCheckBox4.setText("Save");
  86.  
  87. labelIP.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\IP.png")); // NOI18N
  88. labelIP.setText("IP: *");
  89.  
  90. javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
  91. jPanel1.setLayout(jPanel1Layout);
  92. jPanel1Layout.setHorizontalGroup(
  93. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  94. .addGroup(jPanel1Layout.createSequentialGroup()
  95. .addContainerGap()
  96. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  97. .addComponent(jSeparator1)
  98. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  99. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  100. .addComponent(FrameError, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  101. .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
  102. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  103. .addComponent(labelDatabase)
  104. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
  105. .addComponent(labelPassword, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  106. .addComponent(labelUsername, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  107. .addComponent(labelIP))
  108. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  109. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  110. .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
  111. .addComponent(txtHost, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
  112. .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
  113. .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
  114. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  115. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
  116. .addComponent(jCheckBox2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  117. .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  118. .addComponent(jCheckBox3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  119. .addComponent(jCheckBox4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
  120. .addComponent(jLabel4))
  121. .addComponent(btnConnect, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  122. .addContainerGap())
  123. );
  124.  
  125. jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtHost, txtPassword, txtUsername});
  126.  
  127. jPanel1Layout.setVerticalGroup(
  128. jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  129. .addGroup(jPanel1Layout.createSequentialGroup()
  130. .addContainerGap()
  131. .addComponent(jLabel4)
  132. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  133. .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
  134. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
  135. .addComponent(FrameError)
  136. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  137. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  138. .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  139. .addComponent(jCheckBox4)
  140. .addComponent(labelIP))
  141. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  142. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  143. .addComponent(labelDatabase)
  144. .addComponent(txtHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  145. .addComponent(jCheckBox1))
  146. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  147. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  148. .addComponent(labelUsername)
  149. .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  150. .addComponent(jCheckBox2))
  151. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  152. .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
  153. .addComponent(labelPassword)
  154. .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  155. .addComponent(jCheckBox3))
  156. .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
  157. .addComponent(btnConnect)
  158. .addContainerGap())
  159. );
  160.  
  161. javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  162. getContentPane().setLayout(layout);
  163. layout.setHorizontalGroup(
  164. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  165. .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  166. );
  167. layout.setVerticalGroup(
  168. layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  169. .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  170. );
  171.  
  172. pack();
  173. }// </editor-fold>
  174.  
  175. private void btnConnectMouseClicked(java.awt.event.MouseEvent evt) {
  176. String IP, Database, Username, Password;
  177. int doProcess;
  178.  
  179. IP = txtIP.getText();
  180. Database = txtHost.getText();
  181. Username = txtUsername.getText();
  182. Password = txtPassword.getText();
  183.  
  184. if (txtIP.getText().equals("") || txtHost.getText().equals("") || txtUsername.getText().equals("")){
  185. System.out.println("[INFO]: Logging In...");
  186. FrameError.setText("[ERROR]: Please fill up the fields that has a mark (*).");
  187. labelIP.setForeground(Color.RED);
  188. labelDatabase.setForeground(Color.RED);
  189. labelUsername.setForeground(Color.RED);
  190. FrameError.setForeground(Color.RED);
  191. System.out.println(">>> Account Not Available or the Credentials is wrong.");
  192. } else {
  193. Connect Process = new Connect();
  194. doProcess = Process.doConnect(IP, Database, Username, Password);
  195.  
  196. switch (doProcess) {
  197. case 0:
  198. /* Set Notification */
  199. FrameError.setText("[ERROR]: Cannot Connect to Database!");
  200. FrameError.setForeground(Color.RED);
  201. break;
  202. case 1:
  203. /* Set Notification */
  204. Color customColor = new Color(10,10,255);
  205. FrameError.setText("[INFO]: Connected to Database Successfully!");
  206. FrameError.setForeground(customColor);
  207.  
  208. System.out.println("[INFO]: Logging In...");
  209.  
  210. /* Open new Frame */
  211. Session Frame = new Session();
  212. Frame.setVisible(true);
  213. dispose();
  214.  
  215. /* Save Session */
  216. try(
  217. PrintWriter out = new PrintWriter("session.txt")){
  218. out.println(IP);
  219. //out.println(Port);
  220. out.println(Database);
  221. out.println(Username);
  222. out.println(Password);
  223. } catch (FileNotFoundException ex) {
  224. Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
  225. }
  226. System.out.println(">>> Successfully logged in.");
  227. break;
  228. default:
  229. //table.UpdateTable();
  230. break;
  231. }
  232. }
  233. }
  234.  
  235. /**
  236. * @param args the command line arguments
  237. */
  238. public static void main(String args[]) {
  239. /* Set the Nimbus look and feel */
  240. //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  241. /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  242. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  243. */
  244. try {
  245. for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  246. if ("Nimbus".equals(info.getName())) {
  247. javax.swing.UIManager.setLookAndFeel(info.getClassName());
  248. break;
  249. }
  250. }
  251. } catch (ClassNotFoundException ex) {
  252. java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  253. } catch (InstantiationException ex) {
  254. java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  255. } catch (IllegalAccessException ex) {
  256. java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  257. } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  258. java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  259. }
  260. //</editor-fold>
  261.  
  262. /* Create and display the form */
  263. java.awt.EventQueue.invokeLater(new Runnable() {
  264. public void run() {
  265. new Main().setVisible(true);
  266. }
  267. });
  268. }
  269.  
  270. // Variables declaration - do not modify
  271. private javax.swing.JLabel FrameError;
  272. private javax.swing.JButton btnConnect;
  273. private javax.swing.JCheckBox jCheckBox1;
  274. private javax.swing.JCheckBox jCheckBox2;
  275. private javax.swing.JCheckBox jCheckBox3;
  276. private javax.swing.JCheckBox jCheckBox4;
  277. private javax.swing.JLabel jLabel4;
  278. private javax.swing.JPanel jPanel1;
  279. private javax.swing.JSeparator jSeparator1;
  280. private javax.swing.JLabel labelDatabase;
  281. private javax.swing.JLabel labelIP;
  282. private javax.swing.JLabel labelPassword;
  283. private javax.swing.JLabel labelUsername;
  284. private javax.swing.JTextField txtHost;
  285. private javax.swing.JTextField txtIP;
  286. private javax.swing.JPasswordField txtPassword;
  287. private javax.swing.JTextField txtUsername;
  288. // End of variables declaration
  289. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement