Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

java swing code execution

$
0
0
I tried this code for creating a java login page application, the code is like this

 
  
import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;

class LoginDemo extends JFrame
{
 JButton SUBMIT;
 JLabel heading,label1,label2;
 final JTextField  text1,text2;
  LoginDemo()
  {
    setTitle("Login Form");
    setLayout(null);
	heading= new JLabel("RFID based Employee Tracking System");
	heading.setFont(new Font("Comic Sans MS",Font.PLAIN,28));
	heading.setBounds(250,20,1000,50);
	add(heading);
    label1 = new JLabel();
    label1.setText("Username:");
    text1 = new JTextField(15);

    label2 = new JLabel();
    label2.setText("Password:");
    text2 = new JPasswordField(15);

    SUBMIT=new JButton("SUBMIT");
	JButton cancel=new JButton("CANCEL");
    label1.setBounds(350,100,100,20);
    text1.setBounds(450,100,200,20);
    label2.setBounds(350,130,100,20);
    text2.setBounds(450,130,200,20);
    SUBMIT.setBounds(450,160,100,20);
	cancel.setBounds(550,160,100,20);
     add(label1);
     add(text1);
     add(label2);
     add(text2);
     add(SUBMIT);
     add(cancel);

     setVisible(true);
     setSize(1024,768);

    SUBMIT.addActionListener(new ActionListener()
	 {
       public void actionPerformed(ActionEvent ae)
		{
            String value1=text1.getText();
            String value2=text2.getText();
            try{
                 Class.forName("oracle.jdbc.driver.oracleDriver");
                 Connection con = DriverManager.getConnection("jdbc:oracle:thin:@localhost:8080:server","system","oracle");
                 Statement st=con.createStatement();
                 ResultSet rs=st.executeQuery("select * from login where username='"+value1+"' and password='"+value2+"'");
                 String uname="",pass="";
                   if(rs.next())
					   {
                             uname=rs.getString("username");
                             pass=rs.getString("password");
                       }
                   if(value1.equals("") && value2.equals("")) 
					   {
                            JOptionPane.showMessageDialog(null,"Enter login name or password","Error",JOptionPane.ERROR_MESSAGE);
                       }
                   else if(value1.equals(uname) && value2.equals(pass)) 
					   {
                            NextPage page=new NextPage(uname);
                            page.setVisible(true);
                       }
                   else if (!value1.equals(uname) && !value2.equals(pass)) 
					   {
                            text1.setText("");
                            text2.setText("");
                       }
                }
           catch(Exception e){}
        }
    });
  }

      public static void main(String arg[])
	  {
          new LoginDemo();
       }
}




The main problem is it couldn't enter the next page when the submit button is pressed. when it is pressed, execution doesn't proceed to the next page..i think it didn't enter the actionperformed method!!!
Is there any problem with my code.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>