Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 799413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T23:07:21+00:00 2026-05-14T23:07:21+00:00

I would like to create a login form for my application with the possibility

  • 0

I would like to create a login form for my application with the possibility to add or remove users for an sqlite database, i have created the table users(nam, pass) but i can’t unclud it in my login form, it someone could help me

this is my login code:

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;


public class login extends JFrame{

 // Variables declaration

private JLabel jLabel1;

private JLabel jLabel2;

private JTextField jTextField1;

private JPasswordField jPasswordField1;

private JButton jButton1;

private JPanel contentPane;

// End of variables declaration



public login(){

 super();

 create();

 this.setVisible(true);

 }


private void create(){

jLabel1 = new JLabel();

jLabel2 = new JLabel();

jTextField1 = new JTextField();

jPasswordField1 = new JPasswordField();

jButton1 = new JButton();

contentPane = (JPanel)this.getContentPane();


 //

 // jLabel1

 //

 jLabel1.setHorizontalAlignment(SwingConstants.LEFT);

 jLabel1.setForeground(new Color(0, 0, 255));

 jLabel1.setText("username:");

 //

 // jLabel2

 //

  jLabel2.setHorizontalAlignment(SwingConstants.LEFT);

  jLabel2.setForeground(new Color(0, 0, 255));

  jLabel2.setText("password:");

 //

 // jTextField1

 //

  jTextField1.setForeground(new Color(0, 0, 255));

  jTextField1.setSelectedTextColor(new Color(0, 0, 255));

  jTextField1.setToolTipText("Enter your username");

  jTextField1.addActionListener(new ActionListener() {

     public void actionPerformed(ActionEvent e){

    jTextField1_actionPerformed(e);

  }

 });

 //

 // jPasswordField1

 //

  jPasswordField1.setForeground(new Color(0, 0, 255));

  jPasswordField1.setToolTipText("Enter your password");

  jPasswordField1.addActionListener(new ActionListener() {

   public void actionPerformed(ActionEvent e){

    jPasswordField1_actionPerformed(e);

   }

  });

 //

 // jButton1

 //

  jButton1.setBackground(new Color(204, 204, 204));

  jButton1.setForeground(new Color(0, 0, 255));

  jButton1.setText("Login");

  jButton1.addActionListener(new ActionListener() {

   public void actionPerformed(ActionEvent e){

     jButton1_actionPerformed(e);

    }

   });

   //

   // contentPane

   //

   contentPane.setLayout(null);

   contentPane.setBorder(BorderFactory.createEtchedBorder());

   contentPane.setBackground(new Color(204, 204, 204));

   addComponent(contentPane, jLabel1, 5,10,106,18);

   addComponent(contentPane, jLabel2, 5,47,97,18);

   addComponent(contentPane, jTextField1, 110,10,183,22);

   addComponent(contentPane, jPasswordField1, 110,45,183,22);

   addComponent(contentPane, jButton1, 150,75,83,28);

   //

   // login

   //

   this.setTitle("Login To Members Area");

   this.setLocation(new Point(76, 182));

   this.setSize(new Dimension(335, 141));

   this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

   this.setResizable(false);

   }



    /** Add Component Without a Layout Manager (Absolute Positioning) */

    private void addComponent(Container container,Component c,int x,int y,int width,int height){

   c.setBounds(x,y,width,height);

     container.add(c);

   }



    private void jTextField1_actionPerformed(ActionEvent e){


   }



      private void jPasswordField1_actionPerformed(ActionEvent e){



    }



    private void jButton1_actionPerformed(ActionEvent e){

    System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");

   String username = new String(jTextField1.getText());

    String password = new String(jPasswordField1.getText());



   if(username.equals("") || password.equals("")){// If password and username is empty > Do this >>>

     jButton1.setEnabled(false);

    JLabel errorFields = new JLabel("<HTML><FONT COLOR = Blue>You must enter a username and password to login.</FONT></HTML>");

     JOptionPane.showMessageDialog(null,errorFields);

     jTextField1.setText("");

     jPasswordField1.setText("");

     jButton1.setEnabled(true);

     this.setVisible(true);

    } else{

       JLabel optionLabel = new JLabel("<HTML><FONT COLOR = Blue>You entered</FONT><FONT COLOR   = RED> <B>"+username+"</B></FONT> <FONT COLOR = Blue>as your username.<BR> Is this correct?</FONT></HTML>");

      int confirm =JOptionPane.showConfirmDialog(null,optionLabel);

       switch(confirm){ // Switch > Case

     case JOptionPane.YES_OPTION: // Attempt to Login user

       jButton1.setEnabled(false); // Set button enable to false to prevent 2 login attempts

     break;

      case JOptionPane.NO_OPTION: // No Case.(Go back. Set text to 0)

      jButton1.setEnabled(false);

     jTextField1.setText("");

      jPasswordField1.setText("");

      jButton1.setEnabled(true);

      break;

      case JOptionPane.CANCEL_OPTION: // Cancel Case.(Go back. Set text to 0)

      jButton1.setEnabled(false);

     jTextField1.setText("");

     jPasswordField1.setText("");

    jButton1.setEnabled(true);

    break;



    } // End Switch > Case

  }

}



 public static void main(String[] args){

  JFrame.setDefaultLookAndFeelDecorated(true);

 JDialog.setDefaultLookAndFeelDecorated(true);

 try{

  UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

  }catch (Exception ex){

   System.out.println("Failed loading L&F: ");

    System.out.println(ex);

   }

   new login();

 };


 }

my connectDb class :

public class Connectdb {


   private static  Connection connect;

   private static String url ="jdbc:sqlite:data.db"; 
   private static Statement st;
   private static ResultSet rs;

   /**
 * Constructeur privé d'une connection à la bd unique
 */
private ConnectionBd(){
        try {

            Class.forName("org.sqlite.JDBC");

            connect = DriverManager.getConnection(url);


            } catch (ClassNotFoundException ex) {
                                                 Logger.getLogger(ex.getName()).log(Level.SEVERE, null, ex);
                                                 } catch (SQLException e) {
                                                                                          System.exit(e.getErrorCode());
                                                               }

    }

public static Connection getInstance(){

       if(connect == null){
        new Connectdb();

         }else{
              }
return connect;

}

    /**
 * @return 
 */
    public static void initTable(String query){

    try {
        Statement state = getInstance().createStatement(ResultSet.TYPE_FORWARD_ONLY,
                            ResultSet.CONCUR_READ_ONLY);
        ResultSet res = state.executeQuery(query);
        res.close();
        state.close();


       } catch (SQLException e) {
        JOptionPane.showMessageDialog(null, e.getMessage(), "ERROR ! ", JOptionPane.ERROR_MESSAGE);
                                 }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T23:07:22+00:00Added an answer on May 14, 2026 at 11:07 pm

    You should read about JDBC and I would recommend to use JavaDB as database if you only use it with your Java application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to use formtastic to create form but I don't have a
i would like create a array of structure which have a dynamic array :
I would like to create an application which can learn to classify a sequence
I would like to create web application with admin/checkout sections being secured. Assuming I
I would like to create a login field everywhere on the top of my
I have a user input form here: http://www.7bks.com/create (Google login required) When you first
I'd like to add several different user types to my rails application. I have
I would like to add a row to photo_albums table in my db containing
I' trying to create a simple login form where users should be able to
I would like to create this shape using just css. I am pretty sure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.