act2

import java.awt.*; import java.applet.*; import java.awt.event.*; import java.math.*; // public class AppletManejadores

Views 210 Downloads 6 File size 27KB

Report DMCA / Copyright

DOWNLOAD FILE

Recommend stories

Citation preview

import java.awt.*; import java.applet.*; import java.awt.event.*; import 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 = new Button("+"); b2 = new Button("-"); b3 = new Button("*"); b4 = new Button("/"); b5 = new Button("Raiz X"); b6 = new Button("Raiz Y"); b7 = new Button("X ala Y"); b8 = new Button("Y ala X"); b9 = new 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 void actionPerformed(ActionEvent ae) { double num1 = Double.parseDouble(t1.getText()); double num2 = Double.parseDouble(t2.getText()); double 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); }

}