Retourner dans le main une valeur obtenue dans ActionPerformed
Bonjour,
Mon problème se situe dans le titre, j'aimerai retourner dans mon main, une valeur que je trouve dans la méthode ActionPerformed, voici les codes :
FenetreConnexion.java :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
| package stockmanager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class FenetreConnexion extends JFrame implements ActionListener
{
ResultSet resultat = null;
private JPanel container = new JPanel();
private JPanel panCont = new JPanel();
private JLabel logoSoft = new JLabel(new ImageIcon("logo.png"));
private JLabel logoEntreprise = new JLabel(new ImageIcon("logo_Kode.png"));
private JTextField txtLogin = new JTextField("",15);
private JTextField txtPass = new JTextField("",15);
private JLabel labelLogin = new JLabel("Login :");
private JLabel labelPass = new JLabel("Mot de passe :");
private JButton boutonConnexion = new JButton("Connexion");
public String FenetreConnexion()
{
String Fonction;
// Paramètres de base pour la fenêtre
this.setTitle("Fenêtre de connexion de StockManager");
this.setSize(1000, 760);
container.setBackground(Color.WHITE);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
container.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = 0;
gbc.weightx = 0.3;
gbc.weighty = 0.2;
container.add(logoSoft, gbc);
[....]
// Les champs si dessous seront égaux en taille
txtLogin.setPreferredSize(txtPass.getPreferredSize());
txtLogin.setMinimumSize(txtPass.getMinimumSize());
labelLogin.setPreferredSize(labelPass.getPreferredSize());
labelLogin.setMinimumSize(labelPass.getMinimumSize());
boutonConnexion.addActionListener(this);
this.setContentPane(container);
this.setBackground(Color.WHITE);
this.setResizable(true);
this.setVisible(true);
return Fonction;
}
public JTextField getTxtLoginField(){
return txtLogin;
}
public JTextField getTxtPassField(){
return txtPass;
}
@Override
public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();
if (source.equals(boutonConnexion))
{
try {
DataBaseConnection dbc = new DataBaseConnection();
Connection con = dbc.connectDataBase();
Statement req;
req = con.createStatement();
ResultSet reqTotale = req.executeQuery("SELECT Login, MotDePasse, Fonction FROM `activedirectory` WHERE Login= '"+txtLogin.getText()+"' AND MotDePasse = '"+txtPass.getText()+"'");
while (reqTotale.next())
{
System.out.println(reqTotale.getString(1));
System.out.println(reqTotale.getString(2));
System.out.println(reqTotale.getString(3));
if (reqTotale.getString(1).equals(txtLogin.getText()) && reqTotale.getString(2).equals(txtPass.getText()))
{
/* JE VEUX RETOURNER reqTotale.getString(3) QUI VAUT NORMALEMENT LA FONCTION QUI EST ASSOCIEE AU LOGIN/MDP*/
}
}
}
catch (SQLException e1)
{
}
}
}
} |
Le main :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
package stockmanager;
import ...
public class StockManager {
public static void main(String[] args) throws Exception {
// Listes //////////////////////////////////////////////
List listCategories = new ArrayList();
Map listInfos = new TreeMap();
List<Produit> listProduits = new ArrayList<Produit>();
///////////////////////////////
// Creation des tableaux à l'ouverture ///////////////////
EnumCategorie openListcategorie = new EnumCategorie();
listCategories = openListcategorie.createListeCategorie();
System.out.println(listCategories);
EnumInfos openListInfos = new EnumInfos();
listInfos = openListInfos.createListeInfos();
System.out.println(listInfos);
EnumProduits openListProduits = new EnumProduits();
listProduits = openListProduits.createListeProduits();
System.out.println(listProduits);
//////////////////////////////////////////
// TEST !!!!!!! /////////////////////////////////
/*EnumCategorie categorie2 = new EnumCategorie();
categorie2.addCategory("Sand",500);
EnumCategorie categorie3 = new EnumCategorie();
categorie3.deleteCategory("Sandwich");
EnumCategorie categorie3 = new EnumCategorie();
categorie3.deleteCategory("Sandw");*/
////////////////////////////////////////////////
// IHM ////////////////////////////////////////
FenetreConnexion fc = new FenetreConnexion();
////////////////////////////////////////////////
}
} |
Merci d'avance pour votre aide !
PS : Mon niveau en java est bien loin de l'excellence, cependant je ne recherche pas la maintenabilité et l'amélioration du soft.