Package Gui

Source Code of Gui.AddUser

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* AddUser.java
*
* Created on Dec 4, 2010, 5:10:31 PM
*/

package Gui;
import client.ChatClient;

import common.ChatIF;

import java.awt.Color;
import java.awt.Rectangle;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

import logic.obj;

import Gui.*;
import client.ChatClient;
import client.User;

import common.ChatIF;

/**
*
* @author Kipi
*/
public class AddUser extends javax.swing.JFrame {
    private JLabel jLabel666 = null;
  public static  String user; // username
    public static String password ; // password
    public static  String firstname; // first name
    public static String lastname ; // last name
    public static  int age; // age
    public static String address ; // address
    public static  int phone; // phone
    public static int online ; // online
    public static  int priv; // privilege
    String[] data = new String[10];
    public static String host;  // Remove server IP address
    public static ChatClient client;
    private  ChatIF ChatIF = null;
    public static boolean resultAv;
    public static int res = 0;
    //
    /** Creates new form AddUser */
    public AddUser() {
        initComponents();
    }

    public void  sendform(boolean result)
    {
      if(result == false)
      {
        res=0; // if username already exists
      }
      else
        res=1; // if not
   
    }
    public void Available(boolean result){
      if(result == true){
       
        res=1;
      }
        else {
        res=0;
       
       
       
    }
    /** 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">//GEN-BEGIN:initComponents
    private void initComponents() {
     
     
      this.setSize(1000, 700);
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jTextField4 = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jTextField7 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jComboBox2 = new javax.swing.JComboBox();
        jComboBox3 = new javax.swing.JComboBox();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jPasswordField1 = new javax.swing.JPasswordField();
        jPasswordField2 = new javax.swing.JPasswordField();
        jLabel9 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("I-Book : Add User");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });
        getContentPane().setLayout(null);

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel2.setText("Login Name:");
        getContentPane().add(jLabel2);
        jLabel2.setBounds(110, 130, 80, 30);

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel3.setText("Password:");
        getContentPane().add(jLabel3);
        jLabel3.setBounds(110, 220, 100, 17);

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel4.setText("Re-enter password:");
        getContentPane().add(jLabel4);
        jLabel4.setBounds(110, 260, 130, 17);

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel5.setText("First Name:");
        getContentPane().add(jLabel5);
        jLabel5.setBounds(110, 300, 90, 17);

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel6.setText("Last Name:");
        getContentPane().add(jLabel6);
        jLabel6.setBounds(110, 340, 80, 17);

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel7.setText("Birth Date:");
        getContentPane().add(jLabel7);
        jLabel7.setBounds(110, 380, 70, 17);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel8.setText("Address:");
        getContentPane().add(jLabel8);
        jLabel8.setBounds(110, 420, 80, 17);

        jTextField1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField1ActionPerformed(evt);
            }
        });
        getContentPane().add(jTextField1);
        jTextField1.setBounds(260, 140, 130, 20);
        getContentPane().add(jTextField4);
        jTextField4.setBounds(260, 300, 130, 20);

        jTextField5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField5ActionPerformed(evt);
            }
        });
        getContentPane().add(jTextField5);
        jTextField5.setBounds(260, 340, 130, 20);
        getContentPane().add(jTextField7);
        jTextField7.setBounds(260, 420, 130, 20);

        jLabel10.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel10.setText("Create new account:");
        getContentPane().add(jLabel10);
        jLabel10.setBounds(110, 30, 180, 50);

        jButton1.setText("check availability");
        jButton1.setBorder(null);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1);
        jButton1.setBounds(250, 180, 150, 20);

        jLabel11.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Pictures/account4.png"))); // NOI18N
        getContentPane().add(jLabel11);
        jLabel11.setBounds(450, 10, 70, 100);

        jButton2.setText("Submit");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton2);
        jButton2.setBounds(230, 500, 80, 30);

        jButton3.setText("Cancel");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton3);
        jButton3.setBounds(340, 500, 80, 30);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "month", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        getContentPane().add(jComboBox1);
        jComboBox1.setBounds(230, 380, 70, 20);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "day", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        getContentPane().add(jComboBox2);
        jComboBox2.setBounds(300, 380, 70, 20);

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "year", "2010", "2009", "2008", "2007", "2006", "2005", "2004", "2003", "2002", "2001", "2000", "1999", "1998", "1997", "1996", "1995", "1994", "1993", "1992", "1991", "1990", "1989", "1988", "1987", "1986", "1985", "1984", "1983", "1982", "1981", "1980", "1979", "1978", "1977", "1976", "1975", "1974", "1973", "1972", "1971", "1970", "1969", "1968", "1967", "1966", "1965", "1964", "1963", "1962", "1961", "1960", "1959", "1958", "1957", "1956", "1955", "1954", "1953", "1952", "1951", "1950", "1949", "1948", "1947", "1946", "1945", "1944", "1943", "1942", "1941", "1940", "1939", "1938", "1937", "1936", "1935", "1934", "1933", "1932", "1931", "1930", "1929", "1928", "1927", "1926", "1925", "1924", "1923", "1922", "1921", "1920", " " }));
        getContentPane().add(jComboBox3);
        jComboBox3.setBounds(370, 380, 80, 20);

        jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Pictures/X.gif"))); // NOI18N
        jLabel12.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        getContentPane().add(jLabel12);
        jLabel12.setBounds(400, 140, 30, 20);

        jLabel13.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Pictures/Y.gif"))); // NOI18N
        jLabel13.setVerticalAlignment(javax.swing.SwingConstants.TOP);
        getContentPane().add(jLabel13);
        jLabel13.setBounds(400, 140, 20, 20);

        jLabel14.setForeground(new java.awt.Color(204, 0, 0));
        jLabel14.setText("Login Name already taken");
        getContentPane().add(jLabel14);
        jLabel14.setBounds(430, 140, 150, 20);

        jLabel15.setForeground(new java.awt.Color(0, 255, 51));
        jLabel15.setText("Available");
        getContentPane().add(jLabel15);
        jLabel15.setBounds(430, 140, 60, 14);

        jLabel16.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel16.setText("Host:");
        getContentPane().add(jLabel16);
        jLabel16.setBounds(110, 100, 33, 17);

        jTextField6.setText("localhost");
        jTextField6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField6ActionPerformed(evt);
            }
        });
        getContentPane().add(jTextField6);
        jTextField6.setBounds(260, 100, 130, 20);
        getContentPane().add(jPasswordField1);
        jPasswordField1.setBounds(260, 220, 130, 20);

        jPasswordField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jPasswordField2ActionPerformed(evt);
            }
        });
        getContentPane().add(jPasswordField2);
        jPasswordField2.setBounds(260, 260, 130, 20);

        jLabel9.setForeground(new java.awt.Color(204, 0, 0));
        jLabel9.setText("* required fields are missing");
        getContentPane().add(jLabel9);
        jLabel9.setBounds(110, 460, 200, 14);

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Pictures/Blue1.jpg"))); // NOI18N
        getContentPane().add(jLabel1);
        jLabel1.setBounds(0, 0, 1600, 1200);



        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-638)/2, (screenSize.height-659)/2, 638, 659);
        jLabel12.hide();// hide x
        jLabel13.hide();// hide v
        jLabel14.hide();// hide taken
        jLabel15.hide();// hide available
        jLabel9.hide(); // hide required
   
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
      //  setExtendedState(JFrame.MAXIMIZED_BOTH);
        jLabel12.hide();// hide x
        jLabel13.hide();// hide v
        jLabel14.hide();// hide taken
        jLabel15.hide();// hide available
        jLabel9.hide(); // hide required
       
       /*
        jLabel12.setVisible(false); // hide x
        jLabel13.setVisible(false); // hide v
        jLabel14.setVisible(false); // hide taken
        jLabel15.setVisible(false); // hide available
       
        */
    }//GEN-LAST:event_formWindowOpened

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
    }                                           

    private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField5ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField5ActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
      this.dispose();
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField6ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField6ActionPerformed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
         User user1=new User("","","","","",0,0,"","")// Hit Cancel - returns to Login
        Login s=new Login(user1,"");
             this.setVisible(false);
             s.setVisible(true);
            
         
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
      data[1]=  jTextField1.getText(); //username
      host = jTextField6.getText(); // host
      //JOptionPane.showMessageDialog(null," " + data[1] + " already logged in","ERROR",JOptionPane.ERROR_MESSAGE);
        jLabel12.hide();// hide x
        jLabel13.hide();// hide v
        jLabel14.hide();// hide taken
      jLabel12.setVisible(false); // hide x
        jLabel13.setVisible(false); // hide v
        jLabel14.setVisible(false); // hide taken
        jLabel15.setVisible(false); // hide available
      int connected = 1;
        if(data[1].isEmpty())
      {
        jLabel12.setVisible(true);
        connected = 0;
      }
   //   data[0] = "check";
       obj logdt = new obj();
      logdt.setType("check");
      logdt.setParam(0,data[1]);//user
      
      try
      {
         client= new ChatClient(host,5555,ChatIF);
      } // end try
      catch(IOException exception)
      {
        JOptionPane.showMessageDialog(null,"Error: Can't setup connection!","Error",JOptionPane.CLOSED_OPTION);
        connected = 0; // failed to connect
      } // end catch
      if(connected == 1)
          client.handleMessageFromClientUI(logdt);
    
      try {
         Thread.sleep(1000);
         } // end try
      catch (InterruptedException ex) {
         Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
     } // end catch
        if(res == 1)
        {
          jLabel13.setVisible(true);
        //  jLabel15.setVisible(true);
        }
       
        if(res == 0)
        {
          jLabel12.setVisible(true);
          //jLabel14.setVisible(true);
        }
       
     
     
     
     
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jPasswordField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPasswordField2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jPasswordField2ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
      int ErrFlag = 0;
      int connected = 1;
     
      jLabel3.setForeground(Color.black);
      jLabel4.setForeground(Color.black);
      jLabel5.setForeground(Color.black);
      jLabel6.setForeground(Color.black);
      jLabel7.setForeground(Color.black);
      jLabel8.setForeground(Color.black);

     
      /* Retrieving data from text fields */
      data[0]="AddUser";
      data[1]=  jTextField1.getText(); //username
      data[2]=  jPasswordField1.getText(); //password
      data[3]=  jPasswordField2.getText(); //password2
      data[4]=  jTextField4.getText(); //first name
      data[5]=  jTextField5.getText(); //last name
      host = jTextField6.getText(); // host
      data[6]=  jTextField7.getText(); //address
      data[7]""+(String)jComboBox3.getSelectedItem()+"-"+(String)jComboBox2.getSelectedItem()+"-"+(String)jComboBox1.getSelectedItem()+""//address
     
      /* Check for input errors */
     
        if(data[1].isEmpty())
        {
          ErrFlag = 1;
          jLabel2.setForeground(Color.red);
        }
     
      if(!data[2].equals(data[3]) || jPasswordField2.getText().length()==0 || jPasswordField1.getText().length()==0) // if passwords dont match
      {
      ErrFlag = 1;
      jLabel3.setForeground(Color.red);
      jLabel4.setForeground(Color.red);
      }
      if(jTextField1.getText().length()==0) // if login name is empty
      {
        jLabel2.setForeground(Color.red);
        ErrFlag=1;
      }
      if(jTextField4.getText().length()==0) // if first name is empty
      {
        jLabel5.setForeground(Color.red);
        ErrFlag=1;
      }
      if(jTextField5.getText().length()==0) // if last name is empty
      {
        jLabel6.setForeground(Color.red);
        ErrFlag=1;
      }
      if(jTextField7.getText().length()==0) // if address is empty
      {
        jLabel8.setForeground(Color.red);
        ErrFlag=1;
      }
      if(jComboBox1.getSelectedIndex()==0 || jComboBox2.getSelectedIndex()==0 || jComboBox3.getSelectedIndex()==0)   // if birth date is empty
      {
        jLabel7.setForeground(Color.red);
        ErrFlag=1;
      }
      if(ErrFlag==1)
      {
        jLabel9.setVisible(true);
        connected = 0;
      }
     
      /*   */
   
 
      try
      {
         client= new ChatClient(host,5555,ChatIF);
      } // end try
      catch(IOException exception)
      {
        JOptionPane.showMessageDialog(null,"Error: Can't setup connection!","Error",JOptionPane.CLOSED_OPTION);
        connected = 0; // failed to connect
      } // end catch
      if(connected == 1)
      {
          client.handleMessageFromClientUI(data);
    
      try {
         Thread.sleep(1000);
         } // end try
      catch (InterruptedException ex) {
         Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
     } // end catch
        if(res == 1)
        {
          Login L=new Login("","localhost",0);
           
          L.setLocationRelativeTo(null); //put frame at center
           L.setVisible(true);
//          MainWindow s=new MainWindow();
        this.setVisible(false);
//        s.setLocationRelativeTo(null);
//        s.setVisible(true);
        }
       
        if(res == 0)
        {
          jLabel2.setForeground(Color.red);
         
        }
      }// end if connected
     
     
     
   
   
   
   
    } // end event
                                                                 

    /**
    * @param args the command line arguments
   
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new AddUser().setVisible(true);

            }
        });
    }
*/
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPasswordField jPasswordField1;
    private javax.swing.JPasswordField jPasswordField2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    // End of variables declaration//GEN-END:variables

}
TOP

Related Classes of Gui.AddUser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.