Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package Interface;
- import Functions.Connect;
- import java.awt.Color;
- import static java.awt.SystemColor.text;
- import java.io.FileNotFoundException;
- import java.io.PrintWriter;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class Main extends javax.swing.JFrame {
- /**
- * Creates new form Main
- */
- public Main() {
- initComponents();
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- labelDatabase = new javax.swing.JLabel();
- labelUsername = new javax.swing.JLabel();
- labelPassword = new javax.swing.JLabel();
- txtHost = new javax.swing.JTextField();
- txtUsername = new javax.swing.JTextField();
- btnConnect = new javax.swing.JButton();
- jLabel4 = new javax.swing.JLabel();
- jSeparator1 = new javax.swing.JSeparator();
- txtPassword = new javax.swing.JPasswordField();
- jCheckBox1 = new javax.swing.JCheckBox();
- jCheckBox2 = new javax.swing.JCheckBox();
- jCheckBox3 = new javax.swing.JCheckBox();
- FrameError = new javax.swing.JLabel();
- txtIP = new javax.swing.JTextField();
- jCheckBox4 = new javax.swing.JCheckBox();
- labelIP = new javax.swing.JLabel();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jPanel1.setBackground(new java.awt.Color(204, 204, 204));
- labelDatabase.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\Host.png")); // NOI18N
- labelDatabase.setText("Data: *");
- labelUsername.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\User.png")); // NOI18N
- labelUsername.setText("User: *");
- labelPassword.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\Password.png")); // NOI18N
- labelPassword.setText("Pass:");
- btnConnect.setText("Login");
- btnConnect.addMouseListener(new java.awt.event.MouseAdapter() {
- public void mouseClicked(java.awt.event.MouseEvent evt) {
- btnConnectMouseClicked(evt);
- }
- });
- jLabel4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\Logo.png")); // NOI18N
- jCheckBox1.setText("Save");
- jCheckBox2.setText("Save");
- jCheckBox3.setText("Save");
- FrameError.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
- FrameError.setText("Welcome to Global Database");
- FrameError.setToolTipText("Error");
- FrameError.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
- jCheckBox4.setText("Save");
- labelIP.setIcon(new javax.swing.ImageIcon("C:\\Users\\Z\\Documents\\NetBeansProjects\\DBGlobalConnection\\Images\\IP.png")); // NOI18N
- labelIP.setText("IP: *");
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(jSeparator1)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(FrameError, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(labelDatabase)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
- .addComponent(labelPassword, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(labelUsername, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addComponent(labelIP))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txtHost, javax.swing.GroupLayout.PREFERRED_SIZE, 223, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
- .addComponent(jCheckBox2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jCheckBox1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jCheckBox3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jCheckBox4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
- .addComponent(jLabel4))
- .addComponent(btnConnect, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addContainerGap())
- );
- jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtHost, txtPassword, txtUsername});
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jLabel4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(FrameError)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(txtIP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jCheckBox4)
- .addComponent(labelIP))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(labelDatabase)
- .addComponent(txtHost, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jCheckBox1))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(labelUsername)
- .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jCheckBox2))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(labelPassword)
- .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(jCheckBox3))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(btnConnect)
- .addContainerGap())
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void btnConnectMouseClicked(java.awt.event.MouseEvent evt) {
- String IP, Database, Username, Password;
- int doProcess;
- IP = txtIP.getText();
- Database = txtHost.getText();
- Username = txtUsername.getText();
- Password = txtPassword.getText();
- if (txtIP.getText().equals("") || txtHost.getText().equals("") || txtUsername.getText().equals("")){
- System.out.println("[INFO]: Logging In...");
- FrameError.setText("[ERROR]: Please fill up the fields that has a mark (*).");
- labelIP.setForeground(Color.RED);
- labelDatabase.setForeground(Color.RED);
- labelUsername.setForeground(Color.RED);
- FrameError.setForeground(Color.RED);
- System.out.println(">>> Account Not Available or the Credentials is wrong.");
- } else {
- Connect Process = new Connect();
- doProcess = Process.doConnect(IP, Database, Username, Password);
- switch (doProcess) {
- case 0:
- /* Set Notification */
- FrameError.setText("[ERROR]: Cannot Connect to Database!");
- FrameError.setForeground(Color.RED);
- break;
- case 1:
- /* Set Notification */
- Color customColor = new Color(10,10,255);
- FrameError.setText("[INFO]: Connected to Database Successfully!");
- FrameError.setForeground(customColor);
- System.out.println("[INFO]: Logging In...");
- /* Open new Frame */
- Session Frame = new Session();
- Frame.setVisible(true);
- dispose();
- /* Save Session */
- try(
- PrintWriter out = new PrintWriter("session.txt")){
- out.println(IP);
- //out.println(Port);
- out.println(Database);
- out.println(Username);
- out.println(Password);
- } catch (FileNotFoundException ex) {
- Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
- }
- System.out.println(">>> Successfully logged in.");
- break;
- default:
- //table.UpdateTable();
- break;
- }
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Main().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JLabel FrameError;
- private javax.swing.JButton btnConnect;
- private javax.swing.JCheckBox jCheckBox1;
- private javax.swing.JCheckBox jCheckBox2;
- private javax.swing.JCheckBox jCheckBox3;
- private javax.swing.JCheckBox jCheckBox4;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JSeparator jSeparator1;
- private javax.swing.JLabel labelDatabase;
- private javax.swing.JLabel labelIP;
- private javax.swing.JLabel labelPassword;
- private javax.swing.JLabel labelUsername;
- private javax.swing.JTextField txtHost;
- private javax.swing.JTextField txtIP;
- private javax.swing.JPasswordField txtPassword;
- private javax.swing.JTextField txtUsername;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement