bonjour j'ai réalisé un formulaire de connection à une base de donné, seulement quand j'execute, y'a rien qui se passe, j'ai un message "
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at gestionst.FormLogin$3.actionPerformed(FormLogin.java:118) que je ne comprend pas, je débute en java merci de votre aide.
voila mon code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package gestionst;
 
import java.awt.BorderLayout;
import java.awt.EventQueue;
 
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
 
import java.awt.Label;
import java.awt.Font;
import java.awt.TextField;
import java.sql.Connection;
import java.sql.PreparedStatement;
 
import javax.swing.JPasswordField;
 
import java.awt.Panel;
import java.awt.Button;
 
import javax.swing.JLabel;
 
import com.jgoodies.forms.factories.DefaultComponentFactory;
//import com.mysql.jdbc.Connection;
//import com.mysql.jdbc.PreparedStatement;
 
import javax.swing.ImageIcon;
import javax.swing.SwingConstants;
 
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
 
import javax.swing.JTextPane;
import javax.swing.JButton;
 
import java.awt.Color;
 
public class FormLogin extends JFrame {
 
 
	private JPanel contentPane;
	private JPasswordField passwordField;
	private JLabel bl_U;
	private JLabel bl_P;
	private JComponent lbl_U;
	private JComponent lbl_P;
 
 
 
	/**
         * Launch the application.
         */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
 
			public void run() {
				try {
					FormLogin frame = new FormLogin();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
 
	/**
         * *Create the application
         * @return 
         */
 
	public  FormLogin(){
		initialize();
 
	}
 
	/*
	 * Initialise the content of jframe
	 */
	private void initialize() {
		// TODO Auto-generated method stub
	JFrame frame = new JFrame();
 
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1000, 580);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
 
		TextField textFUsermane = new TextField();
		textFUsermane.setBounds(490, 207, 239, 33);
		contentPane.add(textFUsermane);
 
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				   System.exit(0);
			}
		});
		btnCancel.setIcon(new ImageIcon(FormLogin.class.getResource("/images/login.png")));
		btnCancel.setFont(new Font("Tahoma", Font.PLAIN, 18));
		btnCancel.setBounds(255, 368, 134, 43);
		contentPane.add(btnCancel);
 
		JButton btnLogin = new JButton("Login");
		btnLogin.addActionListener(new ActionListener() {
 
			public void actionPerformed(ActionEvent e) {
 
				bl_U.setVisible(false);
				bl_P.setVisible(false);
				System.out.println("btn..");
 
				if(textFUsermane.getText().equals(""))	
				{
					bl_U.setVisible(true);
				}
				else if(String.valueOf(passwordField.getPassword()).equals("")){
					bl_P.setVisible(true);
				}
				else{
 
					System.out.println("connect..");
					Connection con= MyConnection.getConnection();
					PreparedStatement ps = null;
					ResultSet rs;
					String query="SELECT * From user WHERE  username=? and password=?";
 
					try	{
 
 
						ps.setString(1, textFUsermane.getText());
						ps.setString(2, String.valueOf(passwordField.getPassword()));
						rs=ps.executeQuery();
 
						if(rs.next())
						{
							MainForm mf = new MainForm();
							mf.setVisible(true);
							mf.pack();
							mf.setLocationRelativeTo(null);
							/* close the current form		*/
							this.dispose();
 
 
								}else{
 
									JOptionPane.showMessageDialog(null, "username/password invalid connection erroné");
								}
 
 
							}catch (SQLException ex){				
 
 
 
								Logger.getLogger(FormLogin.class.getName()).log(Level.SEVERE, null, ex);
								System.out.println("err : "+ex);
						}
						}
 
 
			}
 
			private void dispose() {
				// TODO Auto-generated method stub
 
			}
 
					});
 
 
 
 
 
 
		btnLogin.setIcon(new ImageIcon(FormLogin.class.getResource("/images/exit.jpg")));
		btnLogin.setFont(new Font("Tahoma", Font.PLAIN, 18));
		btnLogin.setBounds(607, 368, 134, 43);
		contentPane.add(btnLogin);
 
		JLabel lblUsername = DefaultComponentFactory.getInstance().createTitle("USERNAME :");
		lblUsername.setFont(new Font("Tahoma", Font.BOLD, 18));
		lblUsername.setBounds(255, 207, 149, 38);
		contentPane.add(lblUsername);
 
		JLabel lbl_P = DefaultComponentFactory.getInstance().createTitle("*");
		lbl_P.setForeground(Color.RED);
		lbl_P.setFont(new Font("Tahoma", Font.BOLD, 18));
		lbl_P.setBounds(751, 243, 45, 30);
		contentPane.add(lbl_P);
 
		JLabel lblPassword = DefaultComponentFactory.getInstance().createTitle("PASSWORD :");
		lblPassword.setFont(new Font("Tahoma", Font.BOLD, 18));
		lblPassword.setBounds(255, 256, 134, 26);
		contentPane.add(lblPassword);
 
		passwordField = new JPasswordField();
		passwordField.setBounds(490, 246, 239, 30);
		contentPane.add(passwordField);
 
		JLabel lbl_U = DefaultComponentFactory.getInstance().createTitle("*");
		lbl_U.setForeground(Color.RED);
		lbl_U.setFont(new Font("Tahoma", Font.BOLD, 18));
		lbl_U.setBounds(751, 215, 32, 22);
		contentPane.add(lbl_U);
 
		JLabel lblTitle = DefaultComponentFactory.getInstance().createTitle("AFIP  Bookseller");
		lblTitle.setFont(new Font("Tahoma", Font.BOLD, 35));
		lblTitle.setIcon(new ImageIcon(FormLogin.class.getResource("/images/afip.jpg")));
		lblTitle.setBounds(356, 38, 457, 90);
		contentPane.add(lblTitle);
 
		JLabel lblArrierrePlan = DefaultComponentFactory.getInstance().createTitle("");
		lblArrierrePlan.setForeground(Color.RED);
		lblArrierrePlan.setIcon(new ImageIcon(FormLogin.class.getResource("/images/arriere-plan .jpg")));
		lblArrierrePlan.setBounds(-11, 0, 1118, 612);
		contentPane.add(lblArrierrePlan);
	}
}