Bukisoh

TP1

Nov 10th, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.70 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import java.awt.FlowLayout;
  8. import javax.swing.border.TitledBorder;
  9. import javax.swing.UIManager;
  10. import java.awt.Color;
  11. import javax.swing.JButton;
  12. import javax.swing.JTextField;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ActionEvent;
  15. import javax.swing.JTextPane;
  16. import javax.swing.JLabel;
  17.  
  18. public class CalculatriceSwing extends JFrame implements ActionListener {
  19.  
  20.     private JPanel panneau_general;
  21.     private JTextField Add_champ1;
  22.     private JTextField Add_champ2;
  23.     private JLabel Resultat;
  24.     private JButton Substract;
  25.     private Object Add;
  26.     private JButton Substract_1;
  27.     private JButton Add_1;
  28.     private JButton EurToBTC;
  29.     private JButton BTCToEur;
  30.     private JTextField Devise;
  31.     private JLabel RsltConvers;
  32.  
  33.     /**
  34.      * Launch the application.
  35.      */
  36.    
  37.     public static void main(String[] args) {
  38.         EventQueue.invokeLater(new Runnable() {
  39.             public void run() {
  40.                 try {
  41.                     CalculatriceSwing frame = new CalculatriceSwing();
  42.                     frame.setVisible(true);
  43.                 } catch (Exception e) {
  44.                     e.printStackTrace();
  45.                 }
  46.             }
  47.         });
  48.     }
  49.  
  50.     /**
  51.      * Create the frame.
  52.      */
  53.     public CalculatriceSwing() {
  54.         super("KYS");
  55.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  56.         setBounds(100, 100, 470, 296);
  57.         panneau_general = new JPanel();
  58.         panneau_general.setBackground(new Color(102, 102, 102));
  59.         panneau_general.setForeground(new Color(255, 255, 0));
  60.         panneau_general.setBorder(new EmptyBorder(5, 5, 5, 5));
  61.         setContentPane(panneau_general);
  62.         panneau_general.setLayout(null);
  63.        
  64.         JPanel panneau1 = new JPanel();
  65.         panneau1.setBackground(new Color(51, 51, 51));
  66.         panneau1.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Calculer", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
  67.         panneau1.setBounds(10, 11, 437, 97);
  68.         panneau_general.add(panneau1);
  69.         panneau1.setLayout(null);
  70.        
  71.         Add_1 = new JButton("Add");
  72.         Add_1.addActionListener(new ActionListener() {
  73.             public void actionPerformed(ActionEvent e) {
  74.                 OnAdd();
  75.             }
  76.         });
  77.    
  78.         Add_1.setBackground(Color.LIGHT_GRAY);
  79.         Add_1.setBounds(218, 24, 89, 23);
  80.         panneau1.add(Add_1);
  81.        
  82.        
  83.        
  84.         Substract_1 = new JButton("Substract");
  85.         Substract_1.addActionListener(new ActionListener() {
  86.             public void actionPerformed(ActionEvent e) {
  87.                 OnSubstract();
  88.             }
  89.  
  90.         });
  91.        
  92.         Substract_1.setBackground(Color.LIGHT_GRAY);
  93.         Substract_1.setBounds(218, 58, 89, 23);
  94.         panneau1.add(Substract_1);
  95.        
  96.         Add_champ1 = new JTextField();
  97.         Add_champ1.setBackground(new Color(204, 204, 204));
  98.         Add_champ1.setBounds(10, 39, 86, 20);
  99.         panneau1.add(Add_champ1);
  100.         Add_champ1.setColumns(10);
  101.        
  102.         Add_champ2 = new JTextField();
  103.         Add_champ2.setBackground(new Color(204, 204, 204));
  104.         Add_champ2.setBounds(102, 39, 86, 20);
  105.         panneau1.add(Add_champ2);
  106.         Add_champ2.setColumns(10);
  107.        
  108.         Resultat = new JLabel("");
  109.         Resultat.setForeground(Color.RED);
  110.         Resultat.setBackground(Color.GRAY);
  111.         Resultat.setBounds(331, 39, 63, 20);
  112.         panneau1.add(Resultat);
  113.        
  114.         JPanel panneau2 = new JPanel();
  115.         panneau2.setBackground(new Color(51, 51, 51));
  116.         panneau2.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Convertisseur", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
  117.         panneau2.setBounds(10, 119, 437, 127);
  118.         panneau_general.add(panneau2);
  119.         panneau2.setLayout(null);
  120.        
  121.         Devise = new JTextField();
  122.         Devise.setText("Devise");
  123.         Devise.setBounds(38, 51, 86, 20);
  124.         panneau2.add(Devise);
  125.         Devise.setColumns(10);
  126.        
  127.         BTCToEur = new JButton("BTC>Eur");
  128.         BTCToEur.addActionListener(new ActionListener() {
  129.             public void actionPerformed(ActionEvent e) {
  130.                 OnBTCToEur();
  131.             }
  132.         });
  133.         BTCToEur.setBounds(169, 50, 89, 23);
  134.         panneau2.add(BTCToEur);
  135.        
  136.         EurToBTC = new JButton("Eur>BTC");
  137.         EurToBTC.addActionListener(new ActionListener() {
  138.             public void actionPerformed(ActionEvent e) {
  139.                 OnEurToBTC();
  140.             }
  141.         });
  142.         EurToBTC.setBounds(169, 16, 89, 23);
  143.         panneau2.add(EurToBTC);
  144.        
  145.         RsltConvers = new JLabel("");
  146.         RsltConvers.setForeground(Color.WHITE);
  147.         RsltConvers.setBackground(Color.WHITE);
  148.         RsltConvers.setBounds(301, 50, 86, 23);
  149.         panneau2.add(RsltConvers);
  150.        
  151.         JLabel lblTauxDeChange = new JLabel("TAUX DE CHANGE");
  152.         lblTauxDeChange.setForeground(Color.WHITE);
  153.         lblTauxDeChange.setBounds(169, 84, 120, 14);
  154.         panneau2.add(lblTauxDeChange);
  155.        
  156.         JLabel TxChange = new JLabel("1 eur = 0.000078 BTC");
  157.         TxChange.setForeground(Color.WHITE);
  158.         TxChange.setBounds(169, 102, 120, 14);
  159.         panneau2.add(TxChange);
  160.     }
  161.  
  162.    
  163.     public void OnEurToBTC(){
  164.        
  165.         String s1= Devise.getText();
  166.         double i = Double.parseDouble(s1)*0.000078;
  167.         RsltConvers.setText(i+"");
  168.     }
  169.    
  170.     public void OnBTCToEur(){
  171.         String s1= Devise.getText();
  172.         double i = Double.parseDouble(s1)/0.000078;
  173.         RsltConvers.setText(i+"");
  174.     }
  175.  
  176.     public void OnAdd() {
  177.        
  178.         String s1 = Add_champ1.getText();
  179.         String s2 = Add_champ2.getText();
  180.        
  181.         int i =Integer.parseInt(s1)+Integer.parseInt(s2);
  182.         if(i>=0)
  183.             Resultat.setForeground(Color.GREEN);
  184.        
  185.         if(i<0)
  186.             Resultat.setForeground(Color.RED);
  187.            
  188.        
  189.         try {
  190.         Resultat.setText(i+"");}
  191.         catch(NumberFormatException e){Resultat.setText("?");}
  192.        
  193.        
  194.     }
  195.  
  196.     public void OnSubstract(){
  197.         String s1 = Add_champ1.getText();
  198.         String s2 = Add_champ2.getText();
  199.        
  200.         int i =Integer.parseInt(s1)-Integer.parseInt(s2);
  201.        
  202.         if(i>=0)
  203.             Resultat.setForeground(Color.GREEN);
  204.        
  205.         if(i<0)
  206.             Resultat.setForeground(Color.RED);
  207.            
  208.        
  209.         try {
  210.         Resultat.setText(i+"");}
  211.         catch(NumberFormatException e){Resultat.setText("?");}
  212.        
  213.    
  214.         }
  215. }
  216.  
  217.  
  218.  
  219.  
Add Comment
Please, Sign In to add comment