Ver Mensaje Individual
  #1  
Antiguo 24-01-2015
Gerson12 Gerson12 is offline
Miembro
NULL
 
Registrado: abr 2012
Ubicación: Peru-Lima
Posts: 138
Reputación: 13
Gerson12 Va por buen camino
Problema al validar un código con try catch

Hola amigos disculpen nuevamente la molestia pero necesito de su ayuda tengo un problema con mi codigo al momento de validar con el try{}catch(){} para que no me acepte letras en los campos que deben de ir numeros enteros , les explico lo que pasa es que cuando quiero validar el trozo de codigo le inserto el try{}catch(){} y ejecuto el proyecto y al momento de probar que la validacion estè correcta me lanza un erro en el IDE como si lo hubiera puesto mal necesito su ayuda porfavor ,, les dejo el codigo en general que estoy haciendo y una imagen .
Pd: Este codigo es para mi proyecto de algoritmia q debo de sustentar .

Código:
import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.DefaultComboBoxModel;


public class VentadeChocolate extends JDialog implements ActionListener {
	private JComboBox cbo_TipoChocolate;
	private JLabel lblTipoDeChocolate;
	private JLabel lblCantidadDeCajas;
	private JTextField txt_cantidad;
	private JButton btnVender;
	private JButton btnCerrar;
	private JScrollPane ScrollP;
	private JTextArea txtS;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			VentadeChocolate dialog = new VentadeChocolate();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public VentadeChocolate() {
		setBounds(100, 100, 457, 300);
		getContentPane().setLayout(null);
		{
			cbo_TipoChocolate = new JComboBox();
			cbo_TipoChocolate.addActionListener(this);
			cbo_TipoChocolate.setModel(new DefaultComboBoxModel(new String[] {"Tentaci\u00F3n", "Delicia", "Explosi\u00F3n", "Chokoloko", "ChokoBoom"}));
			cbo_TipoChocolate.setBounds(142, 31, 175, 20);
			getContentPane().add(cbo_TipoChocolate);
		}
		{
			lblTipoDeChocolate = new JLabel("Tipo de Chocolate");
			lblTipoDeChocolate.setBounds(10, 34, 122, 14);
			getContentPane().add(lblTipoDeChocolate);
		}
		{
			lblCantidadDeCajas = new JLabel("Cantidad de Cajas");
			lblCantidadDeCajas.setBounds(10, 59, 122, 14);
			getContentPane().add(lblCantidadDeCajas);
		}
		{
			txt_cantidad = new JTextField();
			txt_cantidad.setBounds(142, 56, 142, 20);
			getContentPane().add(txt_cantidad);
			txt_cantidad.setColumns(10);
		}
		{
			btnVender = new JButton("Vender");
			btnVender.addActionListener(this);
			btnVender.setBounds(338, 30, 89, 23);
			getContentPane().add(btnVender);
		}
		{
			btnCerrar = new JButton("Cerrar");
			btnCerrar.addActionListener(this);
			btnCerrar.setBounds(338, 55, 89, 23);
			getContentPane().add(btnCerrar);
		}
		{
			ScrollP = new JScrollPane();
			ScrollP.setBounds(10, 96, 431, 154);
			getContentPane().add(ScrollP);
			{
				txtS = new JTextArea();
				ScrollP.setViewportView(txtS);
			}
		}
	}
	public void actionPerformed(ActionEvent arg0) {
		if (arg0.getSource() == cbo_TipoChocolate) {
			cbo_TipoChocolateActionPerformed(arg0);
		}
		if (arg0.getSource() == btnCerrar) {
			btnCerrarActionPerformed(arg0);
		}
		if (arg0.getSource() == btnVender) {
			btnVenderActionPerformed(arg0);
		}
	}
	
	void CalculoGeneral(int cajas,int tipo_choco){
	}
	
		
			
	//Este proceso  cumple primeo la funcion de descuento y luego enlaza los demas procesos 
	void ImportedeDescuento(double imp_com,int cajas){
	double imp_desc;
		if (cajas<=5)
			imp_desc=(TiendadeChocolate.PorcDesc1/100.0)*imp_com;
			else if(cajas<=10)
				imp_desc=(TiendadeChocolate.PorcDesc2/100.0)*imp_com;
				else if(cajas<=15)
					imp_desc=(TiendadeChocolate.PorcDesc3/100.0)*imp_com;
					else
						imp_desc=(TiendadeChocolate.PorcDesc4/100.0)*imp_com;
		txtS.append("\n Importe de Descuento:"+imp_desc);
		ImporteaPagar(imp_com, imp_desc);
	}
	
	void ImporteaPagar( double imp_com,double imp_desc){
		double imp_pag;
		imp_pag=imp_com-imp_desc;
		txtS.append("\n Importe a pagar:"+imp_pag);
		Obsequio(imp_pag);
	}
	void Obsequio(double imp_pag){
		if(imp_pag>=TiendadeChocolate.IMPGMRO){
			JOptionPane.showMessageDialog(this,"Premio"+TiendadeChocolate.obsequio);}
		else 
			{JOptionPane.showMessageDialog(this,"Lastima no gano nada");}
	}
	
	void imprimir(String tipo,int unidades,double precio,double peso,int cant_vend,	double imp_com){
		txtS.setText("Tipo de Chocolate:"+tipo);
		txtS.append("\n Unidades por caja:"+unidades);
		txtS.append("\n Precio por caja:"+precio);
		txtS.append("\n Peso por caja:"+peso);
		txtS.append("\n Cantidad de Cajas Vendidas:"+cant_vend);
		txtS.append("\n Importe de Compra:"+imp_com);
		
	
	}
void ActualizaciondeDatos(double imp_com,int cajas){
		int tipo;
		tipo=cbo_TipoChocolate.getSelectedIndex();
		switch (tipo) {
		case 0:
			TiendadeChocolate.tot_ventaTentacion++;
					TiendadeChocolate.cant_cajasvenTentacion+=cajas;
						TiendadeChocolate.imp_totalTentacion+=imp_com;
			
		break;
	case 1: 
		TiendadeChocolate.tot_ventaDelicia++;
				TiendadeChocolate.cant_cajasvenDelicia+=cajas;
					TiendadeChocolate.imp_totalDelicia+=imp_com;
			
		break;
	case 2: TiendadeChocolate.tot_ventaExplosion++;
				TiendadeChocolate.cant_cajasvenExplosion+=cajas;
					TiendadeChocolate.imp_totalExplosion+=imp_com;
		
		break;
	case 3: TiendadeChocolate.tot_ventaChokoloko++;
				TiendadeChocolate.cant_cajasvenChokoloko+=cajas;
					TiendadeChocolate.imp_totalChokoloko+=imp_com;
		break;

		default: TiendadeChocolate.tot_ventaChokoBoom++;
					TiendadeChocolate.cant_cajasvenChokoBoom+=cajas;
						TiendadeChocolate.imp_totalChokoBoom+=imp_com;
			break;
		}
		}
	protected void btnVenderActionPerformed(ActionEvent arg0) {
		
			

try{
	int cant_caja,tipo;
	double imp_com;
	cant_caja=Integer.parseInt(txt_cantidad.getText());
	tipo=cbo_TipoChocolate.getSelectedIndex();
	
	switch(tipo){
	case 0: imp_com=cant_caja*TiendadeChocolate.precio0;
					imprimir(TiendadeChocolate.tipo0,TiendadeChocolate.unidades0, TiendadeChocolate.precio0,TiendadeChocolate.peso0,cant_caja,imp_com);
						ImportedeDescuento(imp_com,cant_caja);	
							ActualizaciondeDatos(imp_com,cant_caja);
	break;
	case 1:imp_com=cant_caja*TiendadeChocolate.precio1;
					imprimir(TiendadeChocolate.tipo1,TiendadeChocolate.unidades1, TiendadeChocolate.precio1,TiendadeChocolate.peso1, cant_caja,imp_com);
						ImportedeDescuento(imp_com,cant_caja);
							ActualizaciondeDatos(imp_com,cant_caja);
	break;
	case 2:imp_com=cant_caja*TiendadeChocolate.precio2;
						imprimir(TiendadeChocolate.tipo2,TiendadeChocolate.unidades2, TiendadeChocolate.precio2,TiendadeChocolate.peso2,cant_caja,imp_com);
							ImportedeDescuento(imp_com,cant_caja);	
								ActualizaciondeDatos(imp_com,cant_caja);
	break;
	case 3:imp_com=cant_caja*TiendadeChocolate.precio3;
						imprimir( TiendadeChocolate.tipo3,TiendadeChocolate.unidades3, TiendadeChocolate.precio3,TiendadeChocolate.peso3,cant_caja,imp_com);
							ImportedeDescuento(imp_com,cant_caja);	
								ActualizaciondeDatos(imp_com,cant_caja);
	break;
	default:imp_com=cant_caja*TiendadeChocolate.precio4;
						imprimir(TiendadeChocolate.tipo4,TiendadeChocolate.unidades4, TiendadeChocolate.precio4,TiendadeChocolate.peso4,cant_caja,imp_com);
							ImportedeDescuento(imp_com,cant_caja);
								ActualizaciondeDatos(imp_com,cant_caja);
	}}
	catch(Exception e){
		JOptionPane.showMessageDialog(this,"holas");
	}}

	protected void btnCerrarActionPerformed(ActionEvent arg0) {
	dispose();
	}
	protected void cbo_TipoChocolateActionPerformed(ActionEvent arg0) {
		txt_cantidad.setText("");
	}
}
__________________
Gracias a todos por apoyarme ^^
Responder Con Cita