Guest User

calcu

a guest
Dec 16th, 2015
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.97 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Color;
  3. import java.awt.Font;
  4. import java.awt.event.ActionEvent;
  5. import java.awt.event.ActionListener;
  6.  
  7. import javax.swing.JButton;
  8. import javax.swing.JFrame;
  9. import javax.swing.JLabel;
  10. import javax.swing.JPanel;
  11. import javax.swing.JTextField;
  12.  
  13.  
  14. public class moiCalcu1 extends JFrame implements ActionListener  {
  15.    
  16.   // private double mun1,mun2,mun3,mun4,s1,s2;
  17.  
  18.   private JPanel p1 ;
  19.    
  20.   private JTextField t1 , t2 ,t3,t4;
  21.   private JLabel l1, l2 ,l3;
  22.   private JLabel   l4,l5,l6 ;
  23.  
  24.   private JButton b1 , b2 ;
  25.    String ss1= "" ;
  26.    String ss2= "" ;
  27.    String ss3= "" ;
  28.    String ss4= "" ;
  29.    double num1=0;
  30.    double num2=0 ;
  31.    double num3=0;
  32.    double num4=0;
  33.    double s1  =0  ;
  34.    double s2  =0  ;
  35.  
  36.  
  37.    moiCalcu1 ( ){
  38.        
  39.     this.setTitle("Calcul 4 N");
  40.     this.setSize(500,350);
  41.     //this.setLocationRelativeTo(null);
  42.      
  43.    
  44.     p1.setLayout(new BorderLayout());
  45.     b1 = new JButton ("Calcu");
  46.     b2 = new JButton ("Clear");
  47.    
  48.     b2.addActionListener(this);
  49.     b1.addActionListener(this);
  50.    
  51.     t1 = new JTextField () ;
  52.     t1.setBackground(Color.ORANGE);
  53.     t1.setFont(new Font("Arial",2,20));
  54.     t1.setHorizontalAlignment(JTextField.CENTER);
  55.     l1 = new JLabel() ;
  56.     l1.setText("+");
  57.     t2 = new JTextField () ;
  58.     t2.setBackground(Color.ORANGE);
  59.     t2.setFont(new Font("Arial",2,20));
  60.     l2 = new JLabel() ;
  61.     l2.setText("=");
  62.     l3 = new JLabel() ;
  63.     l3.setText("");
  64.    
  65.     t3 = new JTextField () ;
  66.     t3.setBackground(Color.ORANGE);
  67.     t3.setFont(new Font("Arial",2,20));
  68.     l4 = new JLabel() ;
  69.     l4.setText("*");
  70.     t4 = new JTextField () ;
  71.     t4.setBackground(Color.ORANGE);
  72.     t4.setFont(new Font("Arial",2,20));
  73.     l5 = new JLabel() ;
  74.     l5.setText("=");
  75.     l6 = new JLabel() ;
  76.     l6.setText("");
  77.      
  78.     p1.add(t1,BorderLayout.WEST);
  79.     p1.add(l1,BorderLayout.WEST);
  80.     p1.add(t2,BorderLayout.WEST);
  81.     p1.add(l2,BorderLayout.WEST);
  82.     p1.add(l3,BorderLayout.WEST);
  83.    
  84.     p1.add(t3,BorderLayout.EAST);
  85.     p1.add(l4,BorderLayout.EAST);
  86.     p1.add(t4,BorderLayout.EAST);
  87.     p1.add(l5,BorderLayout.EAST);
  88.     p1.add(l6,BorderLayout.EAST);
  89.    
  90.     p1.add(b1, BorderLayout.CENTER);
  91.     p1.add(b2, BorderLayout.CENTER);
  92.     this.setContentPane(p1);
  93.     this.setVisible(true);
  94.     this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  95.    
  96.    }
  97.  
  98. //@Override
  99.  public void actionPerformed(ActionEvent e) {
  100.     // TODO Auto-generated method stub
  101.      if (e.getSource() == b1) {
  102.     ss1 = t1.getText() ;
  103.     ss2 = t2.getText() ;  
  104.     ss3 = t3.getText() ;
  105.     ss4 = t4.getText() ;
  106.       num1 = Double.parseDouble(ss1);  
  107.       num2 = Double.parseDouble(ss2);
  108.       num3 = Double.parseDouble(ss3);  
  109.       num4 = Double.parseDouble(ss4);
  110.       s1 = num1+num2 ;
  111.       s2 = num3*num4 ;
  112.      
  113.      l3.setText(Double.toString(s1));
  114.      l6.setText(Double.toString(s1));}
  115.      if (e.getSource() == b2 )
  116.      {
  117.          String c = "" ;
  118.          t1 = new JTextField () ;
  119.             t1.setText(c);
  120.          
  121.              
  122.             t2.setText(c);  
  123.             l3.setText(c);  
  124.             t3.setText(c);
  125.             t4.setText(c);  
  126.             l6.setText(c);  
  127.      }
  128. }
  129.    
  130.  
  131.    
  132.    
  133.    
  134. }
Add Comment
Please, Sign In to add comment