Sei sulla pagina 1di 8

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package GUI;

/**

* @author c17010

*/

public class FrmEjercicio1 extends javax.swing.JFrame {

/**

* Creates new form FrmEjercicio1

*/

public FrmEjercicio1() {

initComponents();

/**

* This method is called from within the constructor to initialize the form.

* WARNING: Do NOT modify this code. The content of this method is always

* regenerated by the Form Editor.

*/

@SuppressWarnings("unchecked")

// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jLabel1 = new javax.swing.JLabel();

jLabel2 = new javax.swing.JLabel();


jLabel3 = new javax.swing.JLabel();

txtNombre = new javax.swing.JTextField();

txtPrecio = new javax.swing.JTextField();

btnProceso = new javax.swing.JButton();

jScrollPane1 = new javax.swing.JScrollPane();

txaSalida = new javax.swing.JTextArea();

txtClave = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

jLabel1.setText("NOMBRE DEL ARTICULO:");

jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

jLabel2.setText("CLAVE :");

jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N

jLabel3.setText("PRECIO ORIGINAL:");

btnProceso.setText("PROCESO");

btnProceso.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(java.awt.event.ActionEvent evt) {

btnProcesoActionPerformed(evt);

});

txaSalida.setColumns(20);

txaSalida.setRows(5);

jScrollPane1.setViewportView(txaSalida);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());


getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jLabel1)

.addComponent(jLabel2)

.addComponent(jLabel3))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 57,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(layout.createSequentialGroup()

.addGap(1, 1, 1)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)

.addComponent(txtClave, javax.swing.GroupLayout.DEFAULT_SIZE, 57,


Short.MAX_VALUE)

.addComponent(txtPrecio)))))

.addGroup(layout.createSequentialGroup()

.addGap(83, 83, 83)

.addComponent(btnProceso)))

.addGap(18, 18, 18)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addGap(45, 45, 45)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 223,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel1)

.addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel2)

.addComponent(txtClave, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)

.addComponent(jLabel3)

.addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(18, 18, 18)

.addComponent(btnProceso)))

.addContainerGap(32, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

private void btnProcesoActionPerformed(java.awt.event.ActionEvent evt) {


String nombre=ingresarNombre();

int clave=ingresarClave();

double precio=ingresaPrecio();

double desc=calcularDescuento(clave,precio);

double pf=calcularPF(precio,desc);

mostrar(nombre,precio,desc,pf);

limpiar();

public void limpiar(){

txtNombre.setText("");

txtClave.setText("");

txtPrecio.setText("");

System.out.println("FIN DEL PROGRAMA!!");

public void mostrar(String nombre,double precio,double desc,double pf){

txaSalida.setText("Nombre:"+nombre+"\n");

txaSalida.append("Precio Original:"+precio+"\n");

txaSalida.append("Descuento:"+desc+"\n");

txaSalida.append("Precio Final:"+pf+"\n");

public double calcularPF(double precio,double desc){

return precio-desc;

public double calcularDescuento(int clave,double precio){

double desc;

switch(clave){

case 1: desc=0; break;

case 2: desc=0.20*precio;break;

default: desc=0.10*precio;

}
return desc;

public String ingresarNombre(){

String nom=txtNombre.getText();

return nom;

public int ingresarClave(){

int clave=Integer.parseInt(txtClave.getText());

return clave;

public double ingresaPrecio(){

double precio=Double.parseDouble(txtPrecio.getText());

return precio;

public static void main(String args[]) {

/* Set the Nimbus look and feel */

//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">

/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.

* For details see


http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html

*/

try {

for (javax.swing.UIManager.LookAndFeelInfo info :


javax.swing.UIManager.getInstalledLookAndFeels()) {

if ("Nimbus".equals(info.getName())) {

javax.swing.UIManager.setLookAndFeel(info.getClassName());

break;

} catch (ClassNotFoundException ex) {


java.util.logging.Logger.getLogger(FrmEjercicio1.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(FrmEjercicio1.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(FrmEjercicio1.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(FrmEjercicio1.class.getName()).log(java.util.logging.Level.SE
VERE, null, ex);

//</editor-fold>

/* Create and display the form */

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new FrmEjercicio1().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton btnProceso;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JTextArea txaSalida;

private javax.swing.JTextField txtClave;


private javax.swing.JTextField txtNombre;

private javax.swing.JTextField txtPrecio;

// End of variables declaration

Potrebbero piacerti anche