Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
8.1 kB
1
Indexable
Never
package sistemaCocinas;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import java.awt.Color;
import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.awt.event.ActionEvent;
import javax.swing.DropMode;

public class consultarCocina extends JFrame implements ActionListener {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JTextField textPrecio;
	private JTextField textAncho;
	private JTextField textAlto;
	private JTextField textFondo;
	private JTextField textQuemadores;
	private JComboBox cboModelo;
	private JButton btnCerrar;
	
	// Datos mínimos de la primera cocina
	public static String modelo0 = "Mabe EMP6120PG0";
	public static double precio0 = 949.0;
	public static double fondo0 = 58.6;
	public static double ancho0 = 60.0;
	public static double alto0 = 91.0;
	public static int quemadores0 = 4;
	
	// Datos mínimos de la segunda cocina
	public static String modelo1 = "Indurama Parma";
	public static double precio1 = 1089.0;
	public static double ancho1 = 80.0;
	public static double alto1 = 94.0;
	public static double fondo1 = 67.5;
	public static int quemadores1 = 6;
	
	// Datos mínimos de la tercera cocina
	public static String modelo2 = "Sole COSOL027";
	public static double precio2 = 850.0;
	public static double ancho2 = 60.0;
	public static double alto2 = 90.0;
	public static double fondo2 = 50.0;
	public static int quemadores2 = 4;
	
	// Datos mínimos de la cuarta cocina
	public static String modelo3 = "Coldex CX602";
	public static double precio3 = 629.0;
	public static double ancho3 = 61.6;
	public static double alto3 = 95.0;
	public static double fondo3 = 51.5;
	public static int quemadores3 = 5;
	
	// Datos mínimos de la quinta cocina
	public static String modelo4 = "Reco Dakota";
	public static double precio4 = 849.0;
	public static double ancho4 = 75.4;
	public static double alto4 = 94.5;
	public static double fondo4 = 66.0;
	public static int quemadores4 = 5;
	
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					consultarCocina frame = new consultarCocina();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public consultarCocina() {
		setTitle("Consultar Cocina");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel lblNewLabel = new JLabel("CONSULTAR COCINA");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 16));
		lblNewLabel.setForeground(new Color(0, 0, 255));
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setBounds(28, 21, 380, 26);
		contentPane.add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("Modelo");
		lblNewLabel_1.setBounds(38, 58, 95, 14);
		contentPane.add(lblNewLabel_1);
		
		JLabel lblNewLabel_2 = new JLabel("Precio (S/)");
		lblNewLabel_2.setBounds(38, 97, 95, 14);
		contentPane.add(lblNewLabel_2);
		
		JLabel lblNewLabel_3 = new JLabel("Ancho (cm)");
		lblNewLabel_3.setBounds(38, 122, 95, 14);
		contentPane.add(lblNewLabel_3);
		
		JLabel lblNewLabel_4 = new JLabel("Alto (cm)");
		lblNewLabel_4.setBounds(38, 147, 95, 14);
		contentPane.add(lblNewLabel_4);
		
		JLabel lblNewLabel_5 = new JLabel("Fondo (cm)");
		lblNewLabel_5.setBounds(38, 172, 95, 14);
		contentPane.add(lblNewLabel_5);
		
		JLabel lblNewLabel_6 = new JLabel("Quemadores");
		lblNewLabel_6.setBounds(38, 197, 95, 14);
		contentPane.add(lblNewLabel_6);
		
		textPrecio = new JTextField();
		textPrecio.setBackground(new Color(255, 255, 255));
		textPrecio.setEditable(false);
		textPrecio.setHorizontalAlignment(SwingConstants.RIGHT);
		textPrecio.setBounds(143, 94, 121, 20);
		contentPane.add(textPrecio);
		textPrecio.setColumns(10);
		
		textAncho = new JTextField();
		textAncho.setBackground(new Color(255, 255, 255));
		textAncho.setEditable(false);
		textAncho.setHorizontalAlignment(SwingConstants.RIGHT);
		textAncho.setBounds(143, 119, 121, 20);
		contentPane.add(textAncho);
		textAncho.setColumns(10);
		
		textAlto = new JTextField();
		textAlto.setBackground(new Color(255, 255, 255));
		textAlto.setEditable(false);
		textAlto.setHorizontalAlignment(SwingConstants.RIGHT);
		textAlto.setBounds(143, 144, 121, 20);
		contentPane.add(textAlto);
		textAlto.setColumns(10);
		
		textFondo = new JTextField();
		textFondo.setBackground(new Color(255, 255, 255));
		textFondo.setEditable(false);
		textFondo.setHorizontalAlignment(SwingConstants.RIGHT);
		textFondo.setBounds(143, 169, 121, 20);
		contentPane.add(textFondo);
		textFondo.setColumns(10);
		
		textQuemadores = new JTextField();
		textQuemadores.setBackground(new Color(255, 255, 255));
		textQuemadores.setEditable(false);
		textQuemadores.setHorizontalAlignment(SwingConstants.RIGHT);
		textQuemadores.setBounds(143, 194, 121, 20);
		contentPane.add(textQuemadores);
		textQuemadores.setColumns(10);
		
		cboModelo = new JComboBox();
		cboModelo.setModel(new DefaultComboBoxModel(new String[] {"Mabe EMP6120PG0", "Indurama Parma", "Sole COSOL027", "Coldex CX602", "Reco Dakota"}));
		cboModelo.setBounds(143, 54, 141, 22);
		cboModelo.addActionListener(this);
		contentPane.add(cboModelo);
		
		btnCerrar = new JButton("Cerrar");
		btnCerrar.setBounds(319, 93, 89, 23);
		btnCerrar.addActionListener(this);
		contentPane.add(btnCerrar);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		// Variables
		if (e.getSource() == cboModelo); {
			
			// Variables
			double precio, ancho, alto, fondo;
			int modelo, quemadores;
			
			modelo = cboModelo.getSelectedIndex();
			
			// Procesar
			// Evaluar modelo para fijación de precio
			switch (modelo) {
			case 0: precio = precio0; break;
			case 1: precio = precio1; break;
			case 2: precio = precio2; break;
			case 3: precio = precio3; break;
			default: precio = precio4; break;
			}
			
			// Evaluar modelo para fijación de ancho
			switch (modelo) {
			case 0: ancho = ancho0; break;
			case 1: ancho = ancho1; break;
			case 2: ancho = ancho2; break;
			case 3: ancho = ancho3; break;
			default: ancho = ancho4; break;
			}
				
			// Evaluar modelo para fijación de alto
			switch (modelo) {
			case 0: alto = alto0; break;
			case 1: alto = alto1; break;
			case 2: alto = alto2; break;
			case 3: alto = alto3; break;
			default: alto = alto4; break;
			}
				
			// Evaluar modelo para fijación de fondo
			switch (modelo) {
			case 0: fondo = fondo0; break;
			case 1: fondo = fondo1; break;
			case 2: fondo = fondo2; break;
			case 3: fondo = fondo3; break;
			default: fondo = fondo4; break;
			}
				
			//Evaluar modelo para fijación de quemadores
			switch (modelo) {
			case 0: quemadores = quemadores0; break;
			case 1: quemadores = quemadores1; break;
			case 2: quemadores = quemadores2; break;
			case 3: quemadores = quemadores3; break;
			default: quemadores = quemadores4; break;
			}
				
			//Salida
			NumberFormat formateador = new DecimalFormat("#,###,###.00");
			textPrecio.setText (""+formateador.format(precio));
			textAncho.setText(""+formateador.format(ancho));
			textFondo.setText (""+formateador.format(fondo));
			textAlto.setText(""+formateador.format(alto));
			textQuemadores.setText(""+quemadores);
		}
		
		if (e.getSource() == btnCerrar) {
			dispose ();
		}
		
	}
}
Leave a Comment