Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package operacionesad;
- import java.awt.*;
- import java.awt.event.*;
- public class Operacionesad
- {
- Label L1,L2,L3;
- Button B1,B2, B3, B4;
- TextField T1, T2, T3;
- Frame F1;
- public void c1 ()
- {
- L1= new Label ("Número 1");
- L2= new Label ("Número 2");
- L3= new Label ("Resultado");
- T1= new TextField (20);
- T2= new TextField (20);
- T3= new TextField (20);
- // Botón de sumar
- B1= new Button ("+");
- B1.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- suma ();
- }
- });
- //Botón de restar
- B2= new Button ("-");
- B2.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- resta ();
- }
- });
- //Botón de multiplicar
- B3= new Button ("*");
- B3.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- multi ();
- }
- });
- //Botón de dividir
- B4= new Button ("/");
- B4.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- div ();
- }
- });
- F1= new Frame ("Operaciones");
- //Display
- F1.add(L1);
- F1.add(T1);
- F1.add(L2);
- F1.add(T2);
- F1.add(B1);
- F1.add(B2);
- F1.add(B3);
- F1.add(B4);
- F1.add(T3);
- F1.show();
- F1.setLayout(new FlowLayout ());
- F1.setSize(260, 150);
- F1.setResizable(false);
- }
- public void suma ()
- {
- String TT1, TT2, TT3;
- double a, b, c;
- //
- a= Double.parseDouble(TT1= T1.getText());
- b= Double.parseDouble(TT2= T2.getText());
- c= a+b;
- TT3= Double.toString(c);
- T3.setText(TT3);
- }
- public void resta ()
- {
- String TT1, TT2, TT3;
- double a, b, c;
- //
- a= Double.parseDouble(TT1= T1.getText());
- b= Double.parseDouble(TT2= T2.getText());
- c= a-b;
- TT3= Double.toString(c);
- T3.setText(TT3);
- }
- public void multi ()
- {
- String TT1, TT2, TT3;
- double a, b, c;
- //
- a= Double.parseDouble(TT1= T1.getText());
- b= Double.parseDouble(TT2= T2.getText());
- c= a*b;
- TT3= Double.toString(c);
- T3.setText(TT3);
- }
- public void div ()
- {
- String TT1, TT2, TT3;
- double a, b, c;
- //
- a= Double.parseDouble(TT1= T1.getText());
- b= Double.parseDouble(TT2= T2.getText());
- c= a/b;
- TT3= Double.toString(c);
- T3.setText(TT3);
- }
- public static void main(String[] args)
- {
- Operacionesad n=new Operacionesad();
- n.c1();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement