*/
Stuck? Need help? Ask questions on our forums.
*/

View java\java\bin\manoveg\server\Project.java

networking authentication program 1.0

Submitted By: manoveg
Rating: (Not rated) (Rate It)


package server;
import java.awt.*;
import java.util.*;
import java.sql.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class Project
{
 public static void main(String args[])
 {
  SFrontEnd frame1=new SFrontEnd();
  frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame1.show();
 }
}


class SFrontEnd extends JFrame implements ActionListener
{
 public static final int WIDTH=300;
 public static final int HEIGHT=300;
 private JTextField Username;
 private JPasswordField Password;
 private JTextField Department;
 private JLabel User;
 private JLabel Passw;
 private JLabel Dept;
 public String acommand1="";
 public SFrontEnd()
 {
  setTitle("Server");
  setSize(WIDTH,HEIGHT);
  Container contentPane=getContentPane();
  //JPanel panel=new JPanel();

  Username= new JTextField("",10);
  Username.setMaximumSize(Username.getPreferredSize());
  Box hbox1=Box.createHorizontalBox();

  User=new JLabel("USERNAME");
  hbox1.add(User);
  hbox1.add(Box.createHorizontalStrut(10));
  hbox1.add(Username);
  //panel.add(User);
  //panel.add(Username);
  Password= new JPasswordField("",10);
  Passw=new JLabel("PASSWORD");
  Password.setMaximumSize(Password.getPreferredSize());
  Password.setEchoChar('*');

  Box hbox2=Box.createHorizontalBox();
  hbox2.add(Passw);
  hbox2.add(Box.createHorizontalStrut(10));
  hbox2.add(Password);

  //panel.add(Passw);
  //panel.add(Password);
  Department= new JTextField("",20);
  Dept=new JLabel("DEPARTMENT");
  Department.setMaximumSize(Department.getPreferredSize());

  Box hbox3=Box.createHorizontalBox();
  hbox3.add(Dept);
  hbox3.add(Box.createHorizontalStrut(10));
  hbox3.add(Department);

  Box hbox4=Box.createHorizontalBox();
  JButton Okbutton=new JButton("OK");
  JButton Back = new JButton("BACK");
  hbox4.add(Okbutton);
  hbox4.add(Box.createGlue());
  hbox4.add(Back);
  Okbutton.addActionListener(this);
  Back.addActionListener(this);

  Box vbox=Box.createVerticalBox();
  vbox.add(hbox1);
  vbox.add(hbox2);
  vbox.add(hbox3);
  vbox.add(Box.createGlue());
  vbox.add(hbox4);
 // panel.add(Dept);
 // panel.add(Department);

  contentPane.add(vbox,BorderLayout.CENTER);

  }


 public static Connection dbConnection() throws SQLException , IOException
 {
  Properties props=new Properties();
  FileInputStream in=new FileInputStream("D:/java/java/bin/manoveg/server/database.properties");
  props.load(in);
  in.close();

  String drivers=props.getProperty("jdbc.drivers");
  if(drivers!=null)
  System.setProperty("jdbc.drivers",drivers);
  String url=props.getProperty("jdbc.url");
  String username=props.getProperty("jdbc.username");
  String password=props.getProperty("jdbc.password");
  return DriverManager.getConnection(url,username,password);

  }

  public void actionPerformed(ActionEvent ae)
  {

   acommand1=ae.getActionCommand();

   if(acommand1.equals("OK"))
   {

   SFrontEnd SFront = new SFrontEnd();
   String user=Username.getText();
   String pwd=new String(Password.getPassword());
   String dept=Department.getText();

   try
   {

   Connection conn = dbConnection();

   
   String strSQL="INSERT INTO mylogin VALUES ('"+user+"','"+pwd+"','"+dept+"')";
   


   Statement stat=conn.createStatement();
   stat.execute(strSQL);
   conn.close();
   DialogBox1 d = new DialogBox1(SFront,"Successfull","Records successfully added");
   d.setVisible(true);
   Username.setText("");
   Password.setText("");
   Department.setText("");
   }

   
   catch (SQLException ex)
   {
   DialogBox1 d2 = new DialogBox1(SFront,"Error","The Username already exists");
   d2.setVisible(true);
   Username.setText("");
   Password.setText("");
   Department.setText("");


   }
   catch (IOException ex)
   {
                System.out.println("error :"+ex);
   }
 
  }

   else
   
    if(acommand1.equals("BACK"))
    {
     SFrontEnd31 s5 = new SFrontEnd31();
     s5.setVisible(true);
     this.dispose();
    }



 }
}


class DialogBox1 extends Dialog implements ActionListener
{
 String msg="";
 DialogBox1(Frame parent , String title, String msg1)
 {
  super(parent, title , true);
  msg=msg1;
  setLayout(new FlowLayout(FlowLayout.LEFT));
  setSize(300,300);
  Button Ok = new Button("OK");
  add(Ok);
  Ok.addActionListener(this);
 }

 public void actionPerformed(ActionEvent ae1)
 {
  dispose();
 
  }

 public void paint(Graphics g)
 {
  g.drawString(msg,10,170);
  }
}

corner
© 1996-2008 CommunityHeaven LLC. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
North American business development: Nicolai Wadstrom. Publisher: Lars Hagelin.