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 8870841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:50:09+00:00 2026-06-14T17:50:09+00:00

I am try to build an application based on MVC in Java and I

  • 0

I am try to build an application based on “MVC” in Java and I have 2 classes:
1: Functions and Actions
2: Buttons, Swing elements

I want to access from 1 Class to 2 Class and do specific action.

AccionesUsuarios.java

public class AccionesUsuarios{

private static BaseDatos conn;
private static iniciarSesionw dataLogin;

public void iniciarSesion(){
    dataLogin = new iniciarSesionw();
    String usr = "", pwd = "";
    usr = dataLogin.textLoginUser.getText().trim();
    pwd = dataLogin.textLoginPass.getText().trim();

    System.out.println("Usuario: "+usr);
    System.out.println("Contraseña: "+pwd);
    /*try {
        conn.openConnection();

        /*dataLogin = new iniciarSesionw();
        String username = dataLogin.textLoginUser.getText();
        String password = dataLogin.textLoginPass.getText();

        ComandoBaseDatos comando = new ComandoBaseDatos("SELECT * FROM Usuarios_Operadores WHERE Usuario = '123' AND Clave = '123'");
        ResultSet rs = comando.SQLExecute();

        while (rs.next()) {
            JOptionPane.showMessageDialog(null, "Correcto!");
        }
        conn.closeConnection();
    } catch (SQLException ex) {
        conn.getSqlMessage(ex);
    }*/     
}
}

iniciarSesionw.java

public class iniciarSesionw {

public JTextField textLoginUser;
public JTextField textLoginPass;
public JButton btnIngresar;

private static AccionesUsuarios au;

/*Launch the application */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                iniciarSesionw window = new iniciarSesionw();
                window.frmItcuautlaControl.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

public iniciarSesionw() {
    initialize();
}

private void initialize() { 

            textLoginUser = new JTextField();
    textLoginUser.setBounds(185, 110, 153, 27);
    panel.add(textLoginUser);
    textLoginUser.setColumns(10);

    textLoginPass = new JTextField();
    textLoginPass.setColumns(10);
    textLoginPass.setBounds(185, 148, 153, 27);
    panel.add(textLoginPass);

            btnIngresar = new JButton("Ingresar");
    btnIngresar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            au = new AccionesUsuarios();
            au.iniciarSesion();

        }
    });
}

But when print value of textLoginUser and textLoginPass are empty.

I hope I have explained and thanks in advance.

Edit:

Solved with @looper answer !! But now.. uncomment the section in AccionesUsuarios.java that contains connection to database and display those errors:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at Controlador.AccionesUsuarios.iniciarSesion(AccionesUsuarios.java:43)
at Vista.iniciarSesionw$2.actionPerformed(iniciarSesionw.java:124)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2012)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2335)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:404)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
and more....
  • 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-06-14T17:50:11+00:00Added an answer on June 14, 2026 at 5:50 pm

    The textfields are never set. You should get the contents in an other way:

    btnIngresar = new JButton("Ingresar");
    btnIngresar.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            au = new AccionesUsuarios();
            au.iniciarSesion(textLoginUser, textLoginPass);
    
        }
    });
    

    AccionesUsuarios.java

    public void iniciarSesion(String user, String pass){
        dataLogin = new iniciarSesionw();
        String usr = "", pwd = "";
        usr = user.trim();
        pwd = pass.trim();
    
        System.out.println("Usuario: "+usr);
        System.out.println("Contraseña: "+pwd);
    /*try {
            conn.openConnection();
    
            /*dataLogin = new iniciarSesionw();
            String username = usr;
            String password = pwd;
    
            ComandoBaseDatos comando = new ComandoBaseDatos("SELECT * FROM Usuarios_Operadores WHERE Usuario = '123' AND Clave = '123'");
            ResultSet rs = comando.SQLExecute();
    
            while (rs.next()) {
                JOptionPane.showMessageDialog(null, "Correcto!");
            }
            conn.closeConnection();
        } catch (SQLException ex) {
            conn.getSqlMessage(ex);
        }*/     
    

    As Capn Sparrow pointed out, you create a new instance of your iniciarSesionw-Class in your AccionesUsuarios.java which results in empty values ;).

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

Sidebar

Related Questions

I try to build a JSF 2.0 Web application which is using libraries including
I try build wrap panel with vertical buttons. Every button consist from image and
Iam trying to build an Facebook Application based on PHP. The Application is running
So I need to build an application that will receive xml request and based
I am trying to build an appliction based upon the pcredemo application. When I
I am trying to build a spring MVC application (basically for self trainning reasons).
I am working on a web-based application using asp.net 4.0. I have some dlls
I want to build a new Android project based on another project that is
I'm using CMake to build a Qt based application of mine on Windows with
I have a problem with my application for the iPhone. It's a tab based

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.