IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

avec Java Discussion :

Cloud d'image java


Sujet :

avec Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 35
    Points : 11
    Points
    11
    Par défaut Cloud d'image java
    L’objectif de cette application est de partager des photographies (images au sens large) et de pouvoir
    les rechercher. Comme le nombre potentiel d’utilisateurs et le nombre de photographies peut ˆetre gigantesque on d´ecide d’utiliser les principe du Cloud Computing (http://fr.wikipedia.org/wiki/Cloud_
    computing).
    L’application comporte deux programmes :
    – un programme client utilise par les utilisateurs du systeme ;
    – un programme serveur deploye sur plusieurs machines. Les programmes serveurs collaborent pour stocker les fichiers images et effectuer les recherches.
    Application cliente :
    Un utilisateur client du systeme n’a pas de connaissance directe de la structure du nuage de machines
    servant a stocker les photographies (transparence a la localisation). Il dialogue avec un ou plusieurs serveurs
    de son entourage proche mais pas directement avec les autres serveurs du nuage.
    Chaque utilisateur poss`ede un login et mot de passe, il peut deposer des fichiers de photographies et leur
    associer une liste de mots cl´es afin de les retrouver (annotations). Il peut choisir de permettre la visualisation de
    ses photographies a tous (publiques) ou seulement a une liste d’utilisateurs. De meme, l’utilisateur proprietaire
    d’une photographie peut autoriser l’annotation pour tous, ou bien seulement une pour une liste d’utilisateurs.
    Tout utilisateur du systeme (authentifie ou non) peut rechercher des photographies en specifiant une liste
    de mots cles. Les photographies poss´edant ces mots cle seront affichees. En cliquant sur une photographie on
    doit pouvoir visualiser ses mots cl´es. En cliquant sur un mot cle, on doit pouvoir visualiser les photographies
    ayant ce mot cle (soit ajoute a la liste de ceux presents dans le critere de recherche, soit present seul).
    Il doit egalement etre possible de visualiser les mots cles sous forme de graphes. Les mots cl´es les plus utilis´es doivent apparaıtre plus gros et les n mots cles lies les plus frequemment avec ceux presentes apparaissent
    aussi avec une taille proportionnelle a leur nombre d’occurrences
    Application Serveur :
    On peut lancer plusieurs serveurs sur differentes machines. Lorsque les clients envoient une image a un
    serveur, celui-ci utilise le nom du fichier afin de generer une cl´e utilis´ee ensuite comme identifiant de l’image.
    Un serveur de stockage est determine, au moyen du calcul d’une fonction de hachage appliqu´ee sur le nom,
    l’image lui est ´eventuellement transmise. Chaque serveur possede un repertoire de stockage des images utilisant uns structure arborescente (sous repertoires bases sur la premiere lettre de l’identifiant). En effet, les
    repertoires ont une capacite limitee en fichiers il convient donc d’utiliser des sous repertoires pour repartir
    l’ensemble des fichiers. Le stockage des mots cles, des autorisations sur les images et leur localisation en fonction du nom sont realises en utilisant plusieurs DHT (Distributed Hash Table).

    Bonjour, j'aimerez de l'aide pour faire ce programme. Je ne voit pas comment faire.

    Voila ce que j'ai essayer de faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    public class Utilisateur {
    private String motdepasse;
    private String identifiant;
    public Utilisateur(String mdp,String id){
     motdepasse=mdp;
     identifiant=id;
     }
    public String getmdp(){return motdepasse;}
    public String getid(){return identifiant;}
     
    }
    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
    import java.io.*;
    import java.net.*;
    import java.util.Hashtable;
     
     
    public class ServeurTCP {
    Hashtable album=new Hashtable();
    String [] motclef=new String[50];int nbmotc;String lien=null;
    void ajouterphoto(photo ph, int motclef) {
     album.put(motclef,ph);
    }
     
    photo recherche(String mot){
     photo p=new photo("");int i;
        if(album.get(mot)!=null)
          p=(photo)album.get(mot);
        return p;
     }
     
        public static void main(String[] args) {
            ServerSocket server = null;
            Socket client;
            try {
                server = new ServerSocket(1020);
                // 1020 is an unused port number
            } catch (IOException ie) {
                System.out.println("Cannot open socket.");
                System.exit(1);
            }
            while (true) {
                try {
                    client = server.accept();
                    OutputStream clientOut = client.getOutputStream();
                    PrintWriter pw = new PrintWriter(clientOut, true);
                    InputStream clientIn = client.getInputStream();
                    BufferedReader br = new BufferedReader(new InputStreamReader(
                            clientIn));
                    pw.println("Reponse du serveur > " + br.readLine());
                } catch (IOException ie) {
                }
            }
        }
    }
    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
    import java.net.*;
    import java.io.*;
     
    import java.io.*;
    import java.net.*;
     
    public class ClientTCP{
        public static void main(String args[]) {
            try {
                //Socket client = new Socket("127.0.0.1",1234);
                // Création de la socket pour le serveur IP:port ici
                // IP est en local
                Socket client = new Socket(InetAddress.getLocalHost(),1020);
                // canal d'entrée socket Serveur --> Client
                InputStream clientIn = client.getInputStream();
                // Canal de sortie socket client --> serveur
                OutputStream clientOut = client.getOutputStream();
                // Un meilleur writer pw et reader br
                PrintWriter pw = new PrintWriter(clientOut, true);
                BufferedReader br = new BufferedReader(new InputStreamReader(
                        clientIn));
                // stdIn lecture du clavier
                BufferedReader stdIn = new BufferedReader(new InputStreamReader(
                        System.in));
                System.out.println("Ecrire l'adresse d'une image: ");
                // Lire une ligne depuis le clavier puis transmissiob vers le
                // serveur
                // au moyen du stream de sortie pw
                pw.println(stdIn.readLine());
                System.out.println("Serveur message: ");
                // Affichage de la réponse reçut au moyen du stream d'entré br
                System.out.println(br.readLine());
                pw.close();
                br.close();
                client.close();
            } catch (ConnectException ce) {
                System.out
                        .println("Connexion au serveur impossible.");
            } catch (IOException ie) {
                System.out.println("I/O Error.");
            }
        }
    }
    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
    public class photo {
    private int maxcom;
    private String []commentaire;
    private int nbcom;
    private String photo;
     public photo(String p){
      commentaire=new String[10];
      maxcom=10;
      photo=p;
     }
     
     public String getphoto(){
      return photo;
     }
     
     public void ajoutercommentaire(String s){
     if(nbcom+1<maxcom)
      {commentaire[nbcom]=s;
       nbcom++;
      }
     else
      System.out.println("Trop de Commentaires");
     }
     
     public String[] getcom(){
     return commentaire;
     }
    }
    merci d'avance

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Février 2010
    Messages
    765
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2010
    Messages : 765
    Points : 1 037
    Points
    1 037
    Par défaut
    Bonjour,

    Il n'y a pas grand chose dans tes méthodes. Sur ce forum personne ne te fera ton code. Dit plutôt sur quoi tu bloques, et quelles erreurs tu rencontres.

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 35
    Points : 11
    Points
    11
    Par défaut
    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
    import java.io.*;
    import java.net.*;
    import java.util.Hashtable;
     
     
    public class ServeurTCP {
    public static void main(String[] args) {
    Gestionphoto gs=new Gestionphoto();
    int nbmotc=1; String lien=null;
            ServerSocket server = null;
            Socket client;
            try {
                server = new ServerSocket(1020);
                // 1020 is an unused port number
            } catch (IOException ie) {
                System.out.println("Cannot open socket.");
                System.exit(1);
            }
            while (true) {
                try {
                    client = server.accept();
                    OutputStream clientOut = client.getOutputStream();
                    PrintWriter pw = new PrintWriter(clientOut, true);
                    InputStream clientIn = client.getInputStream();
                    BufferedReader br = new BufferedReader(new InputStreamReader(
                            clientIn));
                    photo p=new photo(br.readLine());
                    for(int i=0;i<nbmotc;i++)
                    {
                     gs.ajouterphoto(p,String.valueOf(nbmotc));
                    }
                    nbmotc++;
                    System.out.println(gs.recherche("1").getphoto());
                } catch (IOException ie) {
                }
            }
        }
    }
    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
    import java.net.*;
    import java.io.*;
     
    import java.io.*;
    import java.net.*;
     
    public class ClientTCP{
        public static void main(String args[]) {
            try {
                //Socket client = new Socket("127.0.0.1",1234);
                // Création de la socket pour le serveur IP:port ici
                // IP est en local
                Socket client = new Socket(InetAddress.getLocalHost(),1020);
                // canal d'entrée socket Serveur --> Client
                InputStream clientIn = client.getInputStream();
                // Canal de sortie socket client --> serveur
                OutputStream clientOut = client.getOutputStream();
                // Un meilleur writer pw et reader br
                PrintWriter pw = new PrintWriter(clientOut, true);
                BufferedReader br = new BufferedReader(new InputStreamReader(
                        clientIn));
                // stdIn lecture du clavier
                BufferedReader stdIn = new BufferedReader(new InputStreamReader(
                        System.in));
                System.out.println("Ecrire l'adresse d'une image: ");
                // Lire une ligne depuis le clavier puis transmissiob vers le
                // serveur
                // au moyen du stream de sortie pw
                pw.println(stdIn.readLine());
                System.out.println("Serveur message: ");
                // Affichage de la réponse reçut au moyen du stream d'entré br
                System.out.println(br.readLine());
                pw.close();
                br.close();
                client.close();
            } catch (ConnectException ce) {
                System.out
                        .println("Connexion au serveur impossible.");
            } catch (IOException ie) {
                System.out.println("I/O Error.");
            }
        }
    }
    Voila deja ce que j'ai fait, j'aimerez faire une communication entre un serveur et un client. Avec le client qui donne le nom de la photo, et le serveur qui stock la photo. Ensuite il faudrait que un autre client puisse faire une recherche et le serveur lui envoie la photo.

    Quels sont les correction a faire dans mes codes Client,Serveur?? Quand je lance les deux, il me dit de rentrer le nom de la photo, mais ensuite il atten la reponse du serveur qui ne renvoie rien

  4. #4
    Modérateur
    Avatar de Alkhan
    Homme Profil pro
    ingénieur full stack
    Inscrit en
    Octobre 2006
    Messages
    1 232
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : ingénieur full stack

    Informations forums :
    Inscription : Octobre 2006
    Messages : 1 232
    Points : 2 061
    Points
    2 061
    Par défaut
    bonjour,
    Citation Envoyé par gio89 Voir le message
    Quand je lance les deux, il me dit de rentrer le nom de la photo, mais ensuite il atten la reponse du serveur qui ne renvoie rien
    C'est normal ton serveur lit ce que le client lui envoi et ensuite se met en attente de la connexion d'un autre client !

    Si tu veux que le client reçoive quelque chose il faut lui envoyer !

    Il te manque quelques notions pour faire quelque chose de correcte.
    Commence par lire quelques docs :
    - pour la partie réseau
    - penser en java (d'autre chapitre pourrait être utile)

  5. #5
    Membre actif
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    182
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Avril 2009
    Messages : 182
    Points : 268
    Points
    268
    Par défaut
    c'est quand meme un projet ambitieux si tu es un debutant, je connais pas ton niveau mais faire un service cloud robuste pouvant servir beaucoup de client simultanement necessite une comprehension en profondeur des streams,threads,sockets et des differents pattern pour y arriver.

    Sans certaines notions comme le thread pooling et beaucoup d'autres c'est impossible de faire un serveur assez robuste pour supporter beaucoup de clients simultanement via les sockets.

    Sinon pour ton projet, peut etre que RMI pourrait faire l'affaire.

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    35
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 35
    Points : 11
    Points
    11
    Par défaut
    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
    public class Face extends javax.swing.JFrame {
    public Gestionphoto gp=new Gestionphoto();String[][] motclefphoto=new String[50][50];int nbphoto=0;String Image;
        public Face(){
            initComponents();
        }
     
        /** 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.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jPanel1 = new javax.swing.JPanel();
            dessin = new javax.swing.JPanel();
            jScrollPane1 = new javax.swing.JScrollPane();
            coms = new javax.swing.JTextArea();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            recherche = new javax.swing.JButton();
            barrerech = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            AjoutPhoto = new javax.swing.JMenuItem();
            jMenu2 = new javax.swing.JMenu();
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
     
            dessin.setLayout(new java.awt.GridLayout());
     
            coms.setColumns(20);
            coms.setRows(5);
            jScrollPane1.setViewportView(coms);
     
            jButton1.setText("Envoyer commentaire");
     
            jButton2.setText("Annuler");
     
            recherche.setText("Rechercher");
            recherche.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    rechercheActionPerformed(evt);
                }
            });
     
            barrerech.setText("                             ");
     
            jLabel1.setText("Donner un mot clef");
     
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGap(38, 38, 38)
                    .addComponent(jButton1)
                    .addGap(101, 101, 101)
                    .addComponent(jButton2)
                    .addContainerGap(281, Short.MAX_VALUE))
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(30, 30, 30)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 414, Short.MAX_VALUE)
                            .addGap(52, 52, 52))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(dessin, javax.swing.GroupLayout.PREFERRED_SIZE, 396, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(barrerech, 0, 0, Short.MAX_VALUE)
                            .addGap(18, 18, 18))
                        .addComponent(jLabel1)
                        .addComponent(recherche, javax.swing.GroupLayout.Alignment.LEADING))
                    .addGap(39, 39, 39))
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(18, 18, 18)
                            .addComponent(barrerech, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(recherche))
                        .addComponent(dessin, javax.swing.GroupLayout.PREFERRED_SIZE, 268, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jButton2))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            jMenu1.setText("Fichier");
     
            AjoutPhoto.setText("Ajouter une photo");
            AjoutPhoto.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    AjoutPhotoActionPerformed(evt);
                }
            });
            jMenu1.add(AjoutPhoto);
     
            jMenuBar1.add(jMenu1);
     
            jMenu2.setText("Edit");
            jMenuBar1.add(jMenu2);
     
            setJMenuBar(jMenuBar1);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
     
            pack();
        }// </editor-fold>
     
        private void AjoutPhotoActionPerformed(java.awt.event.ActionEvent evt) {                                           
        Ajouphoto ap=new Ajouphoto(this, true,gp);
        ap.setVisible(true);
        gp=ap.gs;
        motclefphoto[nbphoto]=ap.motclef;
        nbphoto++;
        System.out.println(gp.recherche("toto").getphoto());
        }                                          
     
        private void rechercheActionPerformed(java.awt.event.ActionEvent evt) {
        if(barrerech.getText().equals(""))
       {System.out.println("Pas de mot");}
       else
       { String motrech=barrerech.getText();
        if(gp.recherche(motrech).getphoto().equals(""))
        {
          System.out.println("mot clef inconnu");
        }
        else
        {
          Image = gp.recherche(motrech).getphoto();
          MonPanel pan=new MonPanel();
          dessin.add(pan);
          pan.setImage(1,Image);
          pan.repaint();
          pack();
          int j=0;String s=" ";
          for(int i=0;i<nbphoto;i++)
          {
            while (motclefphoto[i][j] != null)
           {s+=motclefphoto[i][j]+" ";
            coms.setText(s);
            j++;
           }
           j=0;
          }
        }
       }
        }
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Face().setVisible(true);
                }
            });
        }
     
        // Variables declaration - do not modify
        private javax.swing.JMenuItem AjoutPhoto;
        private javax.swing.JTextField barrerech;
        private javax.swing.JTextArea coms;
        private javax.swing.JPanel dessin;
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenuBar jMenuBar1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JButton recherche;
        // End of variables declaration
     
    }
    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
     
    package projet;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.SwingUtilities;
    import javax.swing.filechooser.*;
    /**
     *
     * @author User
     */
    public class Ajouphoto extends java.awt.Dialog {
    Gestionphoto gs;String []motclef=new String[50];int nbmotc;String lien=null;
        public Ajouphoto(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            initComponents();
        }
        public Ajouphoto(java.awt.Frame parent, boolean modal,Gestionphoto gs) {
            super(parent, modal);
            initComponents();
            this.gs=gs;
            texte.setEditable(false);
            mc.setEditable(false);
        }
     
        /** 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">                          
        private void initComponents() {
     
            jPanel1 = new javax.swing.JPanel();
            jPanel3 = new javax.swing.JPanel();
            texte = new javax.swing.JTextField();
            MotClef = new javax.swing.JButton();
            jScrollPane1 = new javax.swing.JScrollPane();
            mc = new javax.swing.JTextArea();
            ChoisirImage = new javax.swing.JButton();
            Valider = new javax.swing.JButton();
            dessin = new javax.swing.JPanel();
     
            addWindowListener(new java.awt.event.WindowAdapter() {
                public void windowClosing(java.awt.event.WindowEvent evt) {
                    closeDialog(evt);
                }
            });
            setLayout(new java.awt.GridLayout(1, 0));
     
            jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS));
     
            jPanel3.setLayout(new javax.swing.BoxLayout(jPanel3, javax.swing.BoxLayout.Y_AXIS));
     
            texte.setPreferredSize(new java.awt.Dimension(100, 20));
            jPanel3.add(texte);
     
            MotClef.setText("jButton1");
            MotClef.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    MotClefActionPerformed(evt);
                }
            });
            jPanel3.add(MotClef);
     
            mc.setColumns(20);
            mc.setRows(5);
            jScrollPane1.setViewportView(mc);
     
            jPanel3.add(jScrollPane1);
     
            ChoisirImage.setText("jButton1");
            ChoisirImage.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ChoisirImageActionPerformed(evt);
                }
            });
            jPanel3.add(ChoisirImage);
     
            Valider.setText("jButton1");
            Valider.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    ValiderActionPerformed(evt);
                }
            });
            jPanel3.add(Valider);
     
            jPanel1.add(jPanel3);
     
            add(jPanel1);
     
            dessin.setLayout(new java.awt.GridLayout(1, 1));
            add(dessin);
     
            pack();
        }// </editor-fold>                        
     
        /** Closes the dialog */
        private void closeDialog(java.awt.event.WindowEvent evt) {                             
            setVisible(false);
            dispose();
        }                            
     
        private void ChoisirImageActionPerformed(java.awt.event.ActionEvent evt) {                                             
     
    JFileChooser chooser = new JFileChooser();
    //filtrer les fichier a afficher
    int returnVal=chooser.showOpenDialog(this);
    if(returnVal==JFileChooser.APPROVE_OPTION)
    {
     lien=chooser.getSelectedFile().getPath();
    }
    // charger l'image:
    MonPanel pan=new MonPanel();
    dessin.add(pan);
    pan.setBackground(Color.RED);
    pan.setImage(1,lien);
    pan.repaint();
    pack();
    texte.setEditable(true);
        }                                            
     
        private void MotClefActionPerformed(java.awt.event.ActionEvent evt) {                                        
       if(texte.getText().equals(""))
       {System.out.println("Pas de mot");}
       else
       { String mocl=texte.getText();
         mc.setText(mc.getText()+" "+mocl);
         if(nbmotc<49)
         {
          motclef[nbmotc] = texte.getText();
          nbmotc++;
          System.out.println("mot de passe ajouté: "+motclef[nbmotc-1]);
          texte.setText(null);
         }
         else
          System.out.println("Plus de place, trop de mots-clé");
       }
        }                                       
     
        private void ValiderActionPerformed(java.awt.event.ActionEvent evt) {                                        
         photo p=new photo(lien);
         for(int i=0;i<nbmotc;i++)
         {
          gs.ajouterphoto(p,motclef[i]);
         }
         setVisible(false);
         dispose();
        }                                       
     
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    Ajouphoto dialog = new Ajouphoto(new java.awt.Frame(), true);
                    dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                        public void windowClosing(java.awt.event.WindowEvent e) {
                            System.exit(0);
                        }
                    });
                    dialog.setVisible(true);
                }
            });
        }
     
     
        // Variables declaration - do not modify                     
        private javax.swing.JButton ChoisirImage;
        private javax.swing.JButton MotClef;
        private javax.swing.JButton Valider;
        private javax.swing.JPanel dessin;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel3;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextArea mc;
        private javax.swing.JTextField texte;
        // End of variables declaration                   
     
    }
    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
    package projet;
     
    public class photo {
    private int maxcom;
    private String []commentaire;
    private int nbcom;
    private String photo;
     public photo(String p){
      commentaire=new String[10];
      maxcom=10;
      photo=p;
     }
     
     public String getphoto(){
      return photo;
     }
     
     public void ajoutercommentaire(String s){
     if(nbcom+1<maxcom)
      {commentaire[nbcom]=s;
       nbcom++;
      }
     else
      System.out.println("Trop de Commentaires");
     }
     
     public String[] getcom(){
     return commentaire;
     }
    }
    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
    package projet;
    import java.util.Hashtable;
    public class Gestionphoto {
    Hashtable album;
    public Gestionphoto(){
    album=new Hashtable();
    }
    void ajouterphoto(photo ph,String motclef){
     album.put(motclef,ph);
    }
    void ajouterphoto(String ph,String motclef){
     album.put(ph,motclef);
    }
    photo recherche(String mot){
     photo p=new photo("");int i;
        if(album.get(mot)!=null)
          p=(photo)album.get(mot);
        return p;
     }
    String recherche2(String mot){
     String s=null;
        if(album.get(mot)!=null)
          s=(String)album.remove(mot);
        return s;
     }
     
    }
    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
    import java.io.*;
    import java.net.*;
    import java.util.Hashtable;
     
     
    public class ServeurTCP {
    public static void main(String[] args) {
    Gestionphoto gs=new Gestionphoto();
    int nbmotc=1; String lien=null;
            ServerSocket server = null;
            Socket client;
            try {
                server = new ServerSocket(1020);
                // 1020 is an unused port number
            } catch (IOException ie) {
                System.out.println("Cannot open socket.");
                System.exit(1);
            }
            while (true) {
                try {
                    client = server.accept();
                    OutputStream clientOut = client.getOutputStream();
                    PrintWriter pw = new PrintWriter(clientOut, true);
                    InputStream clientIn = client.getInputStream();
                    BufferedReader br = new BufferedReader(new InputStreamReader(
                            clientIn));
                    photo p=new photo(br.readLine());
                    for(int i=0;i<nbmotc;i++)
                    {
                     gs.ajouterphoto(p,String.valueOf(nbmotc));
                    }
                    nbmotc++;
                    System.out.println(gs.recherche("1").getphoto());
                } catch (IOException ie) {
                }
            }
        }
    }
    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
    import java.net.*;
    import java.io.*;
     
    import java.io.*;
    import java.net.*;
     
    public class ClientTCP{
        public static void main(String args[]) {
            try {
                //Socket client = new Socket("127.0.0.1",1234);
                // Création de la socket pour le serveur IP:port ici
                // IP est en local
                Socket client = new Socket(InetAddress.getLocalHost(),1020);
                // canal d'entrée socket Serveur --> Client
                InputStream clientIn = client.getInputStream();
                // Canal de sortie socket client --> serveur
                OutputStream clientOut = client.getOutputStream();
                // Un meilleur writer pw et reader br
                PrintWriter pw = new PrintWriter(clientOut, true);
                BufferedReader br = new BufferedReader(new InputStreamReader(
                        clientIn));
                // stdIn lecture du clavier
                BufferedReader stdIn = new BufferedReader(new InputStreamReader(
                        System.in));
                System.out.println("Ecrire l'adresse d'une image: ");
                // Lire une ligne depuis le clavier puis transmissiob vers le
                // serveur
                // au moyen du stream de sortie pw
                pw.println(stdIn.readLine());
                System.out.println("Serveur message: ");
                // Affichage de la réponse reçut au moyen du stream d'entré br
                System.out.println(br.readLine());
                pw.close();
                br.close();
                client.close();
            } catch (ConnectException ce) {
                System.out
                        .println("Connexion au serveur impossible.");
            } catch (IOException ie) {
                System.out.println("I/O Error.");
            }
        }
    }
    Voila ce que j'ai fais, mon probleme c'est que ici tout marche mais il faut que j'implante un serveur et un client. Comment Dois-je faire? Comment faire pour qu'il y ai un client et serveur en conservant l'interface graphique??

Discussions similaires

  1. [Image/Java] Haralick features deuxième version
    Par ToTo13 dans le forum Contribuez
    Réponses: 34
    Dernier message: 02/11/2010, 16h43
  2. afficher image java dans une applet
    Par xheo dans le forum Interfaces Graphiques en Java
    Réponses: 1
    Dernier message: 12/03/2009, 15h19
  3. [Image] java & Gimp
    Par slim_java dans le forum 2D
    Réponses: 4
    Dernier message: 30/12/2008, 13h09
  4. Empilage d'image : xhtmlrenderer ou image Java ?
    Par nicolr dans le forum Interfaces Graphiques en Java
    Réponses: 6
    Dernier message: 19/04/2008, 15h35
  5. Traitement d'image java OpenCV
    Par moris113 dans le forum Multimédia
    Réponses: 1
    Dernier message: 12/07/2006, 19h12

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo