Le code ci dessous est cens=E9 "=E9muler" un telephone portable avec une=20
image de fond, un clavier et un =E9cran.
L'applet doit s'initialiser dans une fenetre avec pour titre le Modele=20
de telephone et son numero
Le Num compos=E9 doit apparaitre dans sur l'afficheur. Et l'appui sur la=20
touche Appel doit faire le son de chaque chiffre puis sonner.
1) Quand j'execute mon code, j'ai 2 fenetres au lieu d'une
-> une qui contient l'image de fond
-> l'autre qui est la fenetre avec le titre et le telephone.
2) Je n'ai que le son du 1er digit puis la sonnerie. Comment faire pour=20
entendre chaque son et la sonnerie.
Je ne veux pas utiliser dans un premier temps SWING (je veux bien=20
comprendre les principes avec AWT) quelqu'un pourrait m'expliquer ?
/*
* Cr=E9=E9 le 2 juil. 2004
*
* Pour changer le mod=E8le de ce fichier g=E9n=E9r=E9, allez =E0 :
* Fen=EAtre>Pr=E9f=E9rences>Java>G=E9n=E9ration de code>Code e=
t=20
commentaires
*/
/**
* @author JLF928
*
* Pour changer le mod=E8le de ce commentaire de type g=E9n=E9r=E9, allez =
=E0 :
* Fen=EAtre>Pr=E9f=E9rences>Java>G=E9n=E9ration de code>Code e=
t=20
commentaires
*/
public class Phone1 extends Applet implements ActionListener, Runnable {
=09 Button=09touche1,=20
=09=09=09touche2,=20
=09=09=09touche3,
=09=09=09touche4,
=09=09=09touche5,
=09=09=09touche6,
=09=09=09touche7,
=09=09=09touche8,
=09=09=09touche9,
=09=09=09touche0,
=09=09=09dieze,
=09=09=09etoile,
=09=09=09appel,
=09=09=09annuler,
=09=09=09menu;
=09
=09AudioClip =09son1, son2, son3, son4, son5, son6,=20
=09=09=09=09son7, son8, son9, son0, sondieze, sonetoile,
=09=09=09=09sonne;
=09=09=09=09
=09Image image;=09
=09
=09TextField ecran;
=09
=09Frame modele;
=09Panel coque;
=09Panel clavier;
=09
=09Thread monThread;
=09
=09String numero;
=09
=09public void init(){
=09=09//Initialisation des variables
=09=09/*Cr=E9ation du t=E9l=E9phone*/
=09=09numero =3D "06.03.84.47.31";
=09=09modele =3D new Frame("Siemens C60 : " + numero);
=09=09// this.add(modele);
=09=09
=09=09/* Creation des Panel*/
=09=09coque =3D new Panel(new BorderLayout());
=09=09clavier =3D new Panel(new GridLayout(5,3));
=09=09
=09=09/* Creation des Boutons */
=09=09touche1 =3D new Button("1");=20
=09=09touche2 =3D new Button("2"); =20
=09=09touche3 =3D new Button("3");
=09=09touche4 =3D new Button("4");
=09=09touche5 =3D new Button("5");
=09=09touche6 =3D new Button("6");
=09=09touche7 =3D new Button("7");
=09=09touche8 =3D new Button("8");
=09=09touche9 =3D new Button("9");
=09=09touche0 =3D new Button("0");
=09=09dieze =3D new Button("#");
=09=09etoile =3D new Button("*");
=09=09appel =3D new Button("Appel");
=09=09annuler =3D new Button("annuler");
=09=09menu =3D new Button("Menu");
=09=09
=09=09/* Creation des bips */
=09=09son1 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.1.au");
=09=09son2 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.2.au");
=09=09son3 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.3.au");
=09=09son4 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.4.au");
=09=09son5 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.5.au");
=09=09son6 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.6.au");=20
=09=09son7 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.7.au");
=09=09son8 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.8.au");
=09=09son9 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.9.au");
=09=09son0 =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.0.au");
=09=09sondieze =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.pound.au");
=09=09sonetoile =3D getAudioClip(this.getDocumentBase(),=20
"touchtone.star.au");
=09=09sonne =3D getAudioClip(this.getDocumentBase(), "ring.au");
=09=09/* Creation de l'image de fond */=09=09
=09=09image =3D getImage(this.getDocumentBase(), "img05.gif");
=09=09
=09=09/* Creation de l'ecran */
=09=09 ecran =3D new TextField();
=09=09 ecran.setEditable(false);=20
=09=09=20
=09=09//Ajout des listeners
=09=09touche1.addActionListener(this);=20
=09=09touche2.addActionListener(this); =20
=09=09touche3.addActionListener(this);
=09=09touche4.addActionListener(this);
=09=09touche5.addActionListener(this);
=09=09touche6.addActionListener(this);
=09=09touche7.addActionListener(this);
=09=09touche8.addActionListener(this);
=09=09touche9.addActionListener(this);
=09=09touche0.addActionListener(this);
=09=09dieze.addActionListener(this);
=09=09etoile.addActionListener(this);
=09=09appel.addActionListener(this);
=09=09annuler.addActionListener(this);
=09=09menu.addActionListener(this);
=09=09
=09=09//Creation de l'interface graphique
=09=09/* Creation du clavier*/
=09=09clavier.add(annuler);
=09=09clavier.add(menu);
=09=09clavier.add(appel);
=09=09clavier.add(touche1);
=09=09clavier.add(touche2);
=09=09clavier.add(touche3);
=09=09clavier.add(touche4);
=09=09clavier.add(touche5);
=09=09clavier.add(touche6);
=09=09clavier.add(touche7);
=09=09clavier.add(touche8);
=09=09clavier.add(touche9);
=09=09clavier.add(etoile);
=09=09clavier.add(touche0);
=09=09clavier.add(dieze);
=09=09/*Ecran au dessus*/
=09=09coque.add(ecran,BorderLayout.NORTH);
=09=09coque.add(clavier, BorderLayout.SOUTH);