Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.applet.*;
- import java.awt.event.*;
- public class Main extends Applet implements ActionListener {
- Label l1, l2,l3;
- TextField t1,t2,t3;
- Button b1,b2,b3,b4,b5,b6,b7,b8;
- public Main () {
- l1 = new Label("Numero 1");
- t1 = new TextField(8);
- l2 = new Label("Numero 2");
- t2 = new TextField(8);
- b1 = new Button("Suma");
- b2 = new Button("Resta");
- b3 = new Button("Multiplica");
- b4 = new Button("Divide");
- b5 = new Button("Raiz de 1");
- b6 = new Button("Raiz de 2");
- b7 = new Button("Mayor");
- b8 = new Button("Limpia");
- l3 = new Label("Resultado");
- t3 = new TextField(8);
- add(l1);
- add(t1);
- add(l2);
- add(t2);
- add(b1);
- add(b2);
- add(b3);
- add(b4);
- add(b5);
- add(b6);
- add(b7);
- add(b8);
- add(l3);
- add(t3);
- b1. addActionListener(this);
- b2. addActionListener(this);
- b3. addActionListener(this);
- b4. addActionListener(this);
- b5. addActionListener(this);
- b6. addActionListener(this);
- b7. addActionListener(this);
- b8. addActionListener(this);
- }
- public void actionPerformed(ActionEvent ae) {
- if (ae.getSource() == b1) {
- int n1 = Integer.parseInt(t1.getText());
- int n2 = Integer.parseInt(t2.getText());
- int suma = 0;
- suma = n1 + n2;
- t3.setText("" + suma);
- }
- if (ae.getSource() == b2) {
- int n1 = Integer.parseInt(t1.getText());
- int n2 = Integer.parseInt(t2.getText());
- int resta = 0;
- resta = n2 - n1;
- t3.setText("" + resta);
- }
- if (ae.getSource() == b3) {
- int n1 = Integer.parseInt(t1.getText());
- int n2 = Integer.parseInt(t2.getText());
- int multi = 0;
- multi = n1 * n2;
- t3.setText("" + multi);
- }
- if (ae.getSource() == b4) {
- int n1 = Integer.parseInt(t1.getText());
- int n2 = Integer.parseInt(t2.getText());
- int div = 0;
- div = n1 / n2;
- t3.setText("" + div);
- }
- if (ae.getSource() == b5) {
- int n1 = Integer.parseInt(t1.getText());
- double raiz = 0;
- raiz = Math.sqrt(n1);
- t3.setText("" + raiz);
- }
- if (ae.getSource() == b6) {
- int n2 = Integer.parseInt(t2.getText());
- double raiz = 0;
- raiz = Math.sqrt(n2);
- t3.setText("" + raiz);
- }
- if (ae.getSource() == b7) {
- int n1 = Integer.parseInt(t1.getText());
- int n2 = Integer.parseInt(t2.getText());
- int mayor = 0;
- if (n1 > n2)
- mayor = n1;
- else
- mayor = n2;
- t3.setText("" + mayor);
- }
- if (ae.getSource() == b8) {
- t1.setText("");
- t2.setText("");
- t3.setText("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement