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 ...

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
Pass values from form to form
Pass values from form to form       Java program to pass values from one form to another form... to only pass values from one page to another consecutive page which is being
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). 
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
ModuleNotFoundError: No module named 'odoo12-addon-product-form-purchase-link'
: ModuleNotFoundError: No module named 'odoo12-addon-product-form-purchase-link' How...ModuleNotFoundError: No module named 'odoo12-addon-product-form-purchase-link...-form-purchase-link python with following command: pip install odoo12-addon
ModuleNotFoundError: No module named 'odoo12-addon-product-form-sale-link'
: ModuleNotFoundError: No module named 'odoo12-addon-product-form-sale-link' How to remove...ModuleNotFoundError: No module named 'odoo12-addon-product-form-sale-link' ... to install padas library. You can install odoo12-addon-product-form-sale-link
ModuleNotFoundError: No module named 'odoo12-addon-product-form-purchase-link'
: ModuleNotFoundError: No module named 'odoo12-addon-product-form-purchase-link' How...ModuleNotFoundError: No module named 'odoo12-addon-product-form-purchase-link...-form-purchase-link python with following command: pip install odoo12-addon
ModuleNotFoundError: No module named 'odoo12-addon-product-form-sale-link'
: ModuleNotFoundError: No module named 'odoo12-addon-product-form-sale-link' How to remove...ModuleNotFoundError: No module named 'odoo12-addon-product-form-sale-link' ... to install padas library. You can install odoo12-addon-product-form-sale-link
ModuleNotFoundError: No module named 'odoo13-addon-product-form-purchase-link'
: ModuleNotFoundError: No module named 'odoo13-addon-product-form-purchase-link' How...ModuleNotFoundError: No module named 'odoo13-addon-product-form-purchase-link...-form-purchase-link python with following command: pip install odoo13-addon
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
how to fill up a form automaically from database and print it
how to fill up a form automaically from database and print it  sir,i am designing a medical license website.i need to fillup a license form atuomatically from details stored in database.ex:if there are details of a person like
how to fill up a form automaically from database and print it
how to fill up a form automaically from database and print it  sir,i am designing a medical license website.i need to fillup a license form atuomatically from details stored in database.ex:if there are details of a person like
how to fill up a form automaically from database and print it
how to fill up a form automaically from database and print it  sir,i am designing a medical license website.i need to fillup a license form atuomatically from details stored in database.ex:if there are details of a person like
how to fill up a form automaically from database and print it
how to fill up a form automaically from database and print it  sir,i am designing a medical license website.i need to fillup a license form atuomatically from details stored in database.ex:if there are details of a person like
how to fill up a form automaically from database and print it
how to fill up a form automaically from database and print it  sir,i am designing a medical license website.i need to fillup a license form atuomatically from details stored in database.ex:if there are details of a person like
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
how to write function of copy from one to another location in this code
how to write function of copy from one to another location in this code  I need to write a code to copy a file from one location to another using...(); System.out.println(fileName); } } }   hi friend, Please visit the link, may
How to pass variable from one class to another in java
How to pass variable from one class to another in java  How to pass variable from one class to another in java?   Example: public class...; } } //Another class Class2. public class Class2 { public static void main(String
how to get a values from a multipart/form-data - JSP-Servlet
how to get a values from a multipart/form-data  Dear sir , I... submitForm(f){ var form = document.createElement("form"); with(form) { method = "post"; action = "newEntryDetails2.jsp"; name = "form"; id = "form
Fetch the data from mysql and display it on php form
Fetch the data from mysql and display it on php form  when i press on login button, after succesful login the related data of that person should be display in other textbox
Retrieve value of radio button from database to form
Retrieve value of radio button from database to form  var gn=document.getElementsByName("empg"); //empg is name of radio input type. for(var i=0;i
Uploading file in servlet from a html form
Uploading file in servlet from a html form  Sir, I want to upload a picture from my html file and save it to my database as BLOB,but what JAR should i use for this purpose i am really confused about.And also is it possible to do
How to retrieve array values from html form to jsp?
How to retrieve array values from html form to jsp?  Hi! I am... it into jsp. Means i just want to retrieve values from html form containing array... sample code for how to retrive array values from html to jsp.   hi friend
retrieve the records from one table to another table by using cursors
retrieve the records from one table to another table by using cursors  ... from one table to another table by using cursors.The following is my procedure and tables.After execution it insert one extra record to another table. empproc
Problem passing a value from one jsp to another using href
Problem passing a value from one jsp to another using href  first page.jsp <a href="common.jsp?param=<%l.get(k).parentname%>"> common.jsp <%String attr=request.getAttribute("param"); out.print(attr

Ads