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