You are on page 1of 4

package plplplp;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;
import java.awt.Color;

import javax.swing.JTextField;

import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

public class ab extends JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField tfComida;
private JTextField tfBebida;
private JSpinner spinner;

/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ab frame = new ab();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

/**
* Create the frame.
*/
public ab() {
setTitle("Restaurante");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 393, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);

JLabel labelComida = new JLabel("Comidas");


labelComida.setBounds(10, 36, 69, 14);
contentPane.add(labelComida);

JLabel labelBebida = new JLabel("Bebidas");


labelBebida.setBounds(10, 71, 69, 14);
contentPane.add(labelBebida);

JComboBox<String> cboBebida = new JComboBox<String>();


cboBebida.setBounds(89, 67, 100, 20);
cboBebida.setModel(new DefaultComboBoxModel<String>(new String[] {
"-","bebida1", "bebida2", "bebida3", "bebida4"}));
contentPane.add(cboBebida);

JComboBox<String>
cboComida = new JComboBox<String>();
cboComida.setModel(new DefaultComboBoxModel<String>(new String[] {
"-", "comida1", "comida2", "comida3", "comida4"}));
cboComida.setBounds(89, 36, 100, 20);
contentPane.add(cboComida);

JScrollPane scrollPane = new JScrollPane();


scrollPane.setBounds(10, 119, 357, 131);
contentPane.add(scrollPane);

JTextArea txtRslt = new JTextArea();


txtRslt.setBorder(new LineBorder(new Color(0, 0, 0)));
txtRslt.setBounds(10, 119, 357, 131);
//contentPane.add(txtRslt);
scrollPane.setViewportView(txtRslt);

tfComida = new JTextField();


tfComida.setBounds(199, 36, 30, 20);
contentPane.add(tfComida);
tfComida.setColumns(10);

tfBebida = new JTextField();


tfBebida.setColumns(10);
tfBebida.setBounds(199, 68, 30, 20);
contentPane.add(tfBebida);

JButton btnOrdenar = new JButton("Ordenar");


btnOrdenar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//aquí empieza la partr del código

int cantidadB, cantidadC, opcionC, opcionB;


double precioC = 0, precioB = 0, impC, impB, impTotal;
String total, icCfin, icBfin;

//cantidad = Integer.parseInt(txtCantidad.getText());
opcionC = cboComida.getSelectedIndex();
opcionB = cboBebida.getSelectedIndex();

cantidadC = (Integer) spinner.getValue();


cantidadB = (Integer) spinner.getValue();

if (opcionC == 0) {
precioC = 0;
}
if (opcionC == 1) {
precioC = 7.5;
}
if (opcionC == 2) {
precioC = 4.35;
}
if (opcionC == 3) {
precioC = 3.50;
}
if (opcionC == 4) {
precioC = 4.55;
}

impC = precioC * cantidadC;


icCfin = String.format("%.2f", impC);

if (opcionB == 0) {
precioB = 0;
}
if (opcionB == 1) {
precioB = 4.5;
}

if (opcionB == 2) {
precioB = 4.35;
}
if (opcionB == 3) {
precioB = 3.50;
}
if (opcionB == 4) {
precioB = 4.55;
}

impB = precioB * cantidadB;


icBfin = String.format("%.2f", impB);

impTotal = impC + impB;


total = String.format("%.2f", impTotal);

txtRslt.append("\n");
txtRslt.append("oal" + "\n");
txtRslt.append("Importe total por comida: " + icCfin + "\n");
txtRslt.append("Importe total por bebida: " + icBfin + "\n");
txtRslt.append("Total: " + total + "\n");
txtRslt.append("\n");

//textarea = txtResults

}
});

btnOrdenar.setBounds(285, 32, 82, 23);


contentPane.add(btnOrdenar);

JButton btnBorrar = new JButton("New button");

btnBorrar.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

txtRslt.setText(null);
}
});
btnBorrar.setBounds(285, 67, 82, 23);
contentPane.add(btnBorrar);

spinner = new JSpinner();


spinner.setModel(new SpinnerNumberModel(0, 0, 10, 1));
spinner.setBounds(239, 67, 39, 22);
contentPane.add(spinner);

JSpinner spinner1 = new JSpinner();


spinner1.setBounds(238, 36, 39, 20);
contentPane.add(spinner1);

}
}

You might also like