-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUIClient.java
352 lines (314 loc) · 15.5 KB
/
GUIClient.java
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
import java.lang.Float;
import java.rmi.RemoteException;
import java.util.List;
import java.util.Vector;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/*
* GUIClient.java
*
* Created on April 15, 2007, 4:01 PM
*/
/**
*
* @author Yann
*/
public class GUIClient extends javax.swing.JFrame {
private ImplClient monClient;
private boolean isConnected;
private Vector<Article> lesArticles;
private javax.swing.table.DefaultTableModel monTableModel;
private int curArticle= -1;
private int maSelection= -1;
private boolean mise = false;
/** Creates new form GUIClient */
public GUIClient() {
String monLogin = "";
while(monLogin=="")
monLogin = JOptionPane.showInputDialog("Entrez votre nom d'utilisateur");
String monPort = JOptionPane.showInputDialog("Entrez votre numero de port");
try {
monClient = new ImplClient(monLogin, Integer.parseInt(monPort));
} catch (NumberFormatException ex) {
ex.printStackTrace();
} catch (RemoteException ex) {
ex.printStackTrace();
}
initComponents();
isConnected = false;
lesArticles = new Vector<Article>();
createjTable();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
private void initComponents() {
jToolBar1 = new javax.swing.JToolBar();
jScrollPane1 = new javax.swing.JScrollPane();
jTableArticles = new javax.swing.JTable();
jToolBar2 = new javax.swing.JToolBar();
jButtonMiseAJour = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
jLabel1 = new javax.swing.JLabel();
jButtonEffectuerMise = new javax.swing.JButton();
jTextFieldMiseCourante = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jTextFieldVotreMise = new javax.swing.JTextField();
jLabel4 = new javax.swing.JLabel();
jTextFieldMonCredit = new javax.swing.JTextField();
jTextFieldTempsActuel = new javax.swing.JTextField();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItemConnexionDeconnexion = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});
jTableArticles.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{},
{},
{},
{}
},
new String [] {
}
));
jScrollPane1.setViewportView(jTableArticles);
jButtonMiseAJour.setText("Mise \u00e0 jour");
jButtonMiseAJour.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonMiseAJourActionPerformed(evt);
}
});
jToolBar2.add(jButtonMiseAJour);
jLabel1.setText("Temps actuel : ");
jButtonEffectuerMise.setText("Effectuer une mise");
jButtonEffectuerMise.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonEffectuerMiseActionPerformed(evt);
}
});
jTextFieldMiseCourante.setEditable(false);
jLabel2.setText("Mise Courante :");
jLabel3.setText("Votre mise :");
jLabel4.setText("Cr\u00e9dit :");
jTextFieldMonCredit.setEditable(false);
jTextFieldTempsActuel.setEditable(false);
jMenu1.setText("Menu");
jMenuItemConnexionDeconnexion.setText("Connexion/D\u00e9connexion");
jMenuItemConnexionDeconnexion.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemConnexionDeconnexionActionPerformed(evt);
}
});
jMenu1.add(jMenuItemConnexionDeconnexion);
jMenuBar1.add(jMenu1);
setJMenuBar(jMenuBar1);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 615, Short.MAX_VALUE))
.add(jToolBar2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 625, Short.MAX_VALUE)
.add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 625, Short.MAX_VALUE)
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel2)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTextFieldMiseCourante, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 55, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jLabel3)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTextFieldVotreMise, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 55, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jButtonEffectuerMise))
.add(layout.createSequentialGroup()
.addContainerGap()
.add(jLabel1)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTextFieldTempsActuel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 183, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(30, 30, 30)
.add(jLabel4)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jTextFieldMonCredit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 71, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(jToolBar2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 25, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 203, Short.MAX_VALUE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jLabel2)
.add(jTextFieldMiseCourante, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel3)
.add(jTextFieldVotreMise, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jButtonEffectuerMise))
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(jTextFieldMonCredit, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel4)
.add(jTextFieldTempsActuel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.addContainerGap())
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
monClient.deconnexionEbay();
lesArticles.clear();
updatejTable();
isConnected = false;
}//GEN-LAST:event_formWindowClosing
private void jButtonMiseAJourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMiseAJourActionPerformed
lesArticles = monClient.getListArticle();
String s = "";
s+=monClient.getCredit();
jTextFieldMonCredit.setText(s);
updatejTable();
if(monClient.getcurArticle().IsTimeOut())
JOptionPane.showMessageDialog(this, "La periode de mise est ecoule, "+lesArticles.elementAt(curArticle).getLeader()+" remporte les mises.",
"Message fin Mise",JOptionPane.WARNING_MESSAGE);
}//GEN-LAST:event_jButtonMiseAJourActionPerformed
private void jButtonEffectuerMiseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEffectuerMiseActionPerformed
// TODO add your handling code here:
String s = jTextFieldVotreMise.getText();
Float f = new Float(s);
monClient.setcurArticle(maSelection);
if(!monClient.getcurArticle().IsTimeOut()){
monClient.faireMise(f.floatValue());
}
else{ JOptionPane.showMessageDialog(this, "cet item est deja expire", "Avertissement",JOptionPane.WARNING_MESSAGE);}
}//GEN-LAST:event_jButtonEffectuerMiseActionPerformed
private void jMenuItemConnexionDeconnexionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemConnexionDeconnexionActionPerformed
//Connexion
if(!isConnected){
GUIDefAdresse g = new GUIDefAdresse(this);
g.setVisible(true);
}
else
{
monClient.deconnexionEbay();
lesArticles.clear();
updatejTable();
isConnected = false;
}
//Deconnexion
//else
}//GEN-LAST:event_jMenuItemConnexionDeconnexionActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new GUIClient().setVisible(true);
}
});
}
public void updatejTable()
{
while(monTableModel.getRowCount() > 0)
monTableModel.removeRow(0);
for(int i = 0; i<lesArticles.size(); i++)
monTableModel.addRow(new Object[] {lesArticles.get(i).id,lesArticles.get(i).getNom(),lesArticles.get(i).getPrix(),lesArticles.get(i).bestMise, lesArticles.get(i).getDateFin()});
}
public void createjTable()
{
monTableModel = new javax.swing.table.DefaultTableModel();
monTableModel.addColumn("ID#");
monTableModel.addColumn("Nom de l'article");
monTableModel.addColumn("Prix de base");
monTableModel.addColumn("Mise courante");
monTableModel.addColumn("Date de fin");
for(int i = 0; i<lesArticles.size(); i++)
monTableModel.addRow(new Object[] {lesArticles.get(i).id,lesArticles.get(i).getNom(),lesArticles.get(i).getPrix(),lesArticles.get(i).bestMise, lesArticles.get(i).getDateFin()});
jTableArticles.setModel(monTableModel);
ListSelectionModel rowSM = jTableArticles.getSelectionModel();
rowSM.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
else
{
ListSelectionModel rowSM = (ListSelectionModel)e.getSource();
int selectedIndex = rowSM.getMinSelectionIndex();
indexChangeTable(selectedIndex);
}
}
});
}
void connexion2(String adrEbay, String adrPpal) {
if(monClient.connexionEbay(adrEbay,adrPpal)){
lesArticles = monClient.getListArticle();
updatejTable();
String s = "";
s+=monClient.getCredit();
jTextFieldMonCredit.setText(s);
isConnected = true;
}
}
public void indexChangeTable(int i) {
if(i>=0){
float f = lesArticles.get(i).bestMise;
curArticle = i;
String s = "";
s+=f;
jTextFieldMiseCourante.setText(s);
jTextFieldVotreMise.setText(s);
maSelection = i;
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonEffectuerMise;
private javax.swing.JButton jButtonMiseAJour;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItemConnexionDeconnexion;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTable jTableArticles;
private javax.swing.JTextField jTextFieldMiseCourante;
private javax.swing.JTextField jTextFieldMonCredit;
private javax.swing.JTextField jTextFieldTempsActuel;
private javax.swing.JTextField jTextFieldVotreMise;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JToolBar jToolBar2;
// End of variables declaration//GEN-END:variables
private JList list;
}
class SharedListSelectionHandler implements ListSelectionListener {
private GUIClient monGUI;
public SharedListSelectionHandler(GUIClient g)
{
monGUI = g;
}
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel rowSM = (ListSelectionModel)e.getSource();
int selectedIndex = rowSM.getMinSelectionIndex();
System.out.println(selectedIndex);
monGUI.indexChangeTable(selectedIndex);
}
}