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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
| import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class fenetre extends JFrame {
JButton Calculer,AfficherGraph,Quitter;
JLabel label1,label2,label3;
JTextField recupa,recupb,recupc;
JTextArea text1;
JPanel panneau1,panneau2;
//gestion des evenement pour les elements de controle
class ecouteur implements ActionListener {
public void actionPerformed(ActionEvent e) {
String boutton;
boutton= e.getActionCommand();
if(boutton.equals("Calculer"))
{
initialisePoly();
}
if(boutton.equals("Quitter"))
{
System.exit(0);
}
if(boutton.equals("AfficherGraph"))
{
}
}
}
//constructeur
fenetre(String titre) {
super(titre);
//creation des elements de l interface
Calculer =new JButton("Calculer");
AfficherGraph =new JButton("AfficherGraph");
Quitter=new JButton("Quitter");
label1=new JLabel("Enter les valeur pour a,b et c");
label2=new JLabel("X² + ");
label3=new JLabel("X + ");
recupa=new JTextField(4);
recupb=new JTextField(4);
recupc=new JTextField(4);
text1=new JTextArea(4,40);
panneau1 =new JPanel(); //va recevoir text1
panneau1.setLayout(new FlowLayout());
panneau1.setBackground(Color.yellow);
panneau1.add(text1);
panneau2 = new JPanel();//va afficher le Graph
panneau2.setLayout(new FlowLayout());
panneau2.setBackground(Color.green);
panneau2.setSize(100,100);
//gestionnaire de positionnement des element de l interface
setLayout(new FlowLayout());
//integration des elements.
add(label1);
add(recupa);
add(label2);
add(recupb);
add(label3);
add(recupc);
add(panneau1);
add(panneau2);
add(Calculer);
add(AfficherGraph);
add(Quitter);
//fermeture de l application a la fermeture de la fenetre
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
//Enregistrement des boutons
Calculer.addActionListener(new ecouteur());
AfficherGraph.addActionListener(new ecouteur());
Quitter.addActionListener(new ecouteur());
}
//methode pour initialiser le polynome
void initialisePoly()
{
double a,b,c;
a=Double.parseDouble(recupa.getText());
b=Double.parseDouble(recupb.getText());
c=Double.parseDouble(recupc.getText());
polynome poly =new polynome(a,b,c);
if (poly.calculDelta() >=0)
{
System.out.println("delta= "+poly.calculDelta());
System.out.println("s1= "+poly.calculS1());
System.out.println("s2= "+poly.calculS2());
String Afficher1,Afficher2,Afficher3; //variable qui recoivent une chaine de caractere pour envoyer dans text1 (JTexteArea)
Afficher1=("delta=" +poly.calculDelta()+"\n");
Afficher2=("Solution1= " +poly.calculS1() +"\n");
Afficher3=("Solution2= " +poly.calculS2() +"\n");
text1.setText(Afficher1+Afficher2+Afficher3);
}
else
{
System.out.println("delta= "+poly.calculDelta());
System.out.println("s1= "+poly.calculScomp1());
System.out.println("s2= "+poly.calculScomp2());
String Afficher1,Afficher2,Afficher3; //variable qui recoivent une chaine de caractere pour envoyer dans text1 (JTexteArea)
Afficher1=("delta=" +poly.calculDelta()+"\n");
Afficher2=("Solution1= " +poly.calculScomp1() +"\n");
Afficher3=("Solution2= " +poly.calculScomp2() +"\n");
text1.setText(Afficher1+Afficher2+Afficher3);
}
}
} |
Partager