how to connect two swing frames

how to connect two swing frames

how to connect two swing frames

View Answers

January 24, 2011 at 12:14 PM

Hi Friend,

Try this:

1)LoginDemo.java:

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

class LoginDemo extends JFrame{
 JButton SUBMIT;
 JLabel label1,label2;
 final JTextField  text1,text2;
  LoginDemo(){
    setTitle("Login Form");
    setLayout(null);
    label1 = new JLabel();
    label1.setText("Username:");
    text1 = new JTextField(15);

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

    SUBMIT=new JButton("SUBMIT");
    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);
   add(label1);
   add(text1);
   add(label2);
   add(text2);
   add(SUBMIT);

   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("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           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{
     JOptionPane.showMessageDialog(null,"Invalid login name or password","Error",JOptionPane.ERROR_MESSAGE);
     text1.setText("");
     text2.setText("");
  }
    }
    catch(Exception e){}
}
 });
  }
  public static void main(String arg[]){
  new LoginDemo();
}
}

2)NextPage.java:

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

class NextPage extends JFrame
{
  NextPage(String st)
   {
      setLayout(null);
     setDefaultCloseOperation(javax.swing. WindowConstants.DISPOSE_ON_CLOSE);
     setTitle("Welcome");
     JLabel lab=new JLabel("Welcome  "+st);

     lab.setBounds(10,10,500,20);
     add(lab);
     setSize(1024, 768);
      }
 }

Thanks









Related Tutorials/Questions & Answers:
how to connect two swing frames
how to connect two swing frames  how to connect two swing frames   Hi Friend, Try this: 1)LoginDemo.java: import java.sql.*; import java.awt.*; import javax.swing.*; import java.awt.event.*; class LoginDemo extends
update two frames at once
update two frames at once  How do I update two frames at once
Advertisements
how i connect two page
how i connect two page  strong textlink text
How to create Multiple Frames using Java Swing
Multiple Frames in Java Swing In this section, you will learn how to create multiple frames. Java Swing provides the utility to show frame within another... JFrame("Multiple Frames"); frame.setDefaultCloseOperation(JFrame.EXIT
how to connect two databse through HibernateFramework
how to connect two databse through HibernateFramework  how to connect two databse through HibernateFramework
Frames
Frames  using awt how i can link two frames? for example i just want that when i press on the button of frame "frame1" it takes me on another window "frame2" with desired output and hide the "frame1" please help me out
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application, to a japser reporting(two)  I have 2 tables in one swing user interface. I want... want to know do for two tables. (here I am sending two parameters as well
How to send and view data in seperate tables of a swing application, to a japser reporting(two)
How to send and view data in seperate tables of a swing application, to a japser reporting(two)  I have 2 tables in one swing user interface. I want... want to know do for two tables. (here I am sending two parameters as well
How to connect
How to connect  how to connect to a remote host using jsp? We need to update files to the database of the application on the local machine from the updated database on our webpage
how to divide a web page into some frames.....
how to divide a web page into some frames.....  how to divide 1 web page into some parts. i know it using frames in html,bt how can we do it in jsp... page,bt m nt knowing how to divide that into frames in jsp.  Please go
Need Help To Connect XML as backend in Java-Swing
Need Help To Connect XML as backend in Java-Swing  Seat arrangment swing screenshot I made XML program to connect to swing like this. <?xml...) and data changed to Y...but it did nt do it.. i cant understand how to do
How to connect on screen keyboard to system.
How to connect on screen keyboard to system.  How to connect on screen keyboard to system.I made on screen keyboard in java(swing).Now i want connect to system means when i pressed any button then it type on notepad or any
How to connect on screen keyboard to system.
How to connect on screen keyboard to system.  How to connect on screen keyboard to system.I made on screen keyboard in java(swing).Now i want connect to system means when i pressed any button then it type on notepad or any
how to connect webcam in html
how to connect webcam in html  how to connect webcam in html.emphasized text
how to devide a web page into parts and setting the targets like frames but without using frames
how to devide a web page into parts and setting the targets like frames but without using frames  Here is my requirement, I have to devide a web... by user.I am using jsp.(This requirement must be fulfilled without using frames
How to connect with database
How to connect with database  jdbc connection
create frames
create frames  How do I create frames? What is a frameset
How to connect mysql with jsp
How to connect mysql with jsp  how to connect jsp with mysql while using apache tomcat
SWING FRMES
SWING FRMES  hai SIR? HOW TO DESIGN swing Frames send source code
SWING FRMES
SWING FRMES  hai SIR? HOW TO DESIGN swing Frames send source code
How to connect to MySQL in JSP?
How to connect to MySQL in JSP?  How to connect to MySQL in JSP..., You can use the Java JDBC code to connect to MySQL database in JSP page. Check the tutorial: Connect JSP with mysql Thanks
problem in swing program for opening two windows with same login credentials
problem in swing program for opening two windows with same login credentials  I Face two problems while writing the code in swing program 1.i... into the system with same username,password two times then it opens two separate
HTML frames
HTML frames  Are there any problems with using frames
ModuleNotFoundError: No module named 'frames'
'frames' How to remove the ModuleNotFoundError: No module named 'frames'...ModuleNotFoundError: No module named 'frames'  Hi, My Python... to install padas library. You can install frames python with following command
HTML frames
HTML frames  Do search engines dislike frames
how to connect jdbc
how to connect jdbc  package com.tcs.ilp.Try.Controller; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import
how to connect program to database
how to connect program to database  Sir i want ur help in my program. I want to save the data in the database. When i'll click on save button the entered data must be save in the database. I want an action performed method
frames - Java3D
frames  how can i create multiple frames in java?  Hi Friend, You can use JInternalFrame class to create multiple frames in java as we...("Multiple Frames"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE
how to create reports in swing java?
how to create reports in swing java?  how to create reports in swing java
How to concatenate two arrays in Java?
How to concatenate two arrays in Java?  How to concatenate two arrays in Java
how to compare text in two jTextarea
how to compare text in two jTextarea  give some sample code
How To Create Internal Frames In Java
How To Create Internal Frames In Java In this tutorial we will learn about how... a simple example which will demonstrate you how to create frames within a frame... till the application is running and want to do operations on an another frames
HTML combination of frames
HTML combination of frames  How do I specify a specific combination of frames instead of the default document
border around frames
border around frames  How do I remove the border around frames
how to connect SQL Server 2005 using php
how to connect SQL Server 2005 using php  i need to connect SQL Server 2005 using php. how can i connect . how to use mssql_connect function
How to convert a swing form to PDF
How to convert a swing form to PDF  Sir, I want to know about how convert a swing form containing textbox,JTable,JPanel,JLabel, Seperator etc swing menus to a PDF file using java code
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?  HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE
how to connect client to server using Sockets
how to connect client to server using Sockets  how to connect client to server using Sockets
how to connect to database in php using mysql
how to connect to database in php using mysql  how to connect to database in php using mysql
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?
HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE?  HOW TO CREATE COMMENT IN WEBSITE AND CONNECT TO DATABASE
how to use marathi font in swing?
how to use marathi font in swing?  I want to use marathi language on labels,buttons
how to connect mysql with JDBC - JDBC
how to connect mysql with JDBC  I have created three tables in the database MYsql, i have to connect them now using JDBC, can u please suggest me...(); } } Thanks Rajanikant  Hi friend, To mysql connect using JDBC
How to cascade two text boxes??
How to cascade two text boxes??  I am having 3 text boxes if i entered the value in the first text box then the values of the two text boxes should come from the database with respect to first text box value
Regarding frames in HTML
Regarding frames in HTML  I have created a html page including two frames in it,one frame consists "search bar" and the other frame consists login page,when i click on "Sign In" button in login frame,it is displaying the results
Extract frames from Video File
Extract frames from Video File  How to extact the frames from a particular video file and save them in .jpeg format
how to connect xlsx(2007 excel) - JDBC
how to connect xlsx(2007 excel)  i am not able connect to office 2007 excel file from jdbc
ModuleNotFoundError: No module named 'gif-frames'
'gif-frames' How to remove the ModuleNotFoundError: No module named 'gif-frames' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'gif-frames'  Hi, My Python
ModuleNotFoundError: No module named 'gif-frames'
'gif-frames' How to remove the ModuleNotFoundError: No module named 'gif-frames' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'gif-frames'  Hi, My Python
ModuleNotFoundError: No module named 'markdown_frames'
named 'markdown_frames' How to remove the ModuleNotFoundError: No module named 'markdown_frames' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'markdown_frames'  Hi, My
ModuleNotFoundError: No module named 'gif-frames'
'gif-frames' How to remove the ModuleNotFoundError: No module named 'gif-frames' error? Thanks   Hi, In your python environment you...ModuleNotFoundError: No module named 'gif-frames'  Hi, My Python

Ads