//******************primer archivo
package Paque_Eds;
//::::::::::::::::::::::::::::::::::::::EDWARD ESTEBAN MARTINEZ MIRANDA:::::::::::::::::::::::::::::::::::::::::://
//...........................::::::::::::Dj Edwars::::::::::::..................................
import java.awt.BorderLayout;
import java.awt.event.ActionListener;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import javax.swing.*;
import Op.Operar;
public class Cal_Edwars {
JFrame frame;//frame la ventana
JPanel mp;//panel para botones
JPanel mp1;//panel para el cuadro de texto (JTextField)
JPanel mpf;//el de la firma
JTextField Mostrar;//caja de texto (display)
//Menu menu = new Menu( "Aplicación" );
JLabel Firma;//LABEL PARA MI FIRMA
//crear botones
JButton B_1;
JButton B_2;
JButton B_3;
JButton B_4;
JButton B_5;
JButton B_6;
JButton B_7;
JButton B_8;
JButton B_9;
JButton B_0;
JButton B_S;
JButton B_r;
JButton B_I;
JButton B_M;
JButton B_D;
JButton B_p;
JButton B_c;
JButton B_del;
JButton B_ra;
JButton B_porc;
public double a;//variable para el primer numero
public double b;//variable para el segundo nuero
public double op;//esta variable realiza la operacion segun el signo.
public String c="";//aqui de guarda el signo de la operacion para luego ser condicionado.
public String acum="";//acumulador del valor digitado
//
public static void main(String Edwars[]){ //metodo principal
Cal_Edwars n=new Cal_Edwars();
}
//CONSTRUCTOR
public Cal_Edwars() {
//1.creo el frame
frame = new JFrame("Calculadora");//nombre del framer
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mp=new JPanel(new GridLayout(5,4));//grillas (filas , y , columnas)
mp1=new JPanel(new GridLayout(1,1));//SE CREA UN SEGUNDO PANEL PARA LA CAJA DE TEXTO
mpf=new JPanel(new GridLayout(1,1));//firma
//CUADROS DE TEXTO CON TAMAÑO
Mostrar=new JTextField();//no tiene dimencion
//inicializar botones y label
Firma=new JLabel(" EDWARS MARTINEZ");
B_1=new JButton("1");//nombre del boton
B_2=new JButton("2");
B_3=new JButton("3");
B_4=new JButton("4");
B_5=new JButton("5");
B_6=new JButton("6");
B_7=new JButton("7");
B_8=new JButton("8");
B_9=new JButton("9");
B_0=new JButton("0");
B_S=new JButton("+");
B_r=new JButton("-");
B_M=new JButton("*");
B_c=new JButton("c");
B_I=new JButton("=");
B_D=new JButton("/");
B_p=new JButton(".");
B_del=new JButton("d");
B_ra=new JButton("#");
B_porc=new JButton("%");
//adicionar objetos al Panel
mp1.add(Mostrar);//se adiciona primero el segundo panel que contiene la caja de texto
//luego siguen los botones para el otro panel
mp.add(B_1);
mp.add(B_2);
mp.add(B_3);
mp.add(B_S);
mp.add(B_4);
mp.add(B_5);
mp.add(B_6);
mp.add(B_r);
mp.add(B_7);
mp.add(B_8);
mp.add(B_9);
mp.add(B_M);
mp.add(B_c);
mp.add(B_0);
mp.add(B_I);
mp.add(B_D);
mp.add(B_p);
mp.add(B_del);
mp.add(B_ra);
mp.add(B_porc);
mpf.add(Firma);
//SE AGREGAN LOS PANELES AL FRAME
frame.getContentPane().add(mp1,BorderLayout.CENTER);//adicion de del segudo panel al frame
frame.getContentPane().add(mp,BorderLayout.SOUTH);//adicion de del primero panel al frame
frame.getContentPane().add(mpf,BorderLayout.NORTH);
//ACCIONES PARA LOS BOTONES NUMERICOS
// Darle acciones alos botones
B_1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
//operaciones micalculadora= new operaciones();
acum=Mostrar.getText()+"1";
// txtresultado.setText(String.valueOf(micalculadora.resta(Integer.parseInt(txtnum1.getText()), Integer.parseInt(txtnum2.getText()),Integer.parseInt(txtnum3.getText()))));
Mostrar.setText(acum);
}
});
B_2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"2";
Mostrar.setText(acum);
}
});
B_3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"3";
Mostrar.setText(acum);
}
});
B_4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"4";
Mostrar.setText(acum);
}
});
B_5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"5";
Mostrar.setText(acum);
}
});
B_6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"6";
Mostrar.setText(acum);
}
});
B_7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"7";
Mostrar.setText(acum);
}
});
B_8.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"8";
Mostrar.setText(acum);
}
});
B_9.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"9";
Mostrar.setText(acum);
}
});
B_0.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText()+"0";
Mostrar.setText(acum);
}
});
B_S.addActionListener(new ActionListener(){//boton para sumar
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText();
a=(Double.parseDouble(acum));
c="+";
//op=a;
Mostrar.setText("");
}
});
B_r.addActionListener(new ActionListener(){//boton para restar
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText();
a=(Double.parseDouble(acum));
c="-";
//op=a;
Mostrar.setText("");
}
});
B_M.addActionListener(new ActionListener(){//boton para multiplica
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText();
a=(Double.parseDouble(acum));
c="*";
//op=a;
Mostrar.setText("");
}
});
B_D.addActionListener(new ActionListener(){//boton para dividir
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText();
a=(Double.parseDouble(acum));
c="/";
//op=a;
Mostrar.setText("");
}
});
B_c.addActionListener(new ActionListener(){//boton que borra el campo de texto
public void actionPerformed(ActionEvent e){
acum="";
Mostrar.setText(acum);
}
});
B_I.addActionListener(new ActionListener(){//boton igual
public void actionPerformed(ActionEvent e) {
acum=Mostrar.getText();
//int a=(Integer.parseInt(acum));
b=(Double.parseDouble(acum));
Operar obj=new Operar();
if(c=="+"){//condicional para c (variable que me almacena los signos)
//op=a+b;
//String.valueOf(obj.suma(a,b));
//acum=(String.valueOf(a));
Mostrar.setText(String.valueOf(obj.suma(a,b)));
}else{
if(c=="-"){
//op=a-b;
//acum=(String.valueOf(op));
Mostrar.setText(String.valueOf(obj.resta(a,b)));
}
else{
if(c=="*"){
//op=a*b;
//acum=(String.valueOf(op));
Mostrar.setText(String.valueOf(obj.mul(a,b)));
}
else{
if(c=="/"){
//op=a/b;
//acum=(String.valueOf(op));
Mostrar.setText(String.valueOf(obj.div(a,b)));
//JOptionPane.showMessageDialog(null, "profe nada mas con mumeros enteros");
}
}
}
}
}
});
//Dimensionar el Jframe
frame.pack();//no se puede cambiar el tamaño ""
//frame.setSize(240, 176);
frame.setResizable(false);//estatico
frame.setLocationRelativeTo(frame.getParent());
frame.setVisible(true);//visible
}//fin del contructor
}//fin de la clase
//*************************************************************************
package Op;
public class Operar {
public double suma(double a,double b){
double r=a+b;
return r;
}
public double resta(double a,double b){
double r=a-b;
return r;
}
public double mul(double a,double b){
double r=a*b;
return r;
}
public double div(double a,double b){
double r=a/b;
return r;
}
}
miércoles, 24 de marzo de 2010
Suscribirse a:
Enviar comentarios (Atom)
ta wena ta wena...por ahi toy haciendo la mia ojala kede mejor ke la tuya ... aunke no creo porke la toy haciendo con netBeans y despues me toca adaptarla a eclipse compa wen trabajo
ResponderEliminarCODIGO PARA AGREGAR IMAGENES
ResponderEliminarpublic PanelImagen( ){
setBorder( new TitledBorder( "imagen" ) );
setLayout( new GridBagLayout( ) );
ImageIcon imagen = new ImageIcon( " ruta de la imagen" );
etiquetaImagen = new JLabel( "" );
etiquetaImagen.setIcon( imagen );
add( etiquetaImagen );
}
//por lo general se crea una carpeta llamada
//data y alli se almacenan las imagenes que
//desees utilizar...aunke tmbn puedes poner una
//ruta desde tu ordenador