Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT swings:how to link from one form to another form
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sureshkumar
swings:how to link from one form to another form
2 Answer(s)      4 years ago
Posted in : Swing AWT


how to link from one form to another form ...


Advertisement
View Answers

November 12, 2010 at 11:46 AM


Hello Friend,

You can try the following code:

1)LoginDemo.java:

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

class LoginDemo{
 JButton SUBMIT,NEWUSER;
 JFrame f;
 JLabel label1,label2;
 final JTextField  text1;
 final JPasswordField text2;
    LoginDemo(){
        f=new JFrame();
        f.getContentPane().setLayout(null);
        label1 = new JLabel();
        label1.setText("UserName:");
        label1.setBounds(400,50,100,20);
        text1 = new JTextField(25);
        text1.setBounds(500,50,100,20);
        label2 = new JLabel();
        label2.setText("Password:");
        label2.setBounds(400,80,100,20);
        text2 = new JPasswordField(25);
        text2.setBounds(500,80,100,20);
        SUBMIT=new JButton("Login");
        SUBMIT.setBounds(400,110,100,20);

        NEWUSER=new JButton("Create Account");
        NEWUSER.setBounds(500,110,200,20);

        f.add(label1);
        f.add(text1);
        f.add(label2);
        f.add(text2);
        f.add(SUBMIT);
        f.add(NEWUSER);
        f.setSize(1024,768);
        f.setVisible(true);
        SUBMIT.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
        String value1=text1.getText();
        String value2=text2.getText();
        String user1="";
        String pass1="";
        try{
                  Class.forName("com.mysql.jdbc.Driver").newInstance();
            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql", "root", "root");
                 Statement st = con.createStatement();
                 ResultSet res = st.executeQuery("SELECT * FROM  login where username='"+value1+"' and password='"+value2+"'");
                 while (res.next()) {
                 user1 = res.getString("username");
                 pass1 = res.getString("password");
        }
        if(value1.equals(user1) && value2.equals(pass1)) {
        JOptionPane.showMessageDialog(null,"Welcome");
        }
        else{
        JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
                }
        }
                catch(Exception e){
        System.out.println(e.getMessage());
                }
        }
        });
        NEWUSER.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent ae){
        CreateAccount acc=new CreateAccount();
        }
        });
    }
        public static void main(String arg[])   {
        LoginDemo frame=new LoginDemo();
            }
}


November 12, 2010 at 11:46 AM


continue..

2)CreateAccount.java:

import javax.swing.*;
import java.awt.*;
 import java.sql.*;
 import java.awt.event.*;
class CreateAccount extends JFrame{
    JTextField text1,text2,text3,text4,text5;
    JPasswordField pass1;
    JLabel label1,label2,label3,label4,label5,label6;
    JPanel panel;
    JButton button;
    CreateAccount()  {
    text1=new JTextField(15);
    text2=new JTextField(15);
    text3=new JTextField(15);
    pass1=new JPasswordField(15);
    text4=new JTextField(15);
    text5=new JTextField(15);
    label1=new JLabel("Name");
    label2=new JLabel("Address");
    label3=new JLabel("Contact No");
    label4=new JLabel("Email");
    label5=new JLabel("City");
    label6=new JLabel("State");
    button=new JButton("Save");
    panel=new JPanel(new GridLayout(7,2));
    panel.add(label1);
    panel.add(text1);
    panel.add(label2);
    panel.add(text2);
    panel.add(label3);
    panel.add(text3);
    panel.add(label4);
    panel.add(pass1);
    panel.add(label5);
    panel.add(text4);
    panel.add(label6);
    panel.add(text5);
    panel.add(button);
    button.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent ae){
                String value1=text1.getText();
                String value2=text2.getText();
                String value3=text3.getText();
                String value4=pass1.getText();
                String value5=text4.getText();
                String value6=text5.getText();
    try{
                 Class.forName("com.mysql.jdbc.Driver");
                 Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
                 Statement st = con.createStatement();
                  int k=st.executeUpdate("insert into employee(name,address,contactNo,email,city,state) values('"+value1+"','"+value2+"','"+value3+"','"+value4+"','"+value5+"','"+value6+"')");
                 JOptionPane.showMessageDialog(null,"Data is successfully inserted");
                 }
            catch(Exception e){
            System.out.println(e);
            }
            }
            });
            add(panel);
            setSize(300,400);
            setVisible(true);
      }
      public static void main(String args[]){
          CreateAccount acc=new CreateAccount();
      }   
}

Thanks



Related Tutorials/Questions & Answers:
swings:how to link from one form to another form
swings:how to link from one form to another form  how to link from one form to another form
how to use one form out of multiple form from one jsp to another jsp
how to use one form out of multiple form from one jsp to another jsp  Hi All. please give me your valuable advise for below requirement.. I have... one form from abc.jsp as it is to another .jsp(say def.jsp).Your advise
Advertisements
Return Value from One Form
Return Value from One Form  I have two buttons in main form client... is there.when i click dedupe button another form will open. i want to get a field value of dedupe form and use in bank form..how to do
Javascript coding for link a website to another upon verify the form - Java Beginners
Javascript coding for link a website to another upon verify the form  Pls tell me javascript coding for " open a website when we click the verify button in the form? ( after verifying the form go to the desired website). 
Pass values from form to form
Pass values from form to form       Java program to pass values from one form to another form... values from one page to another consecutive page which is being called then we can
form
form   Can I prevent a form from being submitted again
displaying data from ms excel in form.
some logic on how to link this image from my folder to the image.jpg mentioned...displaying data from ms excel in form.  Hi all, I have a requirement.... In one of the column i am also storing the name of a pic file.. say image.jpg
calling one jsp from another jsp page
calling one jsp from another jsp page  need coding for calling one jsp from another jsp including the xml file.Its urgent
How to navigate from one jsf to another in eclipse
How to navigate from one jsf to another in eclipse  Hi there is my...; <h:outputText value="USER DETAILS FORM"> </h:outputText> </b> <p> <h:messages style="color: blue"/> </p> <h:form
Displatying java script form submitted elements in another page
Displatying java script form submitted elements in another page   hi... after submitting the registration form. I want to get the values after submitting the form
File copy from one directory to another in java
File copy from one directory to another in java  I am trying to find very good code example for copying a file from one directory to another... from a directory to another directory. How to achieve this? Is there any API
update one table from another table
update one table from another table  hello, i need to update one table fields by using another table fields. I have to tables Products.... for example TotalQuantity field from Products table should be updated if i
to bring checked data from one page to another
to bring checked data from one page to another  thanks for your help... there is one jsp page , on it there is a link, on click of which it is opening second... fetching data from the database on second jsp page with checkbox corresponding each
How to forward the control from one jsp to another?
How to forward the control from one jsp to another?  Hi! This is Prasad Jandrajupalli. I have the 3 JSP's, but I want communicate with each... is not communicate with the Third JSP. I want forward the control from first jsp to second
copying data from one table to another
copying data from one table to another  i need to copy data from one table to another table.. i.e the 1st eid of employee table must be copied to the 1st eid in appusers table, 2nd eid of employee to the 2nd eid of appusers
how to pass a string from one class to another
how to pass a string from one class to another  hi all, Good morning... string from one class to another. import java.util.*; class A{ static String... string from one class to another. import java.io.*; class Class1 { public
image upload with jsp from form
image upload with jsp from form  hi i used the code specified in your following post http://www.roseindia.net/answers/viewqa/JSP-Servlet/9749-image-upload-and-stored-in-database.html but i am getting following error
passing data from one jframe to another
passing data from one jframe to another  I have two JFrame,built by using the GUI Editor netbeans 6.9.i have to pass a data from a Jtextfield in the first Jframe to another JLabel in the other JFrame.Can you please help me,how
Exception during parsing a parameter from the form in JSP
Exception during parsing a parameter from the form in JSP  Exception during parsing params from a form? I get parameters from a html form. I parse the integer one in the JSP file, but I get exception. Is there anyway I can get
Display tow dimensional array by matrix form using one for loop in java
Display tow dimensional array by matrix form using one for loop in java  Display tow dimensional array by matrix form using one for loop in java
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
value in div from php, reloading form
value in div from php, reloading form  I am having one form with name... have taken two forms login.php in which i am building form and login2.php... getting two forms visible on the same page, i want to omit the first one when i go
PHP form
not getting How to read these Multiple textfield with the same name values in another form and update them to respective coloumn... Please any one help mo out please...PHP form  Hi Sir/Madam, I am developing an attendance form using php
JSP to add details to a database from a HTML form.
JSP to add details to a database from a HTML form.  Hi I'm a second year CS student who has to use JSP to validate a HTML form and add the details... from form and stores it in User--%> String Pword = request.getParameter
how to copy file from one directory to another in java with examples
how to copy file from one directory to another in java with examples  how to copy file from one directory to another in java with examples? I want... copy from one directory to another in java. Thanks
calling one jap page from another jsp page
calling one jap page from another jsp page  i created a button in one jsp page i need to call another jsp page as an action to that button. so how can i call.. plz any one explain. its urgent
Pass cookie from one site to another within the same domain
Pass cookie from one site to another within the same domain  Hi, I want to pass a cookie from one website to another within the same domain. This is just to identify whether the same user is logged in or not. Can anyone help me
File copy from one drive to another. - Java Beginners
File copy from one drive to another.  I want to copy a .mp3 file from one drive(let d: drive)to another drive(let e: drive) in my Windows XP. How can I do
how to pass an array from one jsp to another jsp - JSP-Servlet
how to pass an array from one jsp to another jsp  hi friedns, can any One tell me how to send an array from one jsp to another jsp,pls any one send the code for this.also porvid the code how to retrive the arry in another jsp
problem in sending data from one ip to another ip in JAVA
problem in sending data from one ip to another ip in JAVA  Hi guys . this is naveen kumar...i need a help. i want to connect one ip to another ip... device in JAVA. i know how to ping but don't how to send the msg's to another IP
take data from one table and insert same in another
take data from one table and insert same in another  I want to know when a new field update in table and the same data has to update in another table
Advertisements
 

 

 

DMCA.com