Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package calc ;
- /**
- *
- * @author me
- */
- import java.awt.BorderLayout;
- import java.awt.Color;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- public class Calcu1 extends JFrame implements ActionListener {
- // private double mun1,mun2,mun3,mun4,s1,s2;
- private JPanel p1 ;
- private JTextField t1 , t2 ,t3,t4;
- private JLabel l1, l2 ,l3;
- private JLabel l4,l5,l6 ;
- private JButton b1 , b2 ;
- String ss1= "" ;
- String ss2= "" ;
- String ss3= "" ;
- String ss4= "" ;
- double num1=0;
- double num2=0 ;
- double num3=0;
- double num4=0;
- double s1 =0 ;
- double s2 =0 ;
- Calcu1 ( ){
- this.setTitle("Calcul 4 N");
- this.setSize(500,350);
- p1.setLayout(new BorderLayout());
- b1 = new JButton ("Calcu");
- b2 = new JButton ("Clear");
- b2.addActionListener(this);
- b1.addActionListener(this);
- t1 = new JTextField () ;
- t1.setBackground(Color.ORANGE);
- t1.setFont(new Font("Arial",2,20));
- t1.setHorizontalAlignment(JTextField.CENTER);
- l1 = new JLabel() ;
- l1.setText("+");
- t2 = new JTextField () ;
- t2.setBackground(Color.ORANGE);
- t2.setFont(new Font("Arial",2,20));
- l2 = new JLabel() ;
- l2.setText("=");
- l3 = new JLabel() ;
- l3.setText("");
- t3 = new JTextField () ;
- t3.setBackground(Color.ORANGE);
- t3.setFont(new Font("Arial",2,20));
- l4 = new JLabel() ;
- l4.setText("*");
- t4 = new JTextField () ;
- t4.setBackground(Color.ORANGE);
- t4.setFont(new Font("Arial",2,20));
- l5 = new JLabel() ;
- l5.setText("=");
- l6 = new JLabel() ;
- l6.setText("");
- p1.add(t1,BorderLayout.WEST);
- p1.add(l1,BorderLayout.WEST);
- p1.add(t2,BorderLayout.WEST);
- p1.add(l2,BorderLayout.WEST);
- p1.add(l3,BorderLayout.WEST);
- p1.add(t3,BorderLayout.EAST);
- p1.add(l4,BorderLayout.EAST);
- p1.add(t4,BorderLayout.EAST);
- p1.add(l5,BorderLayout.EAST);
- p1.add(l6,BorderLayout.EAST);
- p1.add(b1, BorderLayout.CENTER);
- p1.add(b2, BorderLayout.CENTER);
- this.setContentPane(p1);
- this.setVisible(true);
- this.setDefaultCloseOperation(EXIT_ON_CLOSE);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- // TODO Auto-generated method stub
- if (e.getSource() == b1) {
- ss1 = t1.getText() ;
- ss2 = t2.getText() ;
- ss3 = t3.getText() ;
- ss4 = t4.getText() ;
- num1 = Double.parseDouble(ss1);
- num2 = Double.parseDouble(ss2);
- num3 = Double.parseDouble(ss3);
- num4 = Double.parseDouble(ss4);
- s1 = num1+num2 ;
- s2 = num3*num4 ;
- l3.setText(Double.toString(s1));
- l6.setText(Double.toString(s1));}
- if (e.getSource() == b2 )
- {
- String c = "" ;
- t1 = new JTextField () ;
- t1.setText(c);
- t2.setText(c);
- l3.setText(c);
- t3.setText(c);
- t4.setText(c);
- l6.setText(c);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement