How to put the logo in login form using swings/awt?

How to put the logo in login form using swings/awt?

Hi,

How to put the logo in login form using swings/awt?

I write the login form is working but i want to put the logo in login form

plz help

View Answers

June 21, 2012 at 4:52 PM

Here is an example that will display logo along with login form in Java Swing.

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

class LoginDemo extends JFrame{
 JButton SUBMIT;
 JLabel label1,label2,lab;
 final JTextField  text1,text2;
  LoginDemo(){
     lab=new JLabel();
     ImageIcon icon=new ImageIcon("c:/image.gif");
     lab.setIcon(icon);

    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");
    lab.setBounds(380,50,50,30);
    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(lab);
   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 if (!value1.equals(uname) && !value2.equals(pass)) {
     text1.setText("");
     text2.setText("");
    }
    }
    catch(Exception e){}
}
 });
  }

  public static void main(String arg[]){
  new LoginDemo();
}
}


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









Related Tutorials/Questions & Answers:
How to put the logo in login form using swings/awt?
Display Logo on login form using swing
Advertisements
How to put the image in footer in login form ?
java login form using netbeans
How to Create Login/ Registration Form using PHP and MYSQL
login form using java bean in eclipse
Login form using Jsp in hibernate - Hibernate
Login Form using Ajax
How to make login form in Struts 2?
Login Form with Java GUI using Netbeans
how to login form through spring dao module
add cookies to login form in jsp by using struts2.0 framework
Login Form
Login Form
login form
login form
How to design a form using java?
login and registration form using servlet and authentication through mysql
Using java script do login form having fields with condition.
Spring 4: Login Form using Spring MVC and Hibernate Example
Creating Login Page In JSF using NetBeans
login form validation - JSP-Servlet
how to genrate login id and password after submitting the sign up form?
administrator login form
Struts 2.1.8 Login Form
PHP MySQL Login Form
Spring Security Authorized Access Using Custom Login Form
How to design a circle logo, design a circle logo, a circle logo
How to put an image on a JButton?
Login form and registration
Spring login form application
How to design home logo, design home logo, home logo
How to validate form using Spring MVC?
Spring alternative to Form Based Login
How to make Spring web Login form?
how to put php in javascript
login form - JSP-Servlet
how to write a jsp form using html
How to put points on a JButton
Login Form
Login Form in Java - Java Beginners
standart login form for messenger in java
standart login form for messenger in java
Login form in jscript
How to implement Captcha in PHP Form using GD Library
how to update values of a html form into an excel table using java servlets?
how to load values of html form into an excel table using java servlet?
How to display data in form using aryylist in struts - Java Beginners
how to put the conditions for empcode in java
how to prepare railway reservation form using core java concepts

Ads