-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFenetre.java
More file actions
195 lines (169 loc) · 6.55 KB
/
Fenetre.java
File metadata and controls
195 lines (169 loc) · 6.55 KB
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
package formulaireProject;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import javax.swing.DefaultCellEditor;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JToolBar;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.DefaultTableCellRenderer;
//la fenetre principale
public class Fenetre extends JFrame implements Serializable{
/**
*
*/
protected File fichier = new File("/home/nabirni/eclipse-workspace/formulaireProject/src/formulaireProject/files/data");
private static final long serialVersionUID = 1L;
private JMenuBar menuBar = new JMenuBar();
private JToolBar toolbar = new JToolBar();
private JPopupMenu popupMenu = new JPopupMenu();
private JPanel centerContainer = new JPanel();
private JTable tableau;
private JComboBox paysBox;
private String listPays[] = {"Niger", "Mali", "Burkina", "Soudan"};
private String[] titres = {"id","nom","prenom","pays","adress","email","phone","suppression"};
private Object[][] donnees = {
{1,"Moussa", "Ismael",listPays[0],"Kharthoum","ismael@gmail.com",118322681,"delete"},
{2,"Ali", "Ismael",listPays[0],"Kharthoum","ismael@gmail.com",118322681,"delete"},
{3,"Moussa", "Ismael",listPays[0],"Kharthoum","ismael@gmail.com",118322681,"delete"},
{4,"Moussa", "Ismael",listPays[0],"Kharthoum","ismael@gmail.com",118322681,"delete"},
{5,"Moussa", "Ismael",listPays[0],"Kharthoum","ismael@gmail.com",118322681,"delete"},
{6,"Moussa", "Ismael",listPays[0],"Kharthoum","ismael@gmail.com",118322681,"delete"},
};
private JSplitPane splitPane;
private JTabbedPane onglets;
private Donnees lesDonnees;
private JButton btnAjouterLigne = new JButton("ajouter une ligne");
//START OF CONSTRUCTOR
public Fenetre() {
this.setTitle("liste des abonnes");
this.setSize(1000, 600);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
menu();
toolbar();
popupMenu();
initComponent();
this.setJMenuBar(menuBar);
this.getContentPane().add(toolbar, BorderLayout.NORTH);
this.getContentPane().add(splitPane, BorderLayout.CENTER);
this.getContentPane().add(btnAjouterLigne, BorderLayout.SOUTH);
}
//========================END OF CONSTRUCTOR
private void initComponent() {
tableau = new JTable(new Tableau(donnees, titres));
tableau.setRowHeight(35);
paysBox = new JComboBox(listPays);
this.tableau.getColumn("suppression").setCellEditor(new SuppButtonEditor(new JCheckBox()));
this.tableau.getColumn("pays").setCellEditor(new DefaultCellEditor(paysBox));
this.tableau.getColumn("pays").setCellRenderer(new DefaultTableCellRenderer());
// tableau.setBackground(new Color(231, 233, 242));
onglet();
splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new Arbre(), onglets);
splitPane.setOneTouchExpandable(false);
splitPane.setDividerSize(5);
splitPane.setDividerLocation(175);
btnAjouterLigne.addActionListener(new AjouterLigne());
}
private void menu() {
JMenu file = new JMenu("fichier");
JMenu edition = new JMenu("Edition");
JMenu options = new JMenu("Options");
JMenu help = new JMenu("Aide");
JMenuItem nouveau = new JMenuItem("noveau");
JMenuItem ouvrir = new JMenuItem("ouvrir");
JMenuItem fermer = new JMenuItem("fermer");
file.add(nouveau);
file.add(ouvrir);
file.add(fermer);
fermer.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
menuBar.add(file);
menuBar.add(edition);
menuBar.add(options);
menuBar.add(help);
}
private void toolbar() {
// JButton ajouterCellule = new JButton(new ImageIcon("/home/nabirni/eclipse-workspace/formulaireInscription/src/formulaireInscription/img/ajout.png"));
JButton homeCellule = new JButton(new ImageIcon("/home/nabirni/eclipse-workspace/formulaireProject/img/home.png"));
JButton playCellule = new JButton(new ImageIcon("/home/nabirni/eclipse-workspace/formulaireProject/img/play.png"));
JButton squareCellule = new JButton(new ImageIcon("/home/nabirni/eclipse-workspace/formulaireProject/img/square.png"));
toolbar.add(homeCellule);
// toolbar.add(ajouterCellule);
toolbar.add(playCellule);
toolbar.add(squareCellule);
}//end of method toolbar()
private void popupMenu() {
JMenu popupOuvrir= new JMenu("fichier");
JMenu popupEdition = new JMenu("Edition");
JMenu popupFermer = new JMenu("Options");
// this.addMouseListener(new MouseAdapter() {
// public void mouseReleased(MouseEvent e) {
// if(e.getButton() == MouseEvent.BUTTON3) {
// popupMenu.add(popupOuvrir);
// popupMenu.add(popupEdition);
// popupMenu.add(popupFermer);
// popupMenu.show(centerContainer, e.getX(), e.getY());
// }
// }
// });
}
private void onglet() {
onglets = new JTabbedPane();
onglets.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent event) {
try(FileInputStream fis = new FileInputStream(Inscription.fichier);
BufferedInputStream bis = new BufferedInputStream (fis);
ObjectInputStream ois = new ObjectInputStream(bis)){
UserInfos infos = (UserInfos)ois.readObject();
lesDonnees = new Donnees(infos.toString());
ois.close();
} catch (FileNotFoundException e) {
System.err.println("fichier introuvable");
e.printStackTrace();
} catch (IOException e) {
System.err.println("probleme de lecture du fichier");
e.printStackTrace();
} catch (ClassNotFoundException e) {
System.err.println("aucune sauvegarde trouvee");
e.printStackTrace();
}
}
});
onglets.add("Tableau", new JScrollPane(tableau));
onglets.add("donnees", lesDonnees);
}
//listener pour ajouter une nouvelle ligne de donnees
private class AjouterLigne implements ActionListener{
public void actionPerformed(ActionEvent event ) {
Object[] donnee =
{7,"NouvelleLigne", "Ismael","Soudan","Kharthoum","ismael@gmail.com",118322681,"delete"};
((Tableau)tableau.getModel()).addRow(donnee);
}
}
}