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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
package Interface;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Equation {
private JFrame frame;
private JTextField textFieldA;
private JTextField textFieldB;
private JTextField textFieldC;
private JTextField textFieldDelta;
private JTextField textFieldX1;
private JTextField textFieldX2;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Equation window = new Equation();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public Equation() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 850, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.getContentPane().add(panel, BorderLayout.CENTER);
panel.setLayout(null);
JLabel lblNewLabelA = new JLabel("Entrer la valeur de A :");
lblNewLabelA.setBounds(24, 91, 134, 16);
panel.add(lblNewLabelA);
JLabel lblNewLabelB = new JLabel("Entrer la valeur de B :");
lblNewLabelB.setBounds(24, 136, 134, 16);
panel.add(lblNewLabelB);
JLabel lblNewLabelC = new JLabel("Entrer la valeur de C :");
lblNewLabelC.setBounds(24, 183, 134, 16);
panel.add(lblNewLabelC);
JLabel lblNewLabelDelta = new JLabel("Delta =");
lblNewLabelDelta.setBounds(24, 229, 56, 16);
panel.add(lblNewLabelDelta);
JLabel lblNewLabelX1 = new JLabel("X1 =");
lblNewLabelX1.setBounds(24, 258, 56, 16);
panel.add(lblNewLabelX1);
JLabel lblNewLabelX2 = new JLabel("X2 =");
lblNewLabelX2.setBounds(24, 287, 56, 16);
panel.add(lblNewLabelX2);
textFieldA = new JTextField();
textFieldA.setBounds(170, 88, 116, 22);
panel.add(textFieldA);
textFieldA.setColumns(10);
textFieldB = new JTextField();
textFieldB.setBounds(170, 133, 116, 22);
panel.add(textFieldB);
textFieldB.setColumns(10);
textFieldC = new JTextField();
textFieldC.setBounds(170, 180, 116, 22);
panel.add(textFieldC);
textFieldC.setColumns(10);
textFieldDelta = new JTextField();
textFieldDelta.setBounds(105, 226, 116, 22);
panel.add(textFieldDelta);
textFieldDelta.setColumns(10);
textFieldX1 = new JTextField();
textFieldX1.setBounds(105, 255, 116, 22);
panel.add(textFieldX1);
textFieldX1.setColumns(10);
textFieldX2 = new JTextField();
textFieldX2.setBounds(105, 284, 116, 22);
panel.add(textFieldX2);
textFieldX2.setColumns(10);
JButton btnNewButton = new JButton("Calcul");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
double b=0;
double a=0;
double c=0;
double delta = b*b-4*a*c;
if (delta>0) {
double X1 = (-b-Math.sqrt(delta))/(2*a);
double X2 = (-b+Math.sqrt(delta))/(2*a);
Double d=toString(delta);
Double x=toString(X1);
Double y=toString(X2);
textFieldDelta.setText("" + d);
textFieldX1.setText(""+ x);
textFieldX2.setText(""+ y);
}
}
private Double toString(double delta) {
return delta;
}
});
btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 20));
btnNewButton.setBounds(280, 229, 155, 36);
panel.add(btnNewButton);
}
} |
Partager