Share on Google+Share on Google+

saidarshan alluri
nextpage
1 Answer(s)      6 years and 4 months ago
Posted in : Java Beginners

my login form using java awt-swing ..still appearing after clicking submit button when i entered into next page how can we make it invisible

Ads

View Answers

December 21, 2010 at 5:54 PM


Hello Friend,

We have provided you the code where if user enters correct username and password then the frame will get closed and only welcome page display. In case if user enters incorrect username or password then login page will not closed and message will get displayed.

To make the login frame invisible, we have used f.setVisible(false).

We are again sending you the code:

1)Login.java:

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

class Login 
{
 JButton SUBMIT;
 JLabel label1,label2;
 final JTextField  text1,text2;
  Login()
  {
      final JFrame f=new JFrame("Login Form");
      f.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);
   f.add(label1);
   f.add(text1);
   f.add(label2);
   f.add(text2);
   f.add(SUBMIT);


  f.setVisible(true);
  f.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(uname) && value2.equals(pass)) {
            f.setVisible(false);
    NextPage page=new NextPage(uname);
    page.setVisible(true);
     }
    else{
     JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
     text1.setText("");
     text2.setText("");

  }
    }
    catch(Exception e){}
}
 });
  }
}
 class LoginDemo
{
  public static void main(String arg[]){

    new Login();
}
}

2)NextPage.java:

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

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

If you have made some changes in the above code, then post your query with code.

Thanks










Related Tutorials/Questions & Answers:
nextpage
) && value2.equals(pass)) { f.setVisible(false); NextPage page=new NextPage(uname); page.setVisible(true); } else... java.awt.*; class NextPage extends JFrame { NextPage(String st
java - JSP-Servlet
java  how to create next button goto nextpage?  Hi Friend, 1)hello.jsp: Enter Name: 2)next.jsp: Thanks
Advertisements
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
" java.lang.NullPointerException at NextPage$2.actionPerformed(NextPage.java:36... first time click on OFF button that error came class NextPage extends JFrame { Image m; Thread t; NextPage(final String uname
Hiding a JFrame
){ String value=text.getText(); NextPage page=new NextPage... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
Hiding a JFrame
){ String value=text.getText(); NextPage page=new NextPage... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
java
")){ NextPage page=new NextPage(value1); page.setVisible(true...)NextPage.java: import java.awt.*; import javax.swing.*; class NextPage extends JFrame { NextPage(String st) { setLayout(null
passing data from one jframe to another
){ String value=text.getText(); NextPage page=new NextPage(value...*; class NextPage extends JFrame { NextPage(String st) { setLayout(null
swing question
); } else if(value1.equals(uname) && value2.equals(pass)) { NextPage page=new NextPage(uname); page.setVisible(true); } else if (!value1.equals... main(String arg[]){ new LoginDemo(); } } class NextPage extends JFrame
Username password
)) { NextPage page=new NextPage(uname); page.setVisible(true); } else...){} } }); } public static void main(String arg[]){ new LoginDemo(); } } class NextPage extends JFrame { NextPage(String st) { setLayout(null
How to put the logo in login form using swings/awt?
if(value1.equals(uname) && value2.equals(pass)) { NextPage page=new NextPage...[]){ new LoginDemo(); } } class NextPage extends JFrame { NextPage(String
How to put the image in footer in login form ?
(uname) && value2.equals(pass)) { NextPage page=new NextPage(uname...[]){ new LoginDemo(); } } class NextPage extends JFrame { NextPage(String st
Java swing
; value2.equals(pass)) { setVisible(false); NextPage page=new NextPage(uname...*; class NextPage extends JFrame { NextPage(String st) { setLayout(null
how to connect two swing frames
if(value1.equals(uname) && value2.equals(pass)) { NextPage page=new NextPage...*; class NextPage extends JFrame { NextPage(String st) { setLayout(null
login
;& value2.equals(pass)) { f.setVisible(false); NextPage page=new NextPage(uname); page.setVisible(true); } else... java.awt.*; class NextPage extends JFrame { NextPage(String st
Swings - Java Beginners
)) { NextPage page=new NextPage(); page.setVisible(true); JLabel... javax.swing.*; import java.awt.*; class NextPage extends JFrame{ NextPage
Display Logo on login form using swing
)) { NextPage page=new NextPage(uname); page.setVisible(true); } else... static void main(String arg[]){ new LoginDemo(); } } class NextPage extends JFrame { NextPage(String st) { setLayout(null
login form
;& value2.equals(pass)) { setVisible(false); NextPage page=new NextPage(uname); page.setVisible(true); } else... java.awt.event.*; class NextPage extends JFrame { NextPage(String st
login form
); NextPage page=new NextPage(uname); page.setVisible(true); } else... java.awt.*; import java.awt.event.*; class NextPage extends JFrame { NextPage
Swings - Java Beginners
) && value2.equals(pass1)) { NextPage page=new NextPage...)NextPage.java: import javax.swing.*; import java.awt.*; class NextPage extends JFrame{ NextPage() { setDefaultCloseOperation(javax.swing.
Login Form in Swing
NextPage()  {  setDefaultCloseOperation(javax.swing.  ...=new NextPage();   page.setVisible(true);   JLabel 
how to implements jdbc connections using awt?
; value2.equals(pass1)) { NextPage page=new NextPage(); page.setVisible(true); JLabel
java and database
(false); NextPage page=new NextPage(uname); page.setVisible(true
java swings - Java Beginners
) && value2.equals(pass1)) { NextPage page=new NextPage(); page.setVisible
JSP Hibernate Tutorial
nextPage = (pageNumber +1) + ""; session.setAttribute( "...;contact.jsp?page=" + nextPage; System.out.println(myUrl
Tutorials   
Java Spring Hibernate Struts Training Retrieve database from the table dynamically in jsp from oracle using servlet What does core Java include? java What are some way to learn Java quickly? Is it required to learn Java before learning Java Script? Is it necessary to learn java script before learning PHP? Are HTML5 and Java Script boosts Java career? Is Java object oriented? Fingerprint application with Java Uninstall Oracle Virtual Box JSON to HashMap Free Java online Training I want example of Control Statement in Java ANSI Color Codes with Python Create a Program that Calculates Input What is difference between JDK,JRE and JVM? How to see ubuntu version on server? How to get Page Source in Selenium (WebDriver) using Java? The path to the driver executable must be set by the webdriver.gecko.driver system property parse data from a link in java Java Program Qns using BlueJ How to fix HAX Kernel Module Is Not Installed error? Installing Audacity Looking for code Logic to check track changes & Coments in MSWord, MSWordx, MSExcel, MSExcelx is ON/OFF Installing JDK on Mac SAX Parser exception ERROR 601 (42P00): Syntax error. Encountered Thread java.lang.NoClassDefFoundError: org/apache/commons/fileupload/FileItemFactory How to install Ubuntu 16.04 LTS? HttpServletRequest cannot be resolved to a type in eclipse - Solved Unhandled event loop exception GC overhead limit exceeded Spring Data jpa with apache phoenix Caused by: java.lang.IllegalArgumentException: Not a host:port pair: PBUF o.a.h.h.z.RecoverableZooKeeper - Possibly transient ZooKeeper, quorum= com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager class not found com.thinkaurelius.titan.diskstorage.hbase.HBaseStoreManager not found How to download and install Java 8 on Windows? How to uninstall JDK 7? How to install gtk-doc-tools package in Ubuntu? How to install Oracle JDK 8 on Ubuntu? ejabberd_ctl.beam not found - Solved How to convert date to UTC format in Java? How to install autoconf, automake and libtool in Ubuntu 15.10? How to convert current date to mm dd yyyy format in Java? How to convert current date to dd mm yyyy format in Java? How to stop window closing in "internalFrameClosing" event. How to find list of all index in Neo4j? neo4j-server.properties file location SASLError using PLAIN: not-authorized

Ads

 
Advertisement null

Ads