Sie sind auf Seite 1von 7

import java.awt.

*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.net.*;
class A
{
static JFrame F3;
static JButton B3,B4,B5,B6;
JFrame F,F1;
JLabel L1,L2,L3,L4;
JTextField T,T1;
JPasswordField P,P1;
JButton B,B1,B2;
ResultSet rs;
Statement st;
A()
{
F= new JFrame("Log In");
F1= new JFrame("Register");
L1= new JLabel("USER NAME");
L2= new JLabel("PASSWORD");
L3= new JLabel("USER NAME");
L4= new JLabel("PASSWORD");
T=new JTextField(10);
T1=new JTextField(10);
P=new JPasswordField(10);
P1=new JPasswordField(10);
B=new JButton("Log In");
B1=new JButton("Sign Up");
B2=new JButton("Register");

F.add(L1);
F.add(T);
F.add(L2);
F.add(P);
F.add(B);
F.add(B1);
F.setLayout(new FlowLayout());
F.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
F.setVisible(true);
F.setSize(200,200);
F1.add(L3);
F1.add(T1);
F1.add(L4);
F1.add(P1);
F1.add(B2);
F1.setSize(200,200);
F1.setLayout(new FlowLayout());
connect();

B1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ea)
{
F1.setVisible(true);
}
}
);
B2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent eb)
{
try
{

String u=T1.getText();
String p=new String(P1.getPassword());
st.executeUpdate("insert into users values('"+u+"','"+p+"')");
JOptionPane.showMessageDialog(null,T1.getText()+" is registered successfully");
}
catch(Exception ez)
{
System.out.println(ez);
}
}
}
);
B.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ec)
{
try
{
String u1=T.getText();
String p1=new String(P.getPassword());
String sql="select username,pass from users where username='"+u1+"'and
pass='"+p1+"'";
rs=st.executeQuery(sql);
int count=0;
while(rs.next())
{
count=count+1;
}
if(count==1)
{
JOptionPane.showMessageDialog(null,"User Found ! Access Granted");
F3.setVisible(true);

}
else if (count>1)
{
JOptionPane.showMessageDialog(null,"Duplicate Users Found ! Acess Denied !");
}
else
{
JOptionPane.showMessageDialog(null,"User Not Found ! Check Your Credentials");
}
}
catch(Exception ew)
{
System.out.println(ew);
}
}
}
);
}
public void connect()
{
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection c = DriverManager.getConnection("jdbc:mysql://localhost/vishwa","root","100%Lv");
st = c.createStatement();
}
catch(Exception ex)
{
System.out.println(ex);
}
}

public static void main(String arg[])


{
new A();
F3=new JFrame("Welcome to JVC");
ImageIcon icon1 = new ImageIcon ("Basic CW.jpg");
ImageIcon icon2 = new ImageIcon ("OOP.jpg");
ImageIcon icon3 = new ImageIcon ("Adv.jpg");
ImageIcon icon4 = new ImageIcon ("UR.jpg");
B3= new JButton(icon1);
B4= new JButton(icon2);
B5= new JButton(icon3);
B6= new JButton(icon4);
F3.add(B3);
F3.add(B4);
F3.add(B5);
F3.add(B6);
F3.setSize(920,480);
F3.setLayout(new FlowLayout());
B3.addActionListener(new C());
B4.addActionListener(new C());
B5.addActionListener(new C());
B6.addActionListener(new C());
}
static class C implements ActionListener
{
public void actionPerformed(ActionEvent y)
{
if(y.getSource()==B3)
{
try{

Desktop d=Desktop.getDesktop();
d.browse(new URI("http://tutorialspoint.com/java/index.htm"));
}
catch(Exception z)
{
System.out.println(z);
}
}
else if( y.getSource()==B4)
{
try{
Desktop d1=Desktop.getDesktop();
d1.browse(new URI("http://www.tutorialspoint.com/java/java_inheritance.htm"));
}
catch(Exception z1)
{
System.out.println(z1);
}
}
else if(y.getSource()==B5)
{
try{
Desktop d2=Desktop.getDesktop();
d2.browse(new URI("http://www.tutorialspoint.com/java/java_data_structures.htm"));
}
catch(Exception z2)
{
System.out.println(z2);
}
}
else

{
try{
Desktop d3=Desktop.getDesktop();
d3.browse(new URI("http://www.tutorialspoint.com/java/java_questions_answers.htm"));
}
catch(Exception z3)
{
System.out.println(z3);
}

}
}
}
}

Das könnte Ihnen auch gefallen