0% found this document useful (0 votes)
53 views14 pages

b0 b00 b1 b2 b3 b4 b5 b6 b7 b8 b9 BP Bs BR BM BD Bi BL t1 PGG pg1 pg2 p1 p2 Numero Resultado Comp Calc

This document contains code for a Java calculator applet. It defines a class called "calculadora" that extends Applet and implements ActionListener. The class initializes buttons for numbers and operators, sets up text fields to display input/output, and includes methods for number button clicks and arithmetic functions like addition, subtraction etc. that update the display based on button presses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views14 pages

b0 b00 b1 b2 b3 b4 b5 b6 b7 b8 b9 BP Bs BR BM BD Bi BL t1 PGG pg1 pg2 p1 p2 Numero Resultado Comp Calc

This document contains code for a Java calculator applet. It defines a class called "calculadora" that extends Applet and implements ActionListener. The class initializes buttons for numbers and operators, sets up text fields to display input/output, and includes methods for number button clicks and arithmetic functions like addition, subtraction etc. that update the display based on button presses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

package tareas;

import java.applet.Applet;
import java.awt.Button;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class calculadora extends Applet implements ActionListener{

Button b0, b00, b1, b2, b3, b4, b5, b6, b7, b8, b9, bp, bs, br, bm,
bd, bi, bl;
TextField t1;
Panel pgg, pg1, pg2, p1, p2;
private double numero = 0.0;
private double resultado = 0.0;
private String comp = "";
private String calc;


public void init(){}


public void start(){

setLayout(new GridLayout(1, 1, 0, 0));
pgg = new Panel(new GridLayout(2, 1, 0, 0));
pg1 = new Panel(new GridLayout(1, 1, 0, 0));
pg2 = new Panel(new GridLayout(1, 2, 5, 5));
p1 = new Panel(new GridLayout(4, 3, 5, 5));
p2 = new Panel(new GridLayout(3, 2, 5, 5));

b0 = new Button("0");
b00 = new Button("00");
b1 = new Button("1");
b2 = new Button("2");
b3 = new Button("3");
b4 = new Button("4");
b5 = new Button("5");
b6 = new Button("6");
b7 = new Button("7");
b8 = new Button("8");
b9 = new Button("9");
bp = new Button(".");
bs = new Button("+");
br = new Button("-");
bm = new Button("*");
bd = new Button("/");
bi = new Button("=");
bl = new Button("Limpiar");
t1 = new TextField();

p1.add(b7);
p1.add(b8);
p1.add(b9);
p1.add(b4);
p1.add(b5);
p1.add(b6);
p1.add(b1);
p1.add(b2);
p1.add(b3);
p1.add(b00);
p1.add(b0);
p1.add(bp);

p2.add(bs);
p2.add(br);
p2.add(bm);
p2.add(bd);
p2.add(bi);
p2.add(bl);

pg1.add(t1);
pg2.add(p1);
pg2.add(p2);

pgg.add(pg1);
pgg.add(pg2);

add(pgg);

b7.addActionListener(this);
b8.addActionListener(this);
b9.addActionListener(this);
bs.addActionListener(this);
br.addActionListener(this);
b4.addActionListener(this);
b5.addActionListener(this);
b6.addActionListener(this);
bm.addActionListener(this);
bd.addActionListener(this);
b1.addActionListener(this);
b2.addActionListener(this);
b3.addActionListener(this);
bi.addActionListener(this);
b0.addActionListener(this);
b00.addActionListener(this);
bp.addActionListener(this);
bl.addActionListener(this);
}

public void actionPerformed(ActionEvent ae){

if (ae.getSource() == b0){
calc = t1.getText();
t1.setText(calc + "0");
}

if (ae.getSource() == b00){
calc = t1.getText();
t1.setText(calc + "00");
}

if (ae.getSource() == b1){
calc = t1.getText();
t1.setText(calc + "1");
}

if (ae.getSource() == b2){
calc = t1.getText();
t1.setText(calc + "2");
}

if (ae.getSource() == b3){
calc = t1.getText();
t1.setText(calc + "3");
}

if (ae.getSource() == b4){
calc = t1.getText();
t1.setText(calc + "4");
}

if (ae.getSource() == b5){
calc = t1.getText();
t1.setText(calc + "5");
}

if (ae.getSource() == b6){
calc = t1.getText();
t1.setText(calc + "6");
}

if (ae.getSource() == b7){
calc = t1.getText();
t1.setText(calc + "7");
}

if (ae.getSource() == b8){
calc = t1.getText();
t1.setText(calc + "8");
}

if (ae.getSource() == b9){
calc = t1.getText();
t1.setText(calc + "9");
}

if (ae.getSource() == bp){
calc = t1.getText();
t1.setText(calc + ".");
}

if (ae.getSource() == bs){
funcSuma();
}

if (ae.getSource() == br){
funcResta();
}

if (ae.getSource() == bm){
funcMult();
}

if (ae.getSource() == bd){
funcDiv();
}

if (ae.getSource() == bi){
funcIgualdad();
}

if (ae.getSource() == bl){
resultado = 0.0;
numero = 0.0;
comp = "";
calc = "";
t1.setText("");
}
}

public void funcSuma(){

if(t1.getText() == ""){
t1.setText("0");
}

numero = Double.parseDouble(t1.getText());

if(comp == "-"){
resultado = (resultado - numero);
t1.setText("0");
} else if(comp == "*"){
resultado = (resultado * numero);
t1.setText("0");
} else if(comp == "/"){
resultado = (resultado / numero);
t1.setText("0");
}

comp = "+";
numero = Double.parseDouble(t1.getText());
resultado = (resultado + numero);
t1.setText("");
}

public void funcResta(){
numero = Double.parseDouble(t1.getText());

if(comp == "+"){
resultado = (resultado + numero);
t1.setText("");
} else if(comp == "*"){
resultado = (resultado * numero);
t1.setText("");
} else if(comp == "/"){
resultado = (resultado / numero);
t1.setText("");
}

comp = "-";
numero = Double.parseDouble(t1.getText());
resultado = (numero - resultado);
t1.setText("");
}

public void funcMult(){

if(t1.getText() == ""){
t1.setText("1");
}

numero = Double.parseDouble(t1.getText());

if(comp == "+"){
resultado = (resultado + numero);
t1.setText("1");
} else if(comp == "-"){
resultado = (resultado - numero);
t1.setText("1");
} else if (comp == "/"){
resultado = (resultado / numero);
t1.setText("1");
}

if(resultado == 0.0){
resultado = 1.0;
}

comp = "*";
numero = Double.parseDouble(t1.getText());
resultado = (resultado * numero);
t1.setText("");
}

public void funcDiv(){

numero = Double.parseDouble(t1.getText());

if(comp == "+"){
resultado = (resultado + numero);
t1.setText("");
} else if(comp == "-"){
resultado = (resultado - numero);
t1.setText("");
} else if(comp == "*"){
resultado = (resultado * numero);
t1.setText("");
}

if(resultado == 0.0){
resultado = 1.0;
}

comp = "/";
numero = Double.parseDouble(t1.getText());
resultado = (numero / resultado);
t1.setText("");
}

public void funcIgualdad(){

numero = Double.parseDouble(t1.getText());

if(comp == "+"){
resultado = (resultado + numero);
t1.setText("" + resultado);
} else if(comp == "-"){
resultado = (resultado - numero);
t1.setText("" + resultado);
} else if(comp == "*"){
resultado = (resultado * numero);
t1.setText("" + resultado);
} else if (comp == "/"){
resultado = (resultado / numero);
t1.setText("" + resultado);
}
}

public void paint(Graphics g)
{
}

}
package tareas;

import java.applet.Applet;
import java.awt.*;

import javax.swing.JOptionPane;


public class plusvalia extends Applet {
Font nuevo=new Font("Arial",Font.BOLD ,18);
Label b=new Label("Estadisticas de pluvicidad 1985-1994");

public void init(){
this.setSize(400,400);
add(b);
}
public void start(){}
public void paint(Graphics g){
double x= 1;
double x1=300-x*188;
double x25=300-x*206;
double x26=300-x*176;
double x27=300-x*122;
double x28=300-x*24;
double x29=300-x*0;
double x30=300-x*6-5;
double x31=300-x*0;
double x32=300-x*82;
double x33=300-x*142;
double x34=300-x*176;
double x35=300-x*250;




int x2=(int) Math.ceil(x1);
g.drawString("188", 25,x2 );

double x3=300-x*206;
int x4=(int) Math.ceil(x25);
g.drawString("206", 25,x4 );

double x5=300-x*176;
int x6=(int) Math.ceil(x26);
g.drawString("176", 25,x6 );

double x7=300-x*122;
int x8=(int) Math.ceil(x27);
g.drawString("122", 25,x8 );

double x9=300-x*24;
int x10=(int) Math.ceil(x28);
g.drawString("24", 25,x10 );

double x11=300-x*0;
int x12=(int) Math.ceil(x29);
g.drawString("0", 25,x12 );

double x13=300-x*6;
int x14=(int) Math.ceil(x30);
g.drawString("6", 25,x14 );

double x15=300-x*0;
int x16=(int) Math.ceil(x31);
g.drawString("0", 25,x16 );

double x17=300-x*82;
int x18=(int) Math.ceil(x32);
g.drawString("82", 25,x18 );

double x19=300-x*142;
int x20=(int) Math.ceil(x33);
g.drawString("142", 25,x20 );

double x121=300-x*176;
int x22=(int) Math.ceil(x34);
g.drawString("176", 25,x22);

double x23=300-x*250;
int x24=(int) Math.ceil(x35);
g.drawString("250", 25,x24 );



g.drawLine(50, 30, 50, 320);
g.drawLine( 15,300, 400, 300);

g.fillRect(55, x2, 20,300-x2);
g.fillRect(80, x4, 20, 300-x4);
g.fillRect(105, x6, 20, 300-x6);
g.fillRect(130, x8, 20, 300-x8);
g.fillRect(155, x10, 20, 300-x10);
g.fillRect(180, x12, 20, 300-x12);
g.fillRect(205, x14, 20, 300-x14);
g.fillRect(230,x16, 20, 300-x16);
g.fillRect(255, x18, 20, 300-x18);
g.fillRect(280, x20, 20, 300-x20);
g.fillRect(305, x22, 20, 300-x22);
g.fillRect(330, x24, 20, 300-x24);
g.drawString("e", 57, 310);g.drawString("n", 57, 320);g.drawString("e",
57, 330);g.drawString("r", 57, 340);g.drawString("o", 57, 350);
g.drawString("f", 82, 311);g.drawString("e", 82, 321);g.drawString("b",
82, 331);g.drawString("r", 82, 341);g.drawString("e", 82, 351);g.drawString("r",
82, 361);g.drawString("o", 82, 371);
g.drawString("m", 107, 311);g.drawString("a", 107, 321);g.drawString("r",
107, 331);g.drawString("z", 107, 341);g.drawString("o", 107, 351);
g.drawString("a", 132, 311);g.drawString("b", 132, 321);g.drawString("r",
132, 331);g.drawString("i", 132, 341);g.drawString("l", 132, 351);
g.drawString("m", 157, 311);g.drawString("a", 157, 321);g.drawString("y",
157, 331);g.drawString("o", 157, 341);
g.drawString("j", 182, 311);g.drawString("u", 182, 321);g.drawString("n",
182, 331);g.drawString("i", 182, 341);g.drawString("o", 182, 351);
g.drawString("j", 207, 311);g.drawString("u", 207, 321);g.drawString("l",
207, 331);g.drawString("i", 207, 341);g.drawString("o", 207, 351);
g.drawString("a", 232, 311);g.drawString("g", 232, 321);g.drawString("o",
232, 331);g.drawString("s", 232, 341);g.drawString("t", 232,
351);g.drawString("o", 232, 361);
g.drawString("s", 257, 311);g.drawString("e", 257, 321);g.drawString("p",
257, 331);g.drawString("t", 257, 341);g.drawString("i", 257,
351);g.drawString("e", 257, 361);g.drawString("m", 257, 371);g.drawString("b",
257, 381);g.drawString("r", 257, 391);g.drawString("e", 257, 400);
g.drawString("o", 282, 311);g.drawString("c", 282, 321);g.drawString("t",
282, 331);g.drawString("u", 282, 341);g.drawString("b", 282,
351);g.drawString("r", 282, 361);g.drawString("e", 282, 371);
g.drawString("n", 307, 311); g.drawString("o", 307, 321);
g.drawString("m", 307, 331); g.drawString("i", 307, 341);
g.drawString("e", 307, 351); g.drawString("m", 307, 361);
g.drawString("b", 307, 371); g.drawString("r", 307, 381);
g.drawString("e", 307, 391);
g.drawString("d", 333, 311); g.drawString("i", 333, 321);
g.drawString("c", 333, 331); g.drawString("i", 333, 341);
g.drawString("e", 333, 351); g.drawString("m", 333, 361);
g.drawString("b", 333, 371); g.drawString("r", 333, 381);
g.drawString("e", 333, 390);

g.drawString("MEDIA", 20, 20);
g.drawString("MESES", 355,320);
}

}
package tareas;

import java.applet.Applet;
import java.awt.*;
import javax.swing.*;


public class tablamul extends Applet {
JPanel a=new JPanel();
public void init(){
String z = JOptionPane.showInputDialog("ingrese un parametro");
int a1=Integer.parseInt(z);
for( char x='b';x<='n';x++){
}
Label =new Label( " Tabla de multiplicar del " + a1 );
Label b=new Label(" "+a1+" * 1 "+" = "+ a1);
Label c=new Label(" "+a1+" * 2 "+" = "+ a1*2);
Label d=new Label(" "+a1+" * 3 "+" = "+ a1*3);
Label e=new Label(" "+a1+" * 4 "+" = "+ a1*4);
Label f=new Label(" "+a1+" * 5 "+" = "+ a1*5);
Label g=new Label(" "+a1+" * 6 "+" = "+ a1*6);
Label h=new Label(" "+a1+" * 7 "+" = "+ a1*7);
Label i=new Label(" "+a1+" * 8 "+" = "+ a1*8);
Label j=new Label(" "+a1+" * 9 "+" = "+ a1*9);
Label k=new Label(" "+a1+" * 10"+" = "+ a1*10);
Label l=new Label(" "+a1+" * 11"+" = "+ a1*11);
Label m=new Label(" "+a1+" * 12"+" = "+ a1*12);
Label n=new Label(" "+a1+" * 13"+" = "+ a1*13);

this.setSize(200, 300);
b.setPreferredSize(new Dimension(140,15));
a.setLayout(new GridLayout(13,1,2,2));
a.add();
a.add(b);
a.add(c);
a.add(d);
a.add(e);
a.add(f);
a.add(g);
a.add(h);
a.add(i);
a.add(j);
a.add(k);
a.add(l);
a.add(m);

this.add(a);
}
public void start(){}
public void paint(Graphics g){}

}
package tareas;

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

import javax.swing.*;
import javax.swing.event.*;


public class poligonos extends Applet implements ChangeListener
,ActionListener{
JComboBox a=new JComboBox();

JLabel etiqueta,etiqueta1,etiqueta2,etiqueta3,etiqueta4,etiqueta5 ;
JSlider tamao ;
JRadioButton contorno;
JComboBox lados=new JComboBox();
Panel p1=new Panel();
Panel p2=new Panel();
int k ;
Button dibujar=new Button("Dibujar");
Choice color;
Label lab=new Label("Escoja");
int j;

public void init(){

setSize(455,350);
etiqueta=new JLabel (" Valor: 0");
etiqueta1=new JLabel (" # lados");
etiqueta2=new JLabel (" color");
etiqueta3=new JLabel (" ");
etiqueta4=new JLabel (" ");
etiqueta5=new JLabel (" ");

lados.addItem("circulo");
lados.addItem("cuadrado");
lados.addItem("triangulo");
lados.addItem("rombo");
lados.addItem("pentagono");
lados.addItem("hexagono");



tamao=new JSlider(JSlider.HORIZONTAL,0,90,0);
p2.setBackground(Color.white);
p2.setPreferredSize(new Dimension(455,280));


a.addItem("Azul");
a.addItem("Verde");
a.addItem("Rojo");





p1.setPreferredSize(new Dimension(450,45));
p1.setLayout(new GridLayout(2,7,10,5));
p1.add(etiqueta );
p1.add(etiqueta1 );
p1.add(etiqueta2);

p1.add(etiqueta5 );

p1.add(tamao);
p1.add(lados);
p1.add(a);

p1.add(dibujar);



add(p1);
add(p2);
tamao.addChangeListener(this);
dibujar.addActionListener(this);
a.addActionListener(this);

}


public void stateChanged(ChangeEvent e) {
j=((JSlider)e.getSource()).getValue();
etiqueta.setText("Valor:" + ((JSlider)e.getSource()).getValue());
}
public void actionPerformed(ActionEvent ev) {


Forma s=new Forma();
Dimension d=p2.getSize();
int ancho=d.width ;
int alto=d.height;
Graphics g= p2.getGraphics();
int y=alto/2;
int x=ancho/2;
String str=ev.getActionCommand();




if(str.equals( "Dibujar"))
{ g.setColor(Color.white);
g.fill3DRect(0, 0, 600, 600, true);

if(str.equals("in")){
k=9;
}


switch(a.getSelectedIndex()){

case 0:
s.color=Color.blue;
break;
case 1:
s.color=Color.green;
break;
case 2:
s.color=Color.red;
break;

}


switch(lados.getSelectedIndex())
{
case 0:
{
int radio = 50+j;
g.setColor(s.color);


g.fillOval(x - radio,
y - radio, radio * 2, radio * 2);


}

break;
case 1:
{
int lado =100+2*j;
g.setColor(s.color);

g.fill3DRect(x-lado/2 ,y-
lado/2 ,lado,lado,true);

}


break;
case 2:
{
int tamao4=50+j;

g.setColor(s.color);
Polygon triangulo = new
Polygon();



triangulo.addPoint(x,y-tamao4);
triangulo.addPoint(x-
tamao4,y+tamao4);

triangulo.addPoint(x+tamao4,y+tamao4);




g.fillPolygon(triangulo);}



break;
case 3:
{
int tamao2 = 51+j;
g.setColor(s.color);
Polygon rombo=new Polygon();

rombo.addPoint(x,y+tamao2);
rombo.addPoint(x-tamao2,y);
rombo.addPoint(x,y-tamao2);
rombo.addPoint(x+tamao2,y);


g.fillPolygon(rombo);


}

break;
case 4:
{ int tamao1 = 50+j;

g.setColor(s.color);
Polygon pentagono=new
Polygon();
pentagono.addPoint(x-
(tamao1/2),y+tamao1);
pentagono.addPoint(x-
tamao1,y);
pentagono.addPoint(x,y-
tamao1);

pentagono.addPoint(x+tamao1,y);

pentagono.addPoint(x+(tamao1/2),y+tamao1);


g.fillPolygon(pentagono);
}

break;
case 5:

{ int tamao=50+j;
Polygon hexagono=new Polygon();
g.setColor(s.color);
hexagono.addPoint(x-
tamao,y);
hexagono.addPoint(x-
(tamao/2),y+tamao);

hexagono.addPoint(x+(tamao/2),y+tamao);

hexagono.addPoint(x+tamao,y);

hexagono.addPoint(x+(tamao/2),y-tamao);
hexagono.addPoint(x-
(tamao/2),y-tamao);


g.fillPolygon(hexagono);


break;
}
}
}
}

}

class Forma {
int x;
int y;
Color color;
void draw(Graphics g) {;}
}

You might also like