217 lines
5.6 KiB
Java
217 lines
5.6 KiB
Java
package fr.blankoworld.ihm;
|
|
|
|
// Importations automatiques
|
|
|
|
import java.awt.BorderLayout;
|
|
import java.awt.event.ActionEvent;
|
|
import java.awt.event.ActionListener;
|
|
import java.awt.event.WindowEvent;
|
|
import java.awt.event.WindowListener;
|
|
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.JFrame;
|
|
import javax.swing.JMenu;
|
|
import javax.swing.JMenuBar;
|
|
import javax.swing.JMenuItem;
|
|
import javax.swing.JOptionPane;
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JTextArea;
|
|
import javax.swing.border.BevelBorder;
|
|
|
|
// Import personnel
|
|
|
|
import fr.blankoworld.ihm.IHMConnexion;
|
|
import fr.blankoworld.connexionBDD.Connexion;
|
|
|
|
public class IHMPrincipale extends JFrame {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
|
|
private JTextArea zoneTexteStatut;
|
|
private IHMConnexion conn;
|
|
private Connexion objetConnexion;
|
|
|
|
private JMenuItem MenuBdd_Connexion;
|
|
private JMenuItem MenuBdd_Fermer;
|
|
|
|
private boolean connecte = false;
|
|
|
|
/**
|
|
* @param args
|
|
*/
|
|
public static void main(String[] args) {
|
|
// TODO Auto-generated method stub
|
|
new IHMPrincipale().setVisible(true);
|
|
}
|
|
|
|
private IHMPrincipale() {
|
|
|
|
// Creation du menu Base de donnees
|
|
JMenu MenuBdd = new JMenu("Base de donnees");
|
|
MenuBdd_Connexion = new JMenuItem("Connexion");
|
|
MenuBdd_Fermer = new JMenuItem("Fermer");
|
|
MenuBdd_Fermer.setEnabled(false);
|
|
JMenuItem MenuBdd_Quitter = new JMenuItem("Quitter");
|
|
MenuBdd.add(MenuBdd_Connexion);
|
|
MenuBdd.add(MenuBdd_Fermer);
|
|
MenuBdd.addSeparator();
|
|
MenuBdd.add(MenuBdd_Quitter);
|
|
|
|
// Creation du menu Aide
|
|
JMenu MenuAide = new JMenu("Aide");
|
|
JMenuItem MenuAide_Apropos = new JMenuItem("A propos");
|
|
MenuAide.add(MenuAide_Apropos);
|
|
|
|
// Creation de la barre de menus
|
|
JMenuBar MenuPrincipal = new JMenuBar();
|
|
MenuPrincipal.add(MenuBdd);
|
|
MenuPrincipal.add(MenuAide);
|
|
|
|
//** Modification de la zone de texte
|
|
|
|
zoneTexteStatut = new JTextArea(6,60);
|
|
zoneTexteStatut.setEditable(false);
|
|
zoneTexteStatut.setBorder(new BevelBorder(BevelBorder.LOWERED));
|
|
|
|
//** Creation des panneaux **//
|
|
// Panneau au centre
|
|
JPanel Panneau_Centre = new JPanel();
|
|
Panneau_Centre.setBorder(BorderFactory.createTitledBorder("Resultat des requetes"));
|
|
|
|
// Panneau en bas
|
|
JPanel Panneau_Bas = new JPanel();
|
|
Panneau_Bas.setBorder(BorderFactory.createTitledBorder("Statut"));
|
|
|
|
// Ajout des boutons et zones de texte au panneau bas
|
|
Panneau_Bas.add(zoneTexteStatut);
|
|
|
|
// Ajout des panneaux a la fenetre
|
|
this.getContentPane().setLayout(new BorderLayout());
|
|
this.add(Panneau_Centre, BorderLayout.CENTER);
|
|
this.add(Panneau_Bas, BorderLayout.SOUTH);
|
|
this.add(MenuPrincipal, BorderLayout.NORTH);
|
|
|
|
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
|
|
this.setSize(700,300);
|
|
this.setLocation(200,200);
|
|
this.setResizable(false);
|
|
this.setTitle("SQLNavigator v0.1");
|
|
|
|
|
|
// ***************************************************** //
|
|
// Creation des fenetres secondaires //
|
|
// ***************************************************** //
|
|
conn = new IHMConnexion(this, "grive", "1521", "v920", "dut", "dut");
|
|
conn.setLocation(400,350);
|
|
|
|
// ***************************************************** //
|
|
|
|
// menu Jeu - bouton Nouveau
|
|
MenuBdd_Connexion.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent ev){
|
|
menuBddConnexion();
|
|
}
|
|
});
|
|
|
|
// menu Jeu - bouton Quitter
|
|
MenuBdd_Quitter.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent ev){
|
|
menuBddQuitter();
|
|
}
|
|
});
|
|
|
|
// menu Apropos - bouton
|
|
MenuAide_Apropos.addActionListener(new ActionListener(){
|
|
public void actionPerformed(ActionEvent ev){
|
|
menuApropos();
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
private void menuBddConnexion(){
|
|
// Affichage de la fenetre de connexion
|
|
conn.setVisible(true);
|
|
|
|
// Mise en place d'une ecoute sur la fenetre
|
|
conn.addWindowListener(new WindowListener(){
|
|
public void windowActivated(WindowEvent ev){
|
|
|
|
}
|
|
public void windowClosed(WindowEvent ev){
|
|
|
|
}
|
|
public void windowClosing(WindowEvent ev){
|
|
conn.dispose();
|
|
|
|
}
|
|
public void windowDeactivated(WindowEvent ev){
|
|
|
|
}
|
|
public void windowDeiconified(WindowEvent ev){
|
|
|
|
}
|
|
public void windowIconified(WindowEvent ev){
|
|
|
|
}
|
|
public void windowOpened(WindowEvent ev){
|
|
|
|
}
|
|
});
|
|
}
|
|
|
|
public void confirmationConnexion(Connexion objetConnexion){
|
|
String[] resultatConnexion;
|
|
|
|
this.objetConnexion = objetConnexion;
|
|
resultatConnexion = new String[2];
|
|
resultatConnexion = this.objetConnexion.connect();
|
|
|
|
this.zoneTexteStatut.setText(resultatConnexion[1]);
|
|
if(Integer.parseInt(resultatConnexion[0]) == 0){
|
|
this.MenuBdd_Connexion.setEnabled(false);
|
|
this.MenuBdd_Fermer.setEnabled(true);
|
|
this.connecte = true;
|
|
}
|
|
}
|
|
|
|
private void menuBddQuitter(){
|
|
String[] resultatFermeture;
|
|
|
|
// On verifie si une connexion a une BDD est en cours
|
|
// - Si oui, on ferme d'abord la connexion
|
|
if(this.connecte){
|
|
resultatFermeture = new String[2];
|
|
resultatFermeture = this.objetConnexion.disconnect();
|
|
|
|
if(Integer.parseInt(resultatFermeture[0]) == 0){
|
|
this.MenuBdd_Fermer.setEnabled(false);
|
|
this.MenuBdd_Connexion.setEnabled(true);
|
|
System.exit(0);
|
|
}
|
|
else{
|
|
this.zoneTexteStatut.setText("Impossible de fermer la base de donnees : " + resultatFermeture[1]);
|
|
}
|
|
}
|
|
// - Si non, alors on peut quitter de suite
|
|
else{
|
|
System.exit(0);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* <p>Action du bouton Apropos du menu Aide</p>
|
|
* @param args
|
|
*/
|
|
private void menuApropos(){
|
|
JOptionPane.showMessageDialog(null, "SQLNavigator\n\n" +
|
|
"Version 0.1\n" +
|
|
"Developpe par Olivier DOSSMANN\n\n",
|
|
"A propos de SQLNavigator",
|
|
JOptionPane.QUESTION_MESSAGE);
|
|
}
|
|
|
|
}
|