*/
Are you blogging on PH? Get your free blog.
*/

View java\java\bin\manoveg\server\Mainscreen.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 Mainscreen
{
 public static void main(String args[])
 {
  SFrontEnd3 frame1=new SFrontEnd3();
  frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame1.show();
 }
}


class SFrontEnd3 extends JFrame implements ActionListener
{
 public static final int WIDTH=300;
 public static final int HEIGHT=300;
 private JTextField Username;
 private JPasswordField Password;
 private JLabel User;
 private JLabel Passw;
 String acommand1="";
 Object acommand2="";
JButton Okbutton;
JButton Back;
 public SFrontEnd3()
 {
  setTitle("Server");
  setSize(WIDTH,HEIGHT);
  Container contentPane=getContentPane();

  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);

  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);


  Box hbox4=Box.createHorizontalBox();
   Okbutton=new JButton("OK");
   Back = new JButton("CLOSE");
   hbox4.add(Okbutton);
   hbox4.add(Box.createHorizontalStrut(10));
   hbox4.add(Back);
 
 
  Okbutton.addActionListener(this);
  Back.addActionListener(this);
 

  Box vbox=Box.createVerticalBox();
  vbox.add(hbox1);
  vbox.add(hbox2);
  vbox.add(Box.createGlue());
  vbox.add(hbox4);

  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"))
    {
       
     
   //SFrontEnd3 SFront = new SFrontEnd3();
   String user=Username.getText();
   String pwd=new String(Password.getPassword());
   String dmuser="";
   String dmpwd="";
   boolean flag=false;

   try
   {

   Connection conn = dbConnection();

    Statement stat=conn.createStatement();
   ResultSet rs = stat.executeQuery("select * from administrator");
   while(rs.next())
   {
    dmuser=rs.getString("username");
    dmpwd=rs.getString("password");
    if(user.equalsIgnoreCase(dmuser))
    {
     if(pwd.equalsIgnoreCase(dmpwd))
     {
      flag=true;
      break;
     }
    }
   }


     if(flag==false)
     {
      throw new SQLException();
     }

    if(flag==true)
    {
     SFrontEnd31 s4 = new SFrontEnd31();
     s4.setVisible(true);
     this.setVisible(false);
     }

   conn.close();
   //DialogBox21 d = new DialogBox21(SFront,"Successfull","Records successfully added");
  // d.setVisible(true);
   //Username.setText("");
   //Password.setText("");

   }
   catch (SQLException ex)
   {
   DialogBox21 d2 = new DialogBox21(new SFrontEnd3(),"Error","The Username or Password is Incorrect");
   d2.setVisible(true);
   Username.setText("");
   Password.setText("");

   }
   catch (IOException ex)
   {
   }
 
}
 else if(acommand1.equals("CLOSE"))
{
 System.exit(0);
}

 }
}


class DialogBox21 extends Dialog implements ActionListener
{
 String msg="";
 DialogBox21(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.