Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.border.TitledBorder;
- import javax.swing.JTextPane;
- import java.awt.Color;
- import java.awt.SystemColor;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JTextField;
- import javax.swing.JRadioButton;
- import javax.swing.ButtonGroup;
- import javax.swing.JButton;
- import javax.swing.JLabel;
- import javax.swing.JList;
- import javax.swing.JScrollBar;
- import javax.swing.border.MatteBorder;
- import java.lang.Math;
- import javax.swing.JSlider;
- import javax.swing.JScrollPane;
- import javax.swing.DefaultListModel;
- public class TPLUCASPANSARDI extends JFrame implements ActionListener {
- private JPanel contentPane;
- private JTextField textFieldTaille;
- private JTextField textFieldPoids;
- private final ButtonGroup buttonGroup = new ButtonGroup();
- private JTextField textField_PdsIdéal;
- private JPanel panel_1;
- private JButton btnIMC;
- private JButton btnpoidsid;
- private JTextPane textPane;
- private JTextPane textRsltIMC;
- private JButton btnEffacer;
- private JRadioButton rdbtnHomme;
- private JRadioButton rdbtnFemme;
- DefaultListModel<String> dlm;
- private JScrollPane scrollPane;
- private JList<String> list;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- TPLUCASPANSARDI frame = new TPLUCASPANSARDI();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public TPLUCASPANSARDI() {
- setTitle("Masse Corporelle");
- setBackground(Color.WHITE);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 450, 416);
- contentPane = new JPanel();
- contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(contentPane);
- contentPane.setLayout(null);
- JPanel panel = new JPanel();
- panel.setBorder(new TitledBorder(null, "Mes Param\u00E8tres", TitledBorder.LEADING, TitledBorder.TOP, null, null));
- panel.setBounds(10, 11, 414, 85);
- contentPane.add(panel);
- panel.setLayout(null);
- JTextPane txtpnTaille = new JTextPane();
- txtpnTaille.setBackground(SystemColor.control);
- txtpnTaille.setText("Taille :");
- txtpnTaille.setBounds(10, 23, 38, 20);
- panel.add(txtpnTaille);
- JTextPane txtpnCm = new JTextPane();
- txtpnCm.setText("cm");
- txtpnCm.setBackground(SystemColor.control);
- txtpnCm.setBounds(141, 23, 26, 20);
- panel.add(txtpnCm);
- JTextPane txtpnPoids = new JTextPane();
- txtpnPoids.setText("poids");
- txtpnPoids.setBackground(SystemColor.control);
- txtpnPoids.setBounds(177, 23, 37, 20);
- panel.add(txtpnPoids);
- JTextPane txtpnKg = new JTextPane();
- txtpnKg.setBackground(SystemColor.control);
- txtpnKg.setText("Kg");
- txtpnKg.setBounds(320, 23, 26, 20);
- panel.add(txtpnKg);
- textFieldTaille = new JTextField();
- textFieldTaille.setText("170");
- textFieldTaille.setBounds(53, 23, 78, 20);
- panel.add(textFieldTaille);
- textFieldTaille.setColumns(10);
- textFieldPoids = new JTextField();
- textFieldPoids.setText("72");
- textFieldPoids.setBounds(224, 23, 86, 20);
- panel.add(textFieldPoids);
- textFieldPoids.setColumns(10);
- rdbtnHomme = new JRadioButton("Homme");
- buttonGroup.add(rdbtnHomme);
- rdbtnHomme.setBounds(47, 50, 86, 23);
- panel.add(rdbtnHomme);
- rdbtnFemme = new JRadioButton("Femme");
- buttonGroup.add(rdbtnFemme);
- rdbtnFemme.setBounds(165, 50, 109, 23);
- panel.add(rdbtnFemme);
- panel_1 = new JPanel();
- panel_1.setBorder(new TitledBorder(null, "Mes Calculs", TitledBorder.LEADING, TitledBorder.TOP, null, null));
- panel_1.setBounds(10, 104, 414, 143);
- contentPane.add(panel_1);
- panel_1.setLayout(null);
- btnIMC = new JButton("IMC");
- btnIMC.setBounds(10, 21, 89, 23);
- panel_1.add(btnIMC);
- btnIMC.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- OnIMC();
- }
- });
- JTextPane txtpnInterpretation = new JTextPane();
- txtpnInterpretation.setText("Interpretation");
- txtpnInterpretation.setBackground(SystemColor.control);
- txtpnInterpretation.setBounds(20, 55, 79, 23);
- panel_1.add(txtpnInterpretation);
- btnpoidsid = new JButton("poids id\u00E9al");
- btnpoidsid.setBounds(10, 89, 89, 23);
- panel_1.add(btnpoidsid);
- btnpoidsid.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- OnPoidsIdeal();
- }
- });
- textField_PdsIdéal = new JTextField();
- textField_PdsIdéal.setBounds(129, 90, 86, 20);
- panel_1.add(textField_PdsIdéal);
- textField_PdsIdéal.setColumns(10);
- JLabel lblNewLabel = new JLabel("Kg");
- lblNewLabel.setBounds(227, 93, 46, 14);
- panel_1.add(lblNewLabel);
- textRsltIMC = new JTextPane();
- textRsltIMC.setBorder(new MatteBorder(1, 1, 1, 1, (Color) new Color(0, 0, 0)));
- textRsltIMC.setBackground(Color.YELLOW);
- textRsltIMC.setBounds(129, 21, 98, 20);
- panel_1.add(textRsltIMC);
- textPane = new JTextPane();
- textPane.setBackground(Color.GREEN);
- textPane.setBounds(129, 55, 146, 20);
- panel_1.add(textPane);
- JPanel panel_2 = new JPanel();
- panel_2.setBorder(new TitledBorder(null, "M\u00E9morisation", TitledBorder.LEADING, TitledBorder.TOP, null, null));
- panel_2.setBounds(10, 258, 414, 108);
- contentPane.add(panel_2);
- panel_2.setLayout(null);
- dlm = new DefaultListModel<String>();
- list = new JList<String>(dlm);
- list.setBackground(Color.WHITE);
- scrollPane = new JScrollPane(list);
- scrollPane.setBounds(28, 30, 261, 67);
- panel_2.add(scrollPane);
- btnEffacer = new JButton("Effacer");
- btnEffacer.setBounds(304, 47, 89, 23);
- panel_2.add(btnEffacer);
- btnEffacer.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- OnEffacer();
- }
- });
- textField_PdsIdéal.setEditable(false);
- btnpoidsid.setEnabled(false);
- btnEffacer.setEnabled(false);
- rdbtnHomme.setSelected(true);
- }
- public void OnPoidsIdeal() {
- String s1=textFieldTaille.getText();
- double d1=Double.parseDouble(s1);
- if(rdbtnHomme.isSelected()) {
- textField_PdsIdéal.setText("" + Math.round(d1 - 100 - ((d1-150)/4)));
- }
- else {
- textField_PdsIdéal.setText("" + Math.round(d1 - 100 - ((d1-150)/2.5)));
- }
- }
- public void OnEffacer() {
- btnpoidsid.setEnabled(false);
- btnEffacer.setEnabled(false);
- textFieldTaille.setText("");
- textFieldPoids.setText("");
- textRsltIMC.setText("");
- textPane.setText("");
- textField_PdsIdéal.setText("");
- }
- public void OnIMC() {
- btnpoidsid.setEnabled(true);
- btnEffacer.setEnabled(true);
- String s1=textFieldTaille.getText();
- String s2=textFieldPoids.getText();
- try{
- double d1=Double.parseDouble(s1);
- d1=d1/100;
- double d2=Double.parseDouble(s2);
- double Result = d2 /( Math.pow(d1, 2));
- textRsltIMC.setText("" + Math.round(Result));
- if(Result<=18.5) {
- textPane.setText("Trop maigre");
- textPane.setBackground(Color.CYAN);
- dlm.addElement("Poids:"+d2+" taille:"+d1*100+" IMC:"+Math.round(Result)+" Trop maigre");
- }
- else if(Result<=25) {
- textPane.setText("Normal");
- textPane.setBackground(Color.GREEN);
- dlm.addElement("Poids:"+d2+" taille:"+d1*100+" IMC:"+Math.round(Result)+" Normal");
- }
- if(Result>25) {
- textPane.setText("Trop gros");
- textPane.setBackground(Color.RED);
- dlm.addElement("Poids:"+d2+" taille:"+d1*100+" IMC:"+Math.round(Result)+" Trop gros");
- }
- }
- catch(NumberFormatException numberformatexception) {
- textFieldTaille.setText("Erreur");
- textFieldPoids.setText("Erreur");
- textRsltIMC.setText("Erreur");
- textPane.setText("Erreur");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment