Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 4

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this
template
*/
package gui;

import javax.swing.JOptionPane;

/**
*
* @author ARTHAS
*/
public class Formulario1 extends javax.swing.JFrame {

/**
* Creates new form Formulario1
*/
public Formulario1() {
initComponents();
setLocationRelativeTo(null);
}

/**
* 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() {

jPanel1 = new javax.swing.JPanel();


jLabel1 = new javax.swing.JLabel();
txtCantidad = new javax.swing.JTextField();
btnCalcular = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
txtReporte = new javax.swing.JTextArea();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("PRODUCTOS"));

jLabel1.setText("CANTIDAD");

btnCalcular.setText("CALCULAR");
btnCalcular.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCalcularActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new
javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout
.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement
.RELATED)
.addComponent(txtCantidad,
javax.swing.GroupLayout.PREFERRED_SIZE, 40,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(138, 138, 138)
.addComponent(btnCalcular)))
.addContainerGap(153, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(

jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout
.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(txtCantidad,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED
, 50, Short.MAX_VALUE)
.addComponent(btnCalcular)
.addContainerGap())
);

txtReporte.setColumns(20);
txtReporte.setRows(5);
jScrollPane1.setViewportView(txtReporte);

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.TRAILING)
.addComponent(jScrollPane1)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED
)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE,
153, Short.MAX_VALUE)
.addContainerGap())
);

pack();
}// </editor-fold>

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

// TODO add your handling code here:


int cantidadProductos=Integer.parseInt(txtCantidad.getText());
String[] productos=new String[cantidadProductos];
double suma=0;
for(int i=0;i<productos.length;i++)
{
double
precio=Double.parseDouble(JOptionPane.showInputDialog("Ingrese el precio del
producto "+ (i+1)));
suma=suma+precio;
}

txtReporte.setText("El resultado de la compra es\t: "+suma+"\n");


double descuento=0.12*suma;
txtReporte.append("El descuento es\t: "+descuento+"\n");
double precioNeto=suma-descuento;
txtReporte.append("El precio neto a pagar es\t:"+precioNeto+"\n");

private void formWindowOpened(java.awt.event.WindowEvent evt) {

// TODO add your handling code here:

/**
* @param args the command line arguments
*/
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(Formulario1.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(Formulario1.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(Formulario1.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(Formulario1.class.getName()).log(java.util.loggi
ng.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Formulario1().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton btnCalcular;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField txtCantidad;
private javax.swing.JTextArea txtReporte;
// End of variables declaration
}

You might also like