RE:como tomar un valor de un jcombobox
Publicado por
antonio (1 intervención) el 01/05/2010 01:01:21
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Prog10 { //declaracion, creacion e inicializacion de componentes,
private static JFrame ventana= new JFrame();
private static JTextField pantalla = new JTextField(12);
private static JButton boton1 = new JButton("1");
private static JButton boton2 = new JButton("2");
private static JButton boton3 = new JButton("3");
private static JButton boton4 = new JButton("4");
private static JButton boton5 = new JButton("5");
private static JButton boton6 = new JButton("6");
private static JButton boton7 = new JButton("7");
private static JButton boton8 = new JButton("8");
private static JButton boton9 = new JButton("9");
private static JButton boton0 = new JButton("0");
private static JButton suma = new JButton("+");
private static JButton resta = new JButton("-");
private static JButton igual = new JButton("=");
private static int aux;
public static void main(String[] args){ // area de definicion de propiedades de el objeto
ventana.setTitle("Calculadora");
ventana.setSize(260,260);
ventana.setDefaultCloseOperation(ventana.EXIT_ON_CLOSE);
ventana.getContentPane().setLayout(null);
pantalla.setBounds(20,20,210,24);
ventana.getContentPane().add(pantalla);
ventana.getContentPane().setLayout(null );
boton7.setBounds(20,85,45,30);
ventana.getContentPane().add(boton7);
ventana.getContentPane().setLayout(null );
boton8.setBounds(75,85,45,30);
ventana.getContentPane().add(boton8);
ventana.getContentPane().setLayout(null );
boton9.setBounds(130,85,45,30);
ventana.getContentPane().add(boton9);
ventana.getContentPane().setLayout(null );
suma.setBounds(185,85,45,30);
ventana.getContentPane().add(suma);
/////////////////////////////////////////
ventana.getContentPane().setLayout(null );
boton4.setBounds(20,130,45,30);
ventana.getContentPane().add(boton4);
ventana.getContentPane().setLayout(null );
boton5.setBounds(75,130,45,30);
ventana.getContentPane().add(boton5);
ventana.getContentPane().setLayout(null );
boton6.setBounds(130,130,45,30);
ventana.getContentPane().add(boton6);
ventana.getContentPane().setLayout(null );
resta.setBounds(185,130,45,30);
ventana.getContentPane().add(resta);
/////////////////////////////////////////////
ventana.getContentPane().setLayout(null );
boton1.setBounds(20,175,45,30);
ventana.getContentPane().add(boton1);
ventana.getContentPane().setLayout(null );
boton2.setBounds(75,175,45,30);
ventana.getContentPane().add(boton2);
ventana.getContentPane().setLayout(null );
boton3.setBounds(130,175,45,30);
ventana.getContentPane().add(boton3);
ventana.getContentPane().setLayout(null );
igual.setBounds(185,175,45,30);
ventana.getContentPane().add(igual);
////////////////////////////////////////////////
//Operandos Logicos//
/////////////suma///////////////////
ventana.setVisible(true);
////////////////////////////////////////////////
boton1.addMouseListener( new MouseAdapter(){
String numero="";
public void mousePressed(MouseEvent e){
numero+="1";
pantalla.setText(numero);
}
}
);//termina mouse listener
//////////////suma//////////////
boton2.addMouseListener( new MouseAdapter(){
String numero2="";
public void mousePressed(MouseEvent e){
numero2+="2";
pantalla.setText(numero2);
}
}
);//termina mou
}; // termina main