[java] probleme avec applet

Résolu/Fermé
domxaline - 6 nov. 2012 à 17:30
 domxaline - 7 nov. 2012 à 08:52
Bonjour,
quand j'ai compillé ce prg,ce dernier me donne erreur message veuillez m'aidez svp
<code>
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;
}
}
}

</code
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
A voir également:

5 réponses

domxaline Messages postés 188 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 7 mars 2018 10
Modifié par domxaline le 6/11/2012 à 21:26
j'ai corrigé mon prg ainsi
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;          
        }  
}  


et j'ai essayé le compiler dans l'invite de commande avec
javac Userin.java,
ce dernier me donnes ce message:
note:UserIn uses or overrides a deprecated API.
note:Recompile with -Xlint:deprecation for details.

et j'ai essayé compilé avec
javac -Xlint UserIn.java

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

quelqu'un peut m'aider svp
0
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
Modifié par KX le 6/11/2012 à 21:32
Ton message ce n'est qu'un avertissement, et tu peux en avoir le détail en suivant les instructions qui te sont afficher à savoir compiler comme ceci : javac -Xlint UserIn.java

Je te laisse regarder ce qui s'affiche, voici comment corriger ça : il faut ajouter un numéro de version pour la sérialisation : private static final long serialVersionUID = 1;

Remarque : si tu utilisais un IDE comme Eclipse ou NetBeans, ce genre de problème se corrigerait en un clic, il faudrait peut-être penser à te simplifier la vie...

Il y a un autre problème, c'est que action(Event, Object) est dépréciée et ne devrait donc plus être utilisée, il y a d'autres mécanismes (les ActionListener) qui ont été mis en place et qui sont plus performants, ils devraient donc être utilisés à la place.La confiance n'exclut pas le contrôle
0
domxaline Messages postés 188 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 7 mars 2018 10
6 nov. 2012 à 21:36
j'ai compilé comme vous dites,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
0
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
6 nov. 2012 à 21:38
Oui, c'est le deuxième problème dont je parlais, mais le message est assez explicite !
0
domxaline Messages postés 188 Date d'inscription lundi 16 mai 2005 Statut Membre Dernière intervention 7 mars 2018 10
Modifié par domxaline le 6/11/2012 à 21:42
j'ai inséré
private static final long serialVersionUID = 1;
à la fin de prg
rien ne changé
0
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
6 nov. 2012 à 21:53
Le serialVersionUID c'est pour corriger le premier avertissement :

warning: [serial] serializable class UserIn has no definition of serialVersionUID
public class UserIn extends Applet

Mais le deuxième avertissement concerne un tout autre problème, qu'il faut aussi corriger :

warning: [deprecation] action(Event,Object) in Component has been deprecated
public boolean action (Event evt, Object arg)

Mais j'insiste sur le fait que ce ne sont que des avertissements, ton programme fonctionnera sans problème dans la plupart des cas.
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
merci beaucoup ça marche
0