Anda di halaman 1dari 3

import java.awt.

*;
import java.awt.event.*;
public class Conversion extends Frame
{
Conversion (String s)
{
super(s);
Panel p1= new Panel();
Panel p2= new Panel();

Dialog bd= new Dialog(this);

Choice c1= new Choice();


Choice c2= new Choice();

c1.add("Dinar TU");
c1.add("Dollar AM");
c1.add("Euro EU");
c2.add("Dinar TU");
c2.add("Dollar AM");
c2.add("Euro EU");

TextField t1 =new TextField (10);


TextField t2=new TextField (10);

Label l= new Label("=");

p1.add(t1);
p1.add(c1);
p1.add(l);
p1.add(t2);
p1.add(c2);

Button conv = new Button ("convertir");


conv.setBackground(new Color(132,118,182));
conv.setForeground(Color.white);

p2.add(conv);

conv.addActionListener(new Ecouteur(t1,t2,c1,c2,bd));

setLayout (new GridLayout(2,1));


add(p1);
add(p2);

setBackground(Color.lightGray);
pack();
setVisible(true);

addWindowListener(new Fermer());

public static void main (String []args)


{
Conversion c =new Conversion("Convertisseur de monnais");
}
}

class Ecouteur implements ActionListener


{
Choice c1,c2;
TextField t1,t2;
Dialog bd;
Ecouteur(TextField t1,TextField t2,Choice c1, Choice c2, Dialog bd)
{
this.t1=t1;
this.t2=t2;
this.c1=c1;
this.c2=c2;
this.bd=bd;
}
public void actionPerformed(ActionEvent e)
{
if(c1.getSelectedItem().equals(c2.getSelectedItem()))
{
bd.setVisible(true);
bd.setTitle("Attention");

bd.addWindowListener(new DialogEcouteur(bd));
bd.add(new Label("Les monnaies convertir sont identiques"));
bd.pack();
}
else if(t1.getText().equals(""))
{
bd.setVisible(true);
bd.setTitle("Attention");
bd.addWindowListener(new DialogEcouteur(bd));
bd.add(new Label("Champ de la monnaies convertir est vide"));
bd.pack();
}
else
{
String montant;
String s1,s2;
s1=c1.getSelectedItem();
s2=c2.getSelectedItem();
double n,res;
if(s1.equals("Dinar TU")&&s2.equals(("Dollar AM")))
{
montant=t1.getText();
n=(new Double (montant)).doubleValue();
res=n*(1/1.4);
t2.setText(new Double(res).toString());
}

if(s1.equals("Dinar TU")&&s2.equals(("Euro EU")))


{
montant=t1.getText();
n=(new Double (montant)).doubleValue();
res=n*(1/1.7);
t2.setText(new Double(res).toString());
}
if(s1.equals("Dollar AM")&&s2.equals(("Dianr TU")))
{
montant=t1.getText();
n=(new Double (montant)).doubleValue();
res=n*1.4;
t2.setText(new Double(res).toString());
}

if(s1.equals("Dollar AM")&&s2.equals(("Euro EU")))


{
montant=t1.getText();
n=(new Double (montant)).doubleValue();
res=n*(1.4/1.7);
t2.setText(new Double(res).toString());
}

if(s1.equals("Euro EU")&&s2.equals(("Dinar TU")))


{
montant=t1.getText();
n=(new Double (montant)).doubleValue();
res=n*1.7;
t2.setText(new Double(res).toString());
}

if(s1.equals("Euro EU")&&s2.equals(("Dollar AM")))


{
montant=t1.getText();
n=(new Double (montant)).doubleValue();
res=n*(1.7/1.4);
t2.setText(new Double(res).toString());
}
}
}
}

class Fermer extends WindowAdapter


{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}

class DialogEcouteur extends WindowAdapter


{
Dialog d;
DialogEcouteur (Dialog d)
{
this.d=d;
}
public void windowClosing (WindowEvent e)
{
d.dispose();
}
}

Anda mungkin juga menyukai