Matematicas

Páginas: 8 (1827 palabras) Publicado: 15 de enero de 2013
Caja Fuerte
import java.awt.*; import java.awt.event.*; import java.applet.Applet; import java.util.Random; public class CajaFuerte extends Applet implements ActionListener,TextListener{ Button uno,dos,tres,reintentar,mostrar; TextArea display; int clave = 123321; public void init(){ uno = new Button(“1”); add(uno); uno.addActionListener(this); dos = new Button(“2”); add(dos);dos.addActionListener(this); tres = new Button(“3”); add(tres); tres.addActionListener(this); reintentar = new Button(“Generar Clave”); add(reintentar); reintentar.addActionListener(this); mostrar = new Button(“Mostrar”); add(mostrar); mostrar.addActionListener(this); display = new TextArea(); add(display); display.addTextListener(this);

} public void paint(Graphics g){ uno.setLocation(10,20);dos.setLocation(40,20); tres.setLocation(70,20); reintentar.setLocation(10,50); mostrar.setLocation(120,50); display.setLocation(10,80); display.setSize(100,50); display.setEditable(false); g.drawString(“Intenta adivinar la combinación de la caja xxxxxx”,10,10); } public void actionPerformed(ActionEvent e) { Random r1 = new Random(System.currentTimeMillis()); String temp = “”; int num,i; if(e.getSource() ==reintentar){ for(i = 0;i < 6;i++){

display.setText(“”); showStatus(“Nueva clave generada. Intenta de nuevo”); num = r1.nextInt(3)+1; temp = temp + Integer.toString(num); } clave = Integer.parseInt(temp); } if (e.getSource() == mostrar) showStatus(Integer.toString(clave)); if (e.getSource() == uno) display.append(“1”); if (e.getSource() == dos) display.append(“2”); if (e.getSource() == tres)display.append(“3”); repaint(); }

public void textValueChanged(TextEvent e) { String cad = display.getText(); if ( cad.length() > 6){ showStatus(“Error”); display.setText(cad.substring(0,6)); } if ( cad.length() == 6 && Integer.parseInt(cad) == clave){ showStatus(“Clave Correcta”); } if (cad.length() == 6 && Integer.parseInt(cad) != clave){ showStatus(“Clave Incorrecta”); display.setText(“”); }repaint(); } }

Calculadora
import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class Calculadora extends Applet implements ActionListener{ TextArea field; Button uno,dos,tres,cuatro,cinco,seis,siete,ocho,nueve,cero,mas,menos,igual,por,entre,limpiar,ans; int flag = 0,ope; long a=0,b=0; public void paint(Graphics g){ field.setSize(200,20); field.setLocation(10,10);uno.setLocation(10,30);

dos.setLocation(30,30); tres.setLocation(50,30); cuatro.setLocation(70,30); cinco.setLocation(90,30); seis.setLocation(110,30); siete.setLocation(130,30); ocho.setLocation(150,30); nueve.setLocation(170,30); cero.setLocation(190,30); mas.setLocation(10,50); menos.setLocation(30,50); por.setLocation(50,50); entre.setLocation(70,50); igual.setLocation(90,50); limpiar.setLocation(110,50); ans.setLocation(110+limpiar.getWidth(),50); } public void init(){ field = new TextArea(); add(field); uno = new Button(“1”); add(uno); uno.addActionListener(this); dos = new Button(“2”); add(dos); dos.addActionListener(this); tres = new Button(“3”); add(tres); tres.addActionListener(this); cuatro = new Button(“4”); add(cuatro); cuatro.addActionListener(this); cinco = new Button(“5”);add(cinco); cinco.addActionListener(this); seis = new Button(“6”); add(seis); seis.addActionListener(this); siete = new Button(“7”); add(siete); siete.addActionListener(this); ocho = new Button(“8”); add(ocho); ocho.addActionListener(this); nueve = new Button(“9”); add(nueve); nueve.addActionListener(this); cero = new Button(“0”); add(cero); cero.addActionListener(this); mas = new Button(“+”); add(mas); mas.addActionListener(this); menos = new Button(“-“); add(menos); menos.addActionListener(this); por = new Button(“*”); add(por); por.addActionListener(this); entre = new Button(“\\”); add(entre); entre.addActionListener(this); igual = new Button(“=”); add(igual); igual.addActionListener(this); limpiar = new Button(“Limpiar”); add(limpiar); limpiar.addActionListener(this); ans = new...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Matematica
  • Matematica
  • Matematicas
  • Las matemáticas
  • Matematica
  • Matematicas
  • Matematica
  • Matematicas

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS