Advertisement
Guest User

Problam Error

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