Guten Morgen Leute,
es geht immer noch um meinen Login.
Und zwar übergebe ich bzw. will ich aus zwei Textfeldern den Inhalt über getText() als Paramter an einen Button ActionListner übergeben.
Ich habe noch eine Klasse LoginCheck die, die eingegebenen Daten auswerten soll.
In dieser Klasse mache ich eine Testausgabe ob meine Parameter ankommen, das tun sie, aber als null. Heißt es steht nicht drin was drin stehen soll.
Meine Gui.
Meine Login Check.
Meine Action Klasse
Ich bin der Meinung das, dies alles so sein müsste, aber das Programm sagt mir etwas anderes. Woran liegt, was mache ich da falsch?
Vielen Dank für eure Zeit und Hilfe.
Mfg Lit-Web
es geht immer noch um meinen Login.
Und zwar übergebe ich bzw. will ich aus zwei Textfeldern den Inhalt über getText() als Paramter an einen Button ActionListner übergeben.
Ich habe noch eine Klasse LoginCheck die, die eingegebenen Daten auswerten soll.
In dieser Klasse mache ich eine Testausgabe ob meine Parameter ankommen, das tun sie, aber als null. Heißt es steht nicht drin was drin stehen soll.
Meine Gui.
Java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
public class LoginGuiElement extends JPanel {
protected JLabel lblLogName;
protected JLabel lblPwd;
protected GridBagLayout pnlLoginLayout;
protected JTextField loginNameField;
protected JTextField loginPwdField;
protected JButton loginButton;
protected String vName;
protected String nName;
/**
*
* Konstruktor gibt das fertige Panel mit allen Loginelementen zurück
*
* */
public LoginGuiElement () {
this.setSize( 500, 500 );
this.setLayout( this.createLogPanelLayout() );
this.setPreferredSize( new Dimension( 500, 150 ) );
this.setBackground( Color.white );
this.add( this.returnLblLogName() );
this.add( this.returnLblPwd() );
this.add( this.returnNameField() );
this.add( this.returnPwdField() );
this.add( this.returnBtnLogin() );
vName = this.returnNameField().getText();
nName = this.returnPwdField().getText();
System.out.println( vName );
System.out.println( nName );
this.setVisible( true );
}
/**
*
* Label Loginname
*
* */
protected JLabel returnLblLogName () {
lblLogName = new JLabel();
Font f = new Font( "Arial", Font.BOLD, 12 );
lblLogName.setText( "Loginname" );
lblLogName.setSize( 120, 20 );
lblLogName.setFont( f );
lblLogName.setForeground( Color.black );
lblLogName.setLocation( 10, 40 );
lblLogName.setVisible( true );
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 100;
gbc.weighty = 20;
pnlLoginLayout.setConstraints( lblLogName, gbc );
return lblLogName;
}
/**
*
* Label Passwortext
*
* */
protected JLabel returnLblPwd () {
lblPwd = new JLabel();
Font f = new Font( "Arial", Font.BOLD, 12 );
lblPwd.setText( "Passwort" );
lblPwd.setSize( 120, 20 );
lblPwd.setFont( f );
lblPwd.setForeground( Color.black );
lblPwd.setLocation( 10, 40 );
lblPwd.setVisible( true );
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 100;
gbc.weighty = 20;
pnlLoginLayout.setConstraints( lblPwd, gbc );
return lblPwd;
}
/**
*
* Eingabefeld für den Loginnamen
*
* */
protected JTextField returnNameField () {
loginNameField = new JTextField();
loginNameField.setPreferredSize( new Dimension( 120, 20 ) );
loginNameField.setVisible( true );
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 120;
gbc.weighty = 20;
pnlLoginLayout.setConstraints( loginNameField, gbc );
return loginNameField;
}
/**
*
* Eingabefeld für die Passworteingabe
* von hier aus soll der Focus Event ausgelöst werden wenn der Focus des Feldes verlassen wird
*
* */
protected JTextField returnPwdField () {
loginPwdField = new JTextField();
loginPwdField.setPreferredSize( new Dimension( 120, 20 ) );
loginPwdField.setVisible( true );
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 120;
gbc.weighty = 20;
pnlLoginLayout.setConstraints( loginPwdField, gbc );
return loginPwdField;
}
/**
*
* Login Button der einen Event feuert um sich ins System einzuloggen
*
* */
protected JButton returnBtnLogin () {
loginButton = new JButton();
loginButton.setPreferredSize( new Dimension( 120, 20 ) );
loginButton.setText( "Login" );
loginButton.addActionListener( new BtnLoginAction( this, vName, nName ) );
loginButton.setVisible( true );
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 2;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 120;
gbc.weighty = 20;
pnlLoginLayout.setConstraints( loginButton, gbc );
return loginButton;
}
/**
*
* Layoutmanger wird ans Panel übergeben
*
* */
protected GridBagLayout createLogPanelLayout () {
pnlLoginLayout = new GridBagLayout();
return pnlLoginLayout;
}
}
Meine Login Check.
Java:
import java.sql.*;
public class LoginCheck {
protected Connection dbCon;
protected Statement stmt;
protected boolean logged;
public LoginCheck ( DatabaseConnect pDbCon ) {
dbCon = pDbCon.connectToDb();
try {
stmt = dbCon.createStatement();
} catch ( SQLException e ) {
e.printStackTrace();
}
}
public boolean login ( String pVorname, String pNachname ) {
try {
int cntLog = 0;
String sqlLog = "SELECT Count(*) As cntLog, vorname, nachname FROM tsv_mitglieder WHERE" +
" vorname = '" + pVorname + "' AND" +
" nachname = '" + pNachname + "'";
ResultSet resultRows = stmt.executeQuery( sqlLog );
while( resultRows.next() ) {
cntLog = resultRows.getInt( "cntLog" );
}
System.out.println( cntLog );
System.out.println( pVorname );
System.out.println( pNachname );
if ( cntLog > 0 ) {
logged = true;
} else {
logged = false;
}
} catch( SQLException e ) {
e.printStackTrace();
}
return logged;
}
}
Meine Action Klasse
Java:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class BtnLoginAction implements ActionListener {
protected JPanel logPanel;
protected String logName;
protected String logPwd;
protected LoginCheck ckl;
public BtnLoginAction ( JPanel pLogPanel, String pLogName, String pLogPwd ) {
logPanel = pLogPanel;
logName = pLogName;
logPwd = pLogPwd;
ckl = new LoginCheck( new DatabaseConnect( "ConfigFiles/mysqlProperties.txt" ) );
}
public void actionPerformed ( ActionEvent pEvent ) {
if ( ckl.login( logName, logPwd ) == true ) {
logPanel.setVisible( false );
}
}
}
Ich bin der Meinung das, dies alles so sein müsste, aber das Programm sagt mir etwas anderes. Woran liegt, was mache ich da falsch?
Vielen Dank für eure Zeit und Hilfe.
Mfg Lit-Web