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
|
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class Mafenetre extends JFrame implements ActionListener, ItemListener{
//la barre de menus
JMenuBar br = new JMenuBar();
// Déclaration des menus
JMenu F = new JMenu("Fichier");
JMenu E = new JMenu("Help");
JMenu A = new JMenu("Affichage");
//Declarations des items de menus
JMenuItem A_C = new JMenuItem("Afficher les informations d une ville");
JMenuItem Q = new JMenuItem("Quitter");
JMenuItem C_A = new JMenuItem("Centre d aide");
JMenuItem A_P = new JMenuItem("A propos du logiciel");
JMenuItem C_C = new JMenuItem("Couleur de fond");
//déclaration de panels
private Carte pcentre;
JPanel pest = new JPanel();
JPanel pestn = new JPanel();
JPanel pestc = new JPanel();
JPanel psud = new JPanel();
JPanel pnord = new JPanel();
JPanel pnord1 = new JPanel();
JComboBox cb = new JComboBox();
JComboBox cc = new JComboBox();
public static final String[] nomcombo = {"dont le nom est","dont le code postale est"};
JComboBox crech = new JComboBox(nomcombo);
JLabel lvdep = new JLabel("Ville de départ");
JLabel lvar = new JLabel("Ville d'arrivée");
JLabel lval = new JLabel("Valider");
JLabel ldist = new JLabel("Distance :");
JLabel ltemp = new JLabel("Temps :");
JLabel lvp = new JLabel("Ville Proche:");
JLabel lrech = new JLabel("Recherche d'une ville");
JLabel nomv = new JLabel("Nom ville");
JLabel cdp = new JLabel("Code postal");
JTextField trech = new JTextField(20);
JTextField ldistr= new JTextField(10);
JTextField ltempr= new JTextField(10);
JTextField nomvr = new JTextField(10);
JTextField cdpr = new JTextField(10);
//JButton rech = new JButton("rechercher");
JButton bok = new JButton("OK");
JButton brech = new JButton("Rechercher");
private Ville[] t;
private ToutesLesVilles maroc;
public Mafenetre()
{
//Parametre de la fenetre, titre, taille, dimension
this.setTitle("Réalisation d'un Maroc Routier");
this.setSize(1024,768);
this.setLayout(new BorderLayout(15,10));
ldistr.setEditable(false);
ltempr.setEditable(false);
//nomvr.setEditable(false);
//cdpr.setEditable(false);
//Ecouteur sur le combobox
cb.addItemListener(this);
//Ecouteur pour sortir de l application
Q.addActionListener(this);
//Ecouteur dans le menu affichage
C_C.addActionListener(this);
C_C.setToolTipText("Changer la couleur de fond");
//Ecouteur sur le menu afficher les infos d une ville
A_C.addActionListener(this);
//ecouteur sur A_P
A_P.addActionListener(this);
//Ajout des items sur le menu fichier
F.add(A_C);
F.add(Q);
//Ajout des items sur le menu aide
E.add(C_A);
E.add(A_P);
//Ajout d un item sur le menu affichage
A.add(C_C);
//Ajout des menus : fichier et help sur la barre de menus
br.add(F);
br.add(A);
br.add(E);
//mettre la barre de menus sur la frame
this.setJMenuBar(br);
//Proprieté de la frame une qui va contenir la carte
//pcentre.setBackground(Color.red);
ToutesLesVilles maroc=new ToutesLesVilles();
t=maroc.charger("C:/Documents and Settings/Administrateur/Bureau/tout/carte/Ville.txt");
for(int i=0; i < t.length; i++)
{
try{
cb.addItem(t[i].getNom());
cc.addItem(t[i].getNom());
}
catch(Exception a)
{ }
}
pcentre = new Carte(maroc);
//Proprietés de la frame trois qui va contenir nos 2 labels avec les noms des réalisateurs et de l encadrant
psud.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Choix"));
psud.setLayout(new BoxLayout(psud,BoxLayout.X_AXIS));
psud.add(Box.createHorizontalStrut(20));
psud.add(lvdep);
psud.add(Box.createHorizontalStrut(10));
psud.add(cb);
psud.add(Box.createHorizontalStrut(20));
psud.add(lvar);
psud.add(Box.createHorizontalStrut(10));
psud.add(cc);
psud.add(Box.createHorizontalStrut(20));
psud.add(bok);
//panel nord
pnord.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Rechercher une ville"));
pnord.setLayout(new BorderLayout());
pnord.add(pnord1, BorderLayout.CENTER);
pnord.setToolTipText("Rechercher une ville sur la carte");
//panel nord 1 qui contient la zone de recherche
//pnord1.setLayout(new BoxLayout(pnord1,BoxLayout.X_AXIS));
pnord1.add(lrech);
pnord1.add(Box.createHorizontalStrut(1));
pnord1.add(crech);
pnord1.add(trech);
pnord1.add(brech);
//panel est
pest.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Resultat"));
pest.setLayout(new BorderLayout());
//panel est nord
pestn.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = gbc.gridy = 0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.insets = new Insets(10, 15, 0, 0);
pestn.add(ldist, gbc);
gbc.gridx =1;
gbc.gridy =0;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.insets = new Insets(10, 15, 0, 0);
pestn.add(ldistr, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.insets = new Insets(10, 15, 0, 0);
pestn.add(ltemp, gbc);
gbc.gridx = 1;
gbc.gridy = 1;
gbc.gridwidth = 1;
gbc.gridheight = 1;
gbc.weightx = 0;
gbc.weighty = 0;
gbc.insets = new Insets(10, 15, 0, 0);
pestn.add(ltempr, gbc);
//panel est centre
pestc.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),"Infos sur ville"));
pestc.setLayout(new GridBagLayout());
GridBagConstraints gbcd = new GridBagConstraints();
gbcd.gridx = gbc.gridy = 0;
gbcd.gridwidth = 1;
gbcd.gridheight = 1;
gbcd.weightx = 0;
gbcd.weighty = 0;
gbcd.insets = new Insets(10, 15, 0, 0);
pestc.add(nomv, gbcd);
gbcd.gridx =1;
gbcd.gridy =0;
gbcd.gridwidth = 1;
gbcd.gridheight = 1;
gbcd.weightx = 0;
gbcd.weighty = 0;
gbcd.insets = new Insets(10, 15, 0, 0);
pestc.add(nomvr, gbcd);
gbcd.gridx = 0;
gbcd.gridy = 1;
gbcd.gridwidth = 1;
gbcd.gridheight = 1;
gbcd.weightx = 0;
gbcd.weighty = 0;
gbcd.insets = new Insets(10, 15, 0, 0);
pestc.add(cdp, gbcd);
gbcd.gridx = 1;
gbcd.gridy = 1;
gbcd.gridwidth = 1;
gbcd.gridheight = 1;
gbcd.weightx = 0;
gbcd.weighty = 0;
gbcd.insets = new Insets(10, 15, 0, 0);
pestc.add(cdpr, gbcd);
pest.add(pestn, BorderLayout.NORTH);
pest.add(pestc, BorderLayout.CENTER);
//Ajouter nos panels sur la frame
this.add(pcentre,BorderLayout.CENTER);
this.add(pest,BorderLayout.EAST);
this.add(psud,BorderLayout.SOUTH);
this.add(pnord,BorderLayout.NORTH);
}
public void itemStateChanged(ItemEvent e){
if(e.getStateChange() == ItemEvent.SELECTED){
String texte = (String)cb.getSelectedItem();
try{
pcentre.setVilleSelectionnee(maroc.getVilleParNom(texte));
pcentre.setBackground(Color.red);
pcentre.updateUI();
}
catch(Exception e1){
System.out.println("Erreur");
}
}}
public void actionPerformed(ActionEvent argo) {
//Object source = argo.getSource();
//int source = JFrame.EXIT_ON_CLOSE;
if(argo.getSource() == Q)
{
int result = JOptionPane.showConfirmDialog(pcentre,"Voulez vous vraiment quittez l application","Quitter application",JOptionPane.YES_NO_OPTION);
if(result == JOptionPane.YES_OPTION) System.exit(0);
}
if(argo.getSource() == C_C)
{
Color color = JColorChooser.showDialog(this,"Choix d'une couleur",Color.RED);
pnord1.setBackground(color);
pnord.setBackground(color);
psud.setBackground(color);
pest.setBackground(color);
pestn.setBackground(color);
pestc.setBackground(color); }
if(argo.getSource() == A_C)
{
String string = JOptionPane.showInputDialog(null, "Entrez le nom de la ville") ;
int rep = 0;
if( string != null)
{
//System.out.println ("vous avez tapez:"+ string);
for(int i=0; i<t.length; i++){
if(t[i].getNom().equalsIgnoreCase(string)){
System.out.println ("vous avez tapez:"+ string);
System.out.println(+ t[i].getCode());
nomvr.setText(t[i].getNom());
//cdpr.setText(String(t[i].getCode()));
}
/* if (t[i].getNom() != string){
JOptionPane.showMessageDialog(this, "Entrer une ville");
string = JOptionPane.showInputDialog(null, "Entrez le nom de la ville") ;
}*/
} }
}
if(argo.getSource() == brech)
{
for(int i = 0; i<t.length;i++){
if(trech.getText().equals(t[i].getNom()))
System.out.println("vous avez choisi"+ trech.getText());}
}}
}
// la classe TInterface, la classe appelante$
import java.util.*;
import java.awt.*;
import javax.swing.*;
public class TInterface {
public static void main(String[]args)
{
Dimension tailleEcran = Toolkit.getDefaultToolkit().getScreenSize();
int hauteur = (int)tailleEcran.getHeight();
int largeur = (int)tailleEcran.getWidth();
//Initialisation d une nouvelle fenetre
Mafenetre fen = new Mafenetre();
//au centre de l'ecran
fen.setLocation((largeur-fen.getWidth())/2,(hauteur - fen.getHeight())/2);
//on rend notre fentre visible
fen.setVisible(true);
fen.setResizable(false);}
} |
Partager