Programacion Java Applet Calculadora
Enviado por • 16 de Junio de 2014 • 1.892 Palabras (8 Páginas) • 311 Visitas
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package applet1;
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
/**
*
* @author Juan
*/
public class AppletCalculadora extends Applet implements ActionListener{
Panel p1,p2;
TextField t1;
Button [] botones=new Button[18];
double op1,op2,resultado;
int operador;
int oper=-1;
@Override
public void init() {
this.resize(130,200);
}
public AppletCalculadora(){
t1=new TextField("",12);
add(t1);
p2=new Panel(new GridLayout(6,3,5,5));
for(int i=0;i<18;i++){
if(i<9){
botones[i]=new Button(String.valueOf(i+1));
}
switch (i){
case 9:
botones[i]=new Button(".");
break;
case 10:
botones[i]=new Button("0");
break;
case 11:
botones[i]=new Button("CE");
break;
case 12:
botones[i]=new Button("+");
break;
case 13:
botones[i]=new Button("-");
break;
case 14:
botones[i]=new Button("=");
break;
case 15:
botones[i]=new Button("*");
break;
case 16:
botones[i]=new Button("/");
break;
case 17:
botones[i]=new Button("C");
break;
}
botones[i]. addActionListener(this);
p2.add(botones[i]);
}
add(p2);
}
public void actionPerformed(ActionEvent e) {
for(int i=0;i<9;i++){
if(e.getSource()==botones[i]){
if(oper==-1){
t1.setText(t1.getText()+String.valueOf(i+1));
}else{
t1.setText(String.valueOf(i+1));
...