You are on page 1of 3

import import import import

java.awt.*; java.applet.*; java.awt.event.*; java.math.*;

// public class AppletManejadores extends Applet implements ActionListener{ Button b1, b2, b3, b4, b5, b6, b7, b8, b9; TextField t1, t2, t3; Label l1, l2 ,l3; public AppletManejadores() { setLayout(new GridLayout(5, 3, 10, 10)); l1 = new Label("X",Label.CENTER); l2 = new Label("Y",Label.CENTER); l3 = new Label("Resultado",Label.CENTER); t1 = new TextField(); t2 = new TextField(); t3 = new TextField(); t3.setEditable(false); b1 b2 b3 b4 b5 b6 b7 b8 b9 = = = = = = = = = new new new new new new new new new Button("+"); Button("-"); Button("*"); Button("/"); Button("Raiz X"); Button("Raiz Y"); Button("X ala Y"); Button("Y ala X"); Button("X modo Y");

add(l1); add(l2); add(l3); add(t1); add(t2); add(t3); add(b1); add(b2); add(b3); add(b4); add(b5); add(b6); add(b7); add(b8); add(b9); b1.addActionListener(this); b2.addActionListener(this); b3.addActionListener(this); b4.addActionListener(this); b5.addActionListener(this);

b6.addActionListener(this); b7.addActionListener(this); b8.addActionListener(this); b9.addActionListener(this);

} public { double double double void actionPerformed(ActionEvent ae) num1 = Double.parseDouble(t1.getText()); num2 = Double.parseDouble(t2.getText()); operacion = 0;

if (ae.getSource() == b1) { operacion = (num1)+(num2); // t3.setText(""+operacion); } if (ae.getSource() == b2) { operacion = (num1)-(num2); // t3.setText(""+operacion); } if (ae.getSource() == b3) { operacion = (num1)*(num2); // t3.setText(""+operacion); }

if (ae.getSource() == b4) { if (num2 != 0) { operacion = (num1)/(num2); } else { // t3.setText(""+operacion); operacion = 0.0; } }

if (ae.getSource() == b5) { if (num1 > 0) { operacion = Math.sqrt((num1)); } else { operacion = 0.0; } }

if (ae.getSource() == b6) { if (num2 > 0) { operacion = Math.sqrt(num2); } else { operacion = 0.0; } } if (ae.getSource()== b7) { operacion = Math.pow(num1,num2); // t3.setText(""+operacion); } if (ae.getSource()== b8) { operacion = Math.pow(num1,num2); // t3.setText(""+operacion); } if (ae.getSource() == b9) { // Modulo de X con el valor de Y operacion = num1 % num2; } t3.setText(""+operacion); } }

You might also like