Calculadora Con Swing

Páginas: 6 (1275 palabras) Publicado: 8 de abril de 2012
/**
* @(#)SwingCalculadora.java
*
* SwingCalculadora Applet application
*
* @Nelson E. Diettez Lucena
* @version 1.00 2012/4/8
*/

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class SwingCalculadora extends JFrame implements ActionListener {
JTextField t1;
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b12,b13,b14,b15,b16,b17,b18,b19;JPanel p1, p2;
String cadDecimal;
String operador="";
boolean esDecimal = false;
boolean nuevoNumero = true;
double Total = 0.0;
double numero= 0.0;

public static void main( String argv[] ) {
SwingCalculadora app = new SwingCalculadora();
//app.setSize( 300,150 );
//app.setVisible( true );

}

public SwingCalculadora() {
/*setLayout(newGridLayout(4,1,5,5));
Icon icon = new ImageIcon("escanear0005.gif");
JButton boton1 = new JButton("JButton", icon);
JToggleButton boton2 = new JToggleButton("JToggleButton");
JCheckBox boton3 = new JCheckBox("JCheckBox");
JRadioButton boton4 = new JRadioButton("JRadioButton");
add(boton1);
add(boton2);
add(boton3);
add(boton4);
setSize( 900,600 );setVisible( true );*/
setLayout(new FlowLayout());
p1 = new JPanel(new GridLayout(6,3,10,10));
p2 = new JPanel(new BorderLayout());
Icon icon0 = new ImageIcon("cero.gif");
Icon icon1 = new ImageIcon("uno.gif");
Icon icon2 = new ImageIcon("dos.gif");
Icon icon3 = new ImageIcon("tres.gif");
Icon icon4 = new ImageIcon("cuatro.gif");
Icon icon5 = new ImageIcon("cinco.gif");Icon icon6 = new ImageIcon("seis.gif");
Icon icon7 = new ImageIcon("siete.gif");
Icon icon8 = new ImageIcon("ocho.gif");
Icon icon9 = new ImageIcon("nueve.gif");

t1 = new JTextField("0",30);
t1.setEditable( false );
b1 = new JButton("+");
b3 = new JButton("-");
b4 = new JButton("*");
b5 = new JButton("/");
b6 = newJButton("=");
b7 = new JButton("C");
b2 = new JButton("CE");
b8 = new JButton(".");
b9 = new JButton("",icon0);
b10 = new JButton("",icon1);
b13 = new JButton("",icon2);
b14 = new JButton("",icon3);
b15 = new JButton("",icon4);
b16 = new JButton("",icon5);
b17 = new JButton("",icon6);
b12 = new JButton("",icon7);
b18 = newJButton("",icon8);
b19 = new JButton("",icon9);

p2.add(t1, BorderLayout.NORTH);
p1.add(b10);
p1.add(b13);
p1.add(b14);
p1.add(b15);
p1.add(b16);
p1.add(b17);
p1.add(b12);
p1.add(b18);
p1.add(b19);
p1.add(b8);
p1.add(b9);
p1.add(b2);
p1.add(b1);
p1.add(b3);
p1.add(b6);p1.add(b4);
p1.add(b5);
p1.add(b7);
add(p2);
p2.add(p1, BorderLayout.SOUTH);

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);
b10. addActionListener(this);
b12. addActionListener(this);
b13. addActionListener(this);
b14. addActionListener(this);
b15. addActionListener(this);
b16. addActionListener(this);
b17. addActionListener(this);
b18. addActionListener(this);
b19. addActionListener(this);
setSize(600,900 );
setVisible( true );
}

public void actionPerformed(ActionEvent ae) {
String digito;
String unaDecima = ( new Double(0.1) ).toString();
cadDecimal = unaDecima.substring( unaDecima.length()-2 ).substring( 0,1 );
//////Numeros/////////////////
if (ae.getSource() == b8){
if(!esDecimal){
esDecimal=true;...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • Swing
  • Swing
  • swinger
  • Swinger
  • Swing
  • swing
  • swing
  • Rebeldes Del Swing

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS