Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: login page connection to button

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    5
    My Mood
    Cheeky
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question login page connection to button

    my problem is that when i run my start page(first page) and click on login, it doesnt opens the login page. can anyone pls help with the solution. its really urgent.. pls help


    my login page is here:-
     
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.sql.*;
     
    class Login extends JFrame
    {
        JButton SUBMIT,ADD;
        JPanel panel;
        JLabel label1,label2;
        final JTextField text1;
        final JPasswordField text2;
        Login(){
            label1 = new JLabel();
            label1.setText("UserName:");
            text1 = new JTextField(15);
            label2 = new JLabel(); 
            label2.setText("Password:");
           text2 = new JPasswordField(15);
            SUBMIT=new JButton("Login");
            ADD=new JButton("Create Account");
            panel=new JPanel(new GridLayout(3,2));
            panel.add(label1);
            panel.add(text1); 
            panel.add(label2); 
            panel.add(text2); 
            panel.add(SUBMIT); 
            panel.add(ADD);
            add(panel,BorderLayout.CENTER);
            SUBMIT.addActionListener(new ActionListener(){ 
                public void actionPerformed(ActionEvent ae){                 
                    String value1=text1.getText();
                    String value2=text2.getText();               
                      if (value1 == null || value1.equals("")) {
                        JOptionPane.showMessageDialog(null, "Enter user id", "Missing field", JOptionPane.DEFAULT_OPTION);
                        return;
                    }
                        if (value2 == null || value2.equals("")) {
                        JOptionPane.showMessageDialog(null, "Enter password", "Missing field", JOptionPane.DEFAULT_OPTION);                  
                        return;
                    }
                    Connection con = null;
                    String url="jdbc:mysql://localhost:3306/";
                    String db="pharma";
                    String driver="com.mysql.jdbc.Driver";
                    String user="root";
                    String pass="root"; 
                    String user1=""; 
                    String pass1=""; 
                    try
                    {
                        Class.forName(driver);
                        con = DriverManager.getConnection(url+db, user, pass); 
                        Statement st = con.createStatement();
                        ResultSet res = st.executeQuery("SELECT * FROM login where username='"+value1+"' && password='"+value2+"'");
                        while (res.next()) {
                            user1 = res.getString("username");
                           pass1 = res.getString("password");
                        }
                        if (value1.equals(user1) && value2.equals(pass1)) {                        
                            dispose();
                            JOptionPane.showMessageDialog(null,"Welcome "+user1+", You have successfully Login");
                            HcHome h=new HcHome();
                h.setBounds(0,0,1020,1000);
                h.setVisible(true);
                        } 
                        else{ 
                            JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE); 
                        } 
                    }
                   catch(Exception e){
                         System.out.println(e.getMessage());
                    } 
                } 
            });
            ADD.addActionListener(new ActionListener(){ 
                public void actionPerformed(ActionEvent ae){ 
                    CreateAccount account=new CreateAccount();
                    account.setVisible(true);
                } 
            });
    }
    public static void main(String arg[]) {
     Login l=new Login();
     l.setBounds(90,150,200,30);
     l.setSize(300,100);
     l.setVisible(true);
      l.setTitle("LOGIN PAGE");
     }
    }


    The start page is here: -



     
     
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    public class Start extends JFrame 
     {
       JLabel title,title1,title2,line,image;
       JButton Login,Back;
       JPanel p;
       int key;
       String b;
       public Start()
        {
          setLayout(null);
          setTitle("Start");
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          title=new JLabel("WELCOME TO AYURVEDA");
          title.setFont(new Font("arial",Font.BOLD,50));
          title.setForeground(Color.red);
          title.setBounds(200,50,1000,70);
          title1=new JLabel("LUNA PHARMA");
          title1.setFont(new Font("arial",Font.BOLD,40));
          title1.setForeground(Color.RED);
          title1.setBounds(350,100,500,70);
          title2=new JLabel("GMP CERTIFIED UNIT");
          title2.setFont(new Font("arial",Font.BOLD,25));
          title2.setForeground(Color.red);
          title2.setBounds(360,150,500,60);
          line=new JLabel("------------------");
          line.setFont(new Font("arial",Font.BOLD,45));
          line.setForeground(Color.blue);
          line.setBounds(360,200,1000,30);
          getContentPane().add(title);
          getContentPane().add(title1);
          getContentPane().add(title2);
          getContentPane().add(line);
          Login=new JButton("Login");
          Login.setMnemonic(KeyEvent.VK_A);
          Login.setToolTipText("Press it to login");
          Login.setFont(new Font("arial",Font.BOLD,20));
          //Login.addActionListener(this);     
         //  Login.addKeyListener(this);    
          getContentPane().add(Login);     
             Back=new JButton("Exit");
          Back.setMnemonic(KeyEvent.VK_B);
          Back.setToolTipText("Press it to Exit");
          Back.setFont(new Font("arial",Font.BOLD,20));
         // Back.addActionListener(this);      
          // Back.addKeyListener(this);      
          getContentPane().add(Back);      
            p=new JPanel();
          p.setLayout(new GridLayout(1,3));
          p.setBounds(330,650,350,30);
              p.add(Login);      
          p.add(Back);
          getContentPane().add(p);
          image=new JLabel(new ImageIcon("http://www.javaprogrammingforums.com/images/Front.jpg"));
          image.setBounds(100,250,900,500);
          getContentPane().add(image);
          setSize(1020,1000);
          setVisible(true);       
          Back.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
            	       {               	        dispose();
             	       }
        }           });
                 Login.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent ae)
       {
            Login l=new Login();
           }
          });     
          }
       public static void main(String args[])
        {
          Start sf=new Start();
          sf.setVisible(true);
        }
      }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: login page connection to button

    Please edit your post and wrap your code with code tags:
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.

    Also remove all the extra blank lines between the statements.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    5
    My Mood
    Cheeky
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: login page connection to button

    thnx for noting.. i am new to this forum.. well, i have done formatting.. pls help..

  4. #4
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: login page connection to button

    Is the button working? Does clicking the button result in the event handling code being called?
    Add some printlns to try to determine where the problem is and try to ask a question that is less general.
    Simply saying "it doesnt opens the login page" does not offer much to go on.

  5. #5
    Junior Member
    Join Date
    May 2013
    Posts
    5
    My Mood
    Cheeky
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: login page connection to button

    well thnks, bt pls dnt do more searching on it. i hv got the solution for it.

Similar Threads

  1. HOW TO REDIRECT TO LOGIN PAGE IF NOT LOGGED IN
    By divyatejak in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: March 6th, 2012, 05:19 AM
  2. Need help in login page in struts
    By vinothkumarrvk in forum Web Frameworks
    Replies: 4
    Last Post: October 4th, 2011, 02:10 PM
  3. Login Page error
    By abhiM in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 23rd, 2011, 07:30 AM
  4. Unable to view jsp pages through same login page
    By Rajiv in forum Web Frameworks
    Replies: 1
    Last Post: August 17th, 2011, 11:43 AM
  5. login page with image
    By balu424525 in forum AWT / Java Swing
    Replies: 1
    Last Post: June 26th, 2011, 11:24 AM