0% found this document useful (0 votes)
46 views7 pages

Tsub Tiva Ttotal Bo1 Bo2 Bo3 Rsi Rno Combo CM CC CF: "Autolavado"

This document contains the code for a Java Swing application that calculates the total cost for car washing services. It defines a Ventana class that extends JFrame and implements ActionListener. The class contains code to build the GUI layout using GridBagLayout and add labels, text fields, buttons, radio buttons and checkboxes. It also contains the actionPerformed method that calculates subtotal, IVA tax and total costs based on vehicle type and optional services selected.

Uploaded by

Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views7 pages

Tsub Tiva Ttotal Bo1 Bo2 Bo3 Rsi Rno Combo CM CC CF: "Autolavado"

This document contains the code for a Java Swing application that calculates the total cost for car washing services. It defines a Ventana class that extends JFrame and implements ActionListener. The class contains code to build the GUI layout using GridBagLayout and add labels, text fields, buttons, radio buttons and checkboxes. It also contains the actionPerformed method that calculates subtotal, IVA tax and total costs based on vehicle type and optional services selected.

Uploaded by

Maria
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

import java.awt.

Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.LayoutManager;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

public class Ventana extends JFrame implements ActionListener{

private JTextField tSub, tIva, tTotal;


private JButton bo1, bo2, bo3;
private JRadioButton rSi, rNo;
private JComboBox combo;
private JCheckBox cM, cC, cF;

public Ventana(){
super("Autolavado");
this.setSize(550,400);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//this.addWindowListener(new WindowAdapter() {
//public void windowClosing(WindowEvent e){
//if (JOptionPane.showConfirmDialog(null, "¿Desea
salir del programa?", "Salir", JOptionPane.YES_NO_OPTION)==
JOptionPane.YES_OPTION);
//System.exit(0);
// }
// });

Container cp = getContentPane();
cp.setLayout(new GridBagLayout());

GridBagConstraints bag = new GridBagConstraints();

JLabel titulo = new JLabel("Autolavado");


bag.gridx = 0;
bag.gridy = 0;
bag.gridwidth = 4;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(titulo, bag);

JLabel placa = new JLabel("Placa:");


bag.gridx = 0;
bag.gridy = 1;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(placa, bag);

JLabel tipo = new JLabel("Tipo:");


bag.gridx = 0;
bag.gridy = 2;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(tipo, bag);

JLabel prop = new JLabel("Propietario:");


bag.gridx = 2;
bag.gridy = 1;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(prop, bag);

JLabel subT = new JLabel("Sub-Total:");


bag.gridx = 0;
bag.gridy = 6;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(subT, bag);

JLabel iva = new JLabel("IVA:");


bag.gridx = 0;
bag.gridy = 7;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(iva, bag);

JLabel total = new JLabel("Total:");


bag.gridx = 0;
bag.gridy = 8;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(total, bag);

JLabel addi = new JLabel("Adicionales:");


bag.gridx = 2;
bag.gridy = 2;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(addi, bag);

JLabel fact = new JLabel("Factura:");


bag.gridx = 2;
bag.gridy = 4;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.CENTER;
cp.add(fact, bag);

JTextField tPlaca = new JTextField(6);


bag.gridx = 1;
bag.gridy = 1;
bag.gridwidth = 1;
bag.gridheight = 1;
bag.fill = GridBagConstraints.HORIZONTAL;
cp.add(tPlaca, bag);

JTextField tProp = new JTextField(15);


bag.gridx = 3;
bag.gridy = 1;
bag.gridwidth = 2;
bag.gridheight = 1;
bag.fill = GridBagConstraints.HORIZONTAL;
cp.add(tProp, bag);

JTextField tSub = new JTextField();


tSub.setEditable(false);
bag.gridx = 1;
bag.gridy = 6;
bag.gridwidth = 2;
bag.gridheight = 1;
bag.fill = GridBagConstraints.HORIZONTAL;
cp.add(tSub, bag);

JTextField tIva = new JTextField();


tIva.setEditable(false);
bag.gridx = 1;
bag.gridy = 7;
bag.gridwidth = 2;
bag.gridheight = 1;
bag.fill = GridBagConstraints.HORIZONTAL;
cp.add(tIva, bag);

JTextField tTotal = new JTextField();


tTotal.setEditable(false);
bag.gridx = 1;
bag.gridy = 8;
bag.gridwidth = 2;
bag.gridheight = 1;
bag.fill = GridBagConstraints.HORIZONTAL;
cp.add(tTotal, bag);

JButton bo1 = new JButton("Calcular");


bo1.addActionListener(this);
bag.gridx = 3;
bag.gridy = 6;
bag.gridwidth = 1;
bag.gridheight = 1;
cp.add(bo1, bag);

JButton bo2 = new JButton("Limpiar");


bo2.addActionListener(this);
bag.gridx = 0;
bag.gridy = 9;
bag.gridwidth = 2;
bag.gridheight = 1;
cp.add(bo2, bag);

JButton bo3 = new JButton("Salir");


bo3.addActionListener(this);
bag.gridx = 4;
bag.gridy = 9;
bag.gridwidth = 1;
bag.gridheight = 1;
cp.add(bo3, bag);

combo = new JComboBox<>();


combo.setEditable(false);
combo.addItem("Automóvil");
combo.addItem("Caminota");
combo.addItem("Camión");
combo.addItem("Motocicleta");
bag.gridx = 1;
bag.gridy = 2;
bag.gridwidth = 1;
bag.gridheight = 1;
cp.add(combo,bag);

JPanel pFactura = new JPanel();


bag.gridx = 3;
bag.gridy = 4;
bag.gridwidth = 1;
bag.gridheight = 1;
rSi = new JRadioButton("Sí");
rNo = new JRadioButton("No");
ButtonGroup bg = new ButtonGroup();
bg.add(rSi);
bg.add(rNo);
pFactura.add(rSi);
pFactura.add(rNo);
cp.add(pFactura,bag);
JPanel pAdi = new JPanel();
cM = new JCheckBox("Maletera");
cC = new JCheckBox("Cera");
cF = new JCheckBox("Faros");
pAdi.add(cM);
pAdi.add(cC);
pAdi.add(cF);
bag.gridx = 3;
bag.gridy = 2;
bag.gridwidth = 2;
bag.gridheight = 1;
cp.add(pAdi,bag);

@Override
public void actionPerformed(ActionEvent e) {
JButton boton = (JButton) e.getSource();
// addi por adicionales
double addi1 = 0.0;
double addi2 = 0.0;
double addi3 = 0.0;
double subT = 0.0;
double auto = 30000.0;
double camioneta = 50000.0;
double camion = 100000.0;
double moto = 15000.0;
double maletera = 6000.0;
double cera = 8000.0;
double faros = 15000.0;
double iva = 0.0;
double total = 0.0;

if(boton == bo1){
if(combo.getSelectedItem().toString().equals("Automóvil")){
if(cM.isSelected() == true){
addi1 += maletera;
}

if(cC.isSelected() == true){
addi2 += cera;
}
if(cF.isSelected() == true){
addi3 += faros;
}
subT = auto + addi1 + addi2 + addi3;
}

/* else
if(combo.getSelectedItem().toString().equals("Camioneta")){
if(cM.isSelected() == true){
addi1 = addi1 + maletera;
} else if(cM.isSelected() == false){
addi1 = 0.0;
}
if(cC.isSelected() == true){
addi2 = addi2 + cera;
}else if(cC.isSelected() == false){
addi2 = 0.0;
}
if(cF.isSelected() == true){
addi3 = addi3 + faros;
}else if(cF.isSelected() == false){
addi3 = 0.0;
}
subT = camioneta + addi1 +addi2 + addi3;
}

else if(combo.getSelectedItem().toString().equals("Camión")){
if(cM.isSelected() == true){
addi1 = addi1 + maletera;
} else if(cM.isSelected() == false){
addi1 = 0.0;
}

if(cC.isSelected() == true){
addi2 = addi2 + cera;
}else if(cC.isSelected() == false){
addi2 = 0.0;
}
if(cF.isSelected() == true){
addi3 = addi3 + faros;
}else if(cF.isSelected() == false){
addi3 = 0.0;
}
subT = camion + addi1 +addi2 + addi3;
}

else
if(combo.getSelectedItem().toString().equals("Motocicleta")){
if(cM.isSelected() == true){
addi1 += maletera;
} else if(cM.isSelected() == false){
addi1 = 0.0;
}
if(cC.isSelected() == true){
addi2 += cera;
}else if(cC.isSelected() == false){
addi2 = 0.0;
}
if(cF.isSelected() == true){
addi3 += faros;
}else if(cF.isSelected() == false){
addi3 = 0.0;
}
subT = moto + addi1 +addi2 + addi3;
}*/

tSub.setText(String.valueOf(subT).toString());

if(rSi.isSelected() == true){
iva += subT * .16;
} else if (rNo.isSelected() == true){
iva = subT * 0;
}

tIva.setText(String.valueOf(iva).toString());

total = iva +subT;

tTotal.setText(String.valueOf(total).toString());
}

You might also like