Clase plantilla:
Código:
main:package AgenciaDeCarros;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class DiseñoPrincipal extends JFrame implements ActionListener {
String nombre, Plazo;
int precio;
double desc;
String Desc;
int plazo;
double pagomensual, pago, pagototal, iva;
int credito;
int apertura=0;
//Botones
private JTextArea t1, t2;
private ButtonGroup bg;
private JRadioButton radio1,radio2, radio3, radio4, radio5, radio6;
private JButton boton1, boton2;
public void DiseñoPrincipal(){
setLayout(null);
this.apertura=0;
t2=new JTextArea("Elige el carro que deseas");
t2.setBounds(10,90,150,20);
t2.setEditable(false);
add(t2);
bg=new ButtonGroup();
radio1=new JRadioButton("Avalon");
radio1.setBounds(10,110,100,30);
bg.add(radio1);
add(radio1);
radio2=new JRadioButton("Corolla");
radio2.setBounds(100,110,100,30);
bg.add(radio2);
add(radio2);
radio3=new JRadioButton("Matrix");
radio3.setBounds(200,110,100,30);
bg.add(radio3);
add(radio3);
radio4=new JRadioButton("Prius");
radio4.setBounds(10,140,100,30);
bg.add(radio4);
add(radio4);
radio5=new JRadioButton("Yaris");
radio5.setBounds(100,140,100,30);
bg.add(radio5);
add(radio5);
radio6=new JRadioButton("Camry");
radio6.setBounds(200,140,100,30);
bg.add(radio6);
add(radio6);
boton1=new JButton("REGISTRA");
boton1.setBounds(10,180,100,30);
boton1.addActionListener(this);
add(boton1);
boton2=new JButton("Salir");
boton2.setBounds(200,180,100,30);
boton2.addActionListener(this);
add(boton2);
setTitle("TOYOTA DURANGO");
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource()==boton1) {
if (radio1.isSelected()) {
nombre="Avalon";
precio=350000;
this.apertura=1;
}
if (radio2.isSelected()) {
nombre="Corolla";
precio=200000;
this.apertura=1;
}
if (radio3.isSelected()) {
nombre="Matrix";
precio=195000;
this.apertura=1;
}
if (radio4.isSelected()) {
nombre="Prius";
precio=400000;
this.apertura=1;
}
if (radio5.isSelected()) {
nombre="Yaris";
precio=150000;
this.apertura=1;
}
if (radio6.isSelected()) {
nombre="Camry";
precio=400000;
this.apertura=1;
}
}
if (e.getSource()==boton2) {
this.setVisible(false);
}
}
public void credito(){
UIManager.put("OptionPane.yesButtonText","Crédito");
UIManager.put("OptionPane.noButtonText","Contado");
credito=JOptionPane.showConfirmDialog(null, "Elige La Forma De Pago", "ELIGE", JOptionPane.YES_NO_OPTION);
if(credito == JOptionPane.YES_OPTION){
desc=0.13;
Desc="13%";
pago=precio*desc;
iva=pago*0.16;
pagototal=pago+iva;
}
if(credito == JOptionPane.NO_OPTION){
desc=precio*0.10;
pago=precio+desc;
iva=pago*0.16;
pagototal=pago+iva;
UIManager.put("OptionPane.yesButtonText","12 meses");
UIManager.put("OptionPane.noButtonText","24 meses");
plazo=JOptionPane.showConfirmDialog(null, "Elige El Plazo Para Pagar $"+pagototal, "ELIGE", JOptionPane.YES_NO_OPTION);
if(plazo==JOptionPane.YES_OPTION){
Plazo="12 Meses";
pagomensual=pagototal/12;
}
if(plazo==JOptionPane.NO_OPTION){
Plazo="24 Meses";
pagomensual=pagototal/24;
}
}
}
public void imprimirfactura(){
}
}
Código:
package AgenciaDeCarros;
public class PruebaAgenciaDeCarros {
public static void main(String args[]){
//Metodo Main
DiseñoPrincipal compra=new DiseñoPrincipal();
compra.setBounds(0,0,500,500);
compra.setVisible(true);
if(compra.apertura==1){
compra.credito();
}
}
}


