Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2834 connectés 

  FORUM HardWare.fr
  Programmation
  Java

  Problem application client/serveur avec interface graphique

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Problem application client/serveur avec interface graphique

n°2074861
motamo
Posté le 09-05-2011 à 21:21:07  profilanswer
 

salut,  
Il s'agit d’écrire une application Client/Serveur en mode TCP/IP ou :  
1) L'application client se présente sous forme d’une interface graphique comme il est indiqué au dessus :  
Quand l'utilisateur saisit un nom de fichier (texte) et appuie sur le boutton « charger » le contenu du fichier est lu et affiche dans la zone d'affichage libellée « contenu ».  
Quand l'utilisateur appuie sur le bouton « décoder » le contenu du fichier est envoyé au serveur nommé « décodeur » (qui attend au port 2007) pour décodage . ce meme fichier est reçu (décoder) et affiché par la suite dans la zone d’affichage libellée « résultat ».  
2) Dans l'application serveur, ce dernier reste en attente d'une connexion client sur le port 2007. Il traite les clients séquentiellement de la manière suivante :  
Il effectue le décodage au fur et à mesure de ces lignes et les renvoie au client en cours de traitement.  
Le décodage se fait comme suit :  
Alphabet codé : NOPQRSTUVWXYZABCDEFGHIJKLM  
Alphabet original :ABCDEFGHIJKLMNOPQRSTUVWXYZ  
========================================================================================  
Mon probleme est comment affiché la reponse du serveur dans une TextArea de coté client.  
mon code est comme suite:  
==================================classe client==================================  
import java.awt.*;  
import java.awt.event.*;  
import java.io.*;  
import java.util.*;  
import java.net.*;  
public class Client extends Frame {  
Client(){  
setTitle("service du décodage" );  
Panel p1=new Panel();  
Panel p2=new Panel();  
Panel p3=new Panel();  
Label l=new Label("Nom de fichier" );  
TextField tfn=new TextField(10);  
TextArea ta1=new TextArea(10,30);  
TextArea ta2=new TextArea(10,30);  
Button bc=new Button("charger" );  
Button bd=new Button("décoder" );  
p1.add(l);  
p1.add(tfn);  
p2.add(bc);  
p2.add(bd);  
p3.add(ta1);  
p3.add(ta2);  
add(p1,"North" );  
add(p3,"South" );  
add(p2,"Center" );  
pack();  
setVisible(true);  
bc.addActionListener(new Ecouteur500(tfn,ta1));  
bd.addActionListener(new Ecouteur501(ta1,ta2));  
this.addWindowListener(new Ecouteur502());  
}  
public static void main(String[]args){  
Client c=new Client();  
}  
}  
============================= classe ecouteur500==================================  
import java.awt.*;  
import java.awt.event.*;  
import java.io.*;  
public class Ecouteur500 implements ActionListener {  
TextField tfn;  
TextArea ta1;  
Ecouteur500(TextField tfn,TextArea ta1){  
this.tfn=tfn;  
this.ta1=ta1;  
}  
public void actionPerformed(ActionEvent e){  
Button b=(Button)e.getSource();  
if(b.getLabel().equals("charger" )){  
try {  
BufferedReader fin=new BufferedReader(new FileReader(tfn.getText()));  
String line;  
ta1.setText(null);  
while((line=fin.readLine())!=null){  
ta1.append(line+"\n" );  
}  
fin.close();  
}catch(IOException e1){  
System.out.println("errure E/S" );  
}  
}  
}  
}  
============================ classe ecouteur501=====================================  
import java.awt.*;  
import java.awt.event.*;  
import java.io.*;  
import java.net.*;  
import java.util.*;  
public class Ecouteur501 implements ActionListener {  
TextArea ta1;  
TextArea ta2;  
Ecouteur501(TextArea ta1,TextArea ta2){  
this.ta1=ta1;  
this.ta2=ta2;  
}  
public void actionPerformed(ActionEvent e){  
Button b=(Button)e.getSource();  
if(b.getLabel().equals("décoder" )){  
try{  
//String texte=ta1.getText();  
//StringTokenizer st=new StringTokenizer(texte,"\n" );  
Socket sc=new Socket(InetAddress.getLocalHost(),8000);  
BufferedReader infromser=new BufferedReader(new InputStreamReader(sc.getInputStream()));  
PrintWriter outtoser=new PrintWriter(new OutputStreamWriter(sc.getOutputStream()));  
FileInputStream mess = new FileInputStream("E:\\source.txt" ) ;  
String ligne="";  
String ligne2="";  
/*while((st.hasMoreTokens())){  
sout.println(st.nextToken());  
}  
sout.flush();  
sout.println("#*#" );  
sout.flush();  
sc.close();  
String line;  
ta2.setText(null);  
while(true){  
line=sin.readLine();  
if(line.trim().equals("#*#" )){  
sout.println("#*#" );  
sout.flush();  
sc.close();  
System.exit(0);  
}**/  
int taille=mess.available();  
outtoser.write(taille);  
for(int i=0;i<taille;i++){  
int b10=mess.read();  
outtoser.write(b10);  
}  
ta2.append(ligne2+"\n" );  
}catch(IOException e2){  
System.out.println("erreur E/S" );  
}  
}  
}  
}  
=================================== classe ecouteur502================================  
import java.awt.event.WindowAdapter;  
import java.awt.event.WindowEvent;  
class Ecouteur502 extends WindowAdapter{  
public void windowClosing(WindowEvent e){  
System.exit(-1);  
}  
}  
======================================== classe serveur=============================  
import java.awt.*;  
import java.awt.event.*;  
import java.io.*;  
import java.util.*;  
import java.net.*;  
public class Serveur {  
Serveur(){  
char[]t1={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};  
char[]t2={'N','O','P','Q','R','S','T','U','V','W','X','Z','A','B','C','D','E','F','G','H','I','J','K','L','M'};  
try{  
ServerSocket ss=new ServerSocket(8000);  
Socket sc=ss.accept();  
BufferedReader br=new BufferedReader(new InputStreamReader(sc.getInputStream()));  
PrintWriter pw= new PrintWriter(new OutputStreamWriter(sc.getOutputStream()));  
String line="";  
String nline="";  
while(!(line=br.readLine()).equals("#*#" )){  
for(int i=0;i<line.length();i++){  
int j;  
for(j=0;(j<26);j++){  
if(line.charAt(i)==t2[j]){  
nline=nline+t1[j];  
}else  
nline=nline+line.charAt(i);  
}  
}  
pw.println(nline);  
pw.flush();  
}  
}catch(IOException e3){  
System.out.println("erreur" );  
}  
}  
public static void main(String[]args){  
Serveur s=new Serveur();  
}  
}  
====================================================================================  
merci de votre aide

mood
Publicité
Posté le 09-05-2011 à 21:21:07  profilanswer
 


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Java

  Problem application client/serveur avec interface graphique

 

Sujets relatifs
Appeler un php sur un autre serveur (cron)Bug graphique
Problem de Filtre en SQLVBA Excel - graphique données sources = tableau
[VBA AutoCAD] Problème inter-applicationun petite problem avec les processeur
Interface graphique d'un agent de dialogue... Côté client 
Plus de sujets relatifs à : Problem application client/serveur avec interface graphique


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR