hi,
I am new to Java and still learning it.. I am trying to make a login screen which checks the authencity of the user.. the database is in the Access with fields username and password.. Can anyone help me with the coding.. I know i am asking too much but... if you can that i'll be very greatful..
I have done this coding, i think you can add in it...
---------import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.plaf.metal.*;
import java.sql.*;
public class Screen extends JFrame implements ActionListener
{
public Screen()
{
JPanel contentpane=(JPanel)getContentPane();
contentpane.setLayout(new FlowLayout());
JLabel username= new JLabel("UserName:"
JTextField txtuser= new JTextField(18);
JLabel password= new JLabel("Password:"
JPasswordField txtpass = new JPasswordField(18);
txtpass.setEchoChar('*');
JButton login= new JButton("Login"
login.addActionListener(this);
login.setActionCommand("Login"
JButton cancel= new JButton("Cancel"
cancel.addActionListener(this);
cancel.setActionCommand("Cancel"
contentpane.add(username);
contentpane.add(txtuser);
contentpane.add(password);
contentpane.add(txtpass);
contentpane.add(login);
contentpane.add(cancel);
addWindowListener(new Screen.WindowEventHandler());
}
static public void main(String[] args)
{
Screen scr= new Screen();
scr.setSize(new Dimension(300,140));
scr.setTitle("Login Screen"
scr.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand()=="Login"
{
//Defining the Database Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
//Making the connection
String url = "jdbcdbc:doctor";
Connection con = DriverManager.getConnection(url, "", ""
//I AM IN A FIX OVER HERE IT IS GIVING ERROR AND I DON'T KNOW HOW TO CARRY ON WITH IT..
//Executing the Statement
Statement stmt = con.createStatement();
stmt.executeUpdate( )
System.out.println("Login is pressed"
}
if (e.getActionCommand()=="Cancel"
System.out.println("Cancel is pressed"
}
public class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
}
Thank you in advance..
I am new to Java and still learning it.. I am trying to make a login screen which checks the authencity of the user.. the database is in the Access with fields username and password.. Can anyone help me with the coding.. I know i am asking too much but... if you can that i'll be very greatful..
I have done this coding, i think you can add in it...
---------import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.plaf.metal.*;
import java.sql.*;
public class Screen extends JFrame implements ActionListener
{
public Screen()
{
JPanel contentpane=(JPanel)getContentPane();
contentpane.setLayout(new FlowLayout());
JLabel username= new JLabel("UserName:"
JTextField txtuser= new JTextField(18);
JLabel password= new JLabel("Password:"
JPasswordField txtpass = new JPasswordField(18);
txtpass.setEchoChar('*');
JButton login= new JButton("Login"
login.addActionListener(this);
login.setActionCommand("Login"
JButton cancel= new JButton("Cancel"
cancel.addActionListener(this);
cancel.setActionCommand("Cancel"
contentpane.add(username);
contentpane.add(txtuser);
contentpane.add(password);
contentpane.add(txtpass);
contentpane.add(login);
contentpane.add(cancel);
addWindowListener(new Screen.WindowEventHandler());
}
static public void main(String[] args)
{
Screen scr= new Screen();
scr.setSize(new Dimension(300,140));
scr.setTitle("Login Screen"
scr.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand()=="Login"
{
//Defining the Database Driver
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"
//Making the connection
String url = "jdbcdbc:doctor";
Connection con = DriverManager.getConnection(url, "", ""
//I AM IN A FIX OVER HERE IT IS GIVING ERROR AND I DON'T KNOW HOW TO CARRY ON WITH IT..
//Executing the Statement
Statement stmt = con.createStatement();
stmt.executeUpdate( )
System.out.println("Login is pressed"
}
if (e.getActionCommand()=="Cancel"
System.out.println("Cancel is pressed"
}
public class WindowEventHandler extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
}
Thank you in advance..