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 :

Applet qui ne fonctionne pas


Sujet :

avec Java

  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut Applet qui ne fonctionne pas
    Bonjour,
    quand j'ai compilé ce prg,ce dernier me donne erreur message veuillez m'aidez svp
    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
     
    import java.awt.*;
    import java.applet.*;
    public class UserIn extends Applet
    {
    TextField text1, text2;
    public void init( )
    {
    text1=new TextField(8);
    text2=new TextField(8);
    add (text1);
    add (text2);
    text1.setText("0");
    text2.setText("0");
    }
    public void paint( Graphics g)
    {
    int x=0, y=0, z=0;
    String s1, s2, s;
    g.drawString ("Input a number in each box", 10, 50);
    try
    {
    s1=text1.getText();
    x=Integer.parseInt(s1);
    s2=text2.getText();
    y=Integer.parseInt(s2);
    }
    catch(Exception e )
    {
    z=x+y;
    s=String.valueOf(z);
    g.drawString( "THE SUM IS:", 10, 75);
    g.drawString(s, 100, 75);
    }
    public Boolean action(Event event, Object object)
    {
    repaint( );
    return true;
    }
    }
    }
    erreur message sont:
    Exception in thread "AWT-EventQueue-1" java.lang.Error: Unresolved compilation problems:
    Illegal modifier for parameter action; only final is permitted
    Syntax error on token "(", ; expected
    Syntax error on token ",", ; expected
    Syntax error on token ")", ; expected
    Void methods cannot return a value
    at UserIn.paint(UserIn.java:34)
    at sun.awt.RepaintArea.paintComponent(RepaintArea.java:264)
    at sun.awt.RepaintArea.paint(RepaintArea.java:240)
    at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:347)
    at java.awt.Component.dispatchEventImpl(Component.java:4937)
    at java.awt.Container.dispatchEventImpl(Container.java:2287)
    at java.awt.Component.dispatchEvent(Component.java:4687)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:703)
    at java.awt.EventQueue.access$000(EventQueue.java:102)
    at java.awt.EventQueue$3.run(EventQueue.java:662)
    at java.awt.EventQueue$3.run(EventQueue.java:660)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
    at java.awt.EventQueue$4.run(EventQueue.java:676)
    at java.awt.EventQueue$4.run(EventQueue.java:674)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

    merci d'avance

  2. #2
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Bonjour,

    Indente ton code et tu verras qu'il y a une accolade fermante "}" mal placé pour les méthodes paint() et action().

    A+.

  3. #3
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut
    j'ai corrigé mon prg ainsi
    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
     
    import java.awt.*;
    import java.applet.*;
    public class UserIn extends Applet
    {
    	    TextField text1, text2;
    	    public void init( )
    	    {
    	             text1=new TextField(8);
    	             text2=new TextField(8);
    	             add (text1);
    	             add (text2);
    	             text1.setText("0");
    	             text2.setText("0");
    	    }
    	    public void paint(Graphics g)
    	    {
    	      int x=0, y=0, z=0;
    	      String s1, s2, s;
    	      g.drawString ("Input a number in each box", 10, 50);
    	      try
    	         {
    	             s1=text1.getText();
    	             x=Integer.parseInt(s1);
    	             s2=text2.getText();
    	             y=Integer.parseInt(s2);
    	         }
    	       catch(Exception e )
    	        {
    	            z=x+y;
    	            s=String.valueOf(z);
    	            g.drawString( "THE SUM IS:", 10, 75); 
    	            g.drawString(s, 100, 75);     
    	        }}
    	       public boolean action (Event evt, Object arg)
    	       {
    	    	  repaint( );
    	          return true;        
    	       }
    }
    maintenant quand j'ai compile dans l'invite de commande
    javac UserIn.java
    ce dernier m'affiche le message suivant:
    note:UserIn uses or overrides a deprecated API.
    note:Recompile with -Xlint:deprecation for details.

    que veut dire par -Xlint

  4. #4
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    C'est expliqué sur la FAQ.

    A+.

  5. #5
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut
    et j'ai compilé avec
    javac -Xlint UserIn.java


    j'ai message suivante:
    UserIn.java:34: warning: [deprecation] action<Event,Object>in component has been deprecated
    public boolean action<Event evt,Object arg>
    1 warning

    le résultat de mon calcul (sum) s'affiche pas non plus
    où est ce que j'ai pu faire erreur?

    merci à votre aide

  6. #6
    Rédacteur/Modérateur
    Avatar de andry.aime
    Homme Profil pro
    Inscrit en
    Septembre 2007
    Messages
    8 391
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Ile Maurice

    Informations forums :
    Inscription : Septembre 2007
    Messages : 8 391
    Points : 15 059
    Points
    15 059
    Par défaut
    Le block catch est fait pour intercepter des erreurs, pas pour faire des calculs.

    A+.

  7. #7
    Membre habitué
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    684
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 684
    Points : 147
    Points
    147
    Par défaut
    merci beaucoup j'ai corrigé mon erreur
    merci encore

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Code qui ne fonctionne pas sur Mac
    Par malbaladejo dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 14/01/2005, 11h08
  2. [SQL] Requête à jointure qui ne fonctionne pas
    Par Bensor dans le forum Langage SQL
    Réponses: 2
    Dernier message: 09/12/2004, 16h10
  3. Jointure externe qui ne fonctionne pas
    Par Guizz dans le forum Langage SQL
    Réponses: 3
    Dernier message: 05/02/2004, 12h26
  4. CREATEFILEMAPPING qui ne fonctionne pas???
    Par Jasmine dans le forum MFC
    Réponses: 2
    Dernier message: 06/01/2004, 19h33
  5. UNION qui ne fonctionne pas
    Par r-zo dans le forum Langage SQL
    Réponses: 7
    Dernier message: 21/07/2003, 10h04

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