0% found this document useful (0 votes)
15 views17 pages

Sala Guia 14

Uploaded by

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

Sala Guia 14

Uploaded by

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

UNIVERSIDAD

TECNOLÓGICA DE LOS
ANDES

PROGRAMACIÓN ORIENTADA A
OBJETOS
ING. DE SISTEMAS E INFORMÁTICA-A-CUSCO-202401

TEMA: guia14

MAGISTER:

GODOFREDO POCCORI UMERES

GRUPO:

• DANTE NAYHUA HUAMAN


1. Codificación en Java NetBeans (TXT)

Clase:

package PClases;

public class Casa {

public double soles;

public double dolares;

public double marcos;

public double CalculaMontoEuros()

return(soles/3.51+marcos/2.12+dolares)*1.09;

Jframe:

package PFormulario;

import PClases.Casa;

import javax.swing.DefaultListModel;

import javax.swing.ImageIcon;

import javax.swing.JOptionPane;

import javax.swing.JButton;
import javax.swing.JFrame;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JTextField;

import javax.swing.JList;

import javax.swing.JScrollPane;

/**

* @author DES23

*/

public class frmCasaCambio extends javax.swing.JFrame {

/**

* Creates new form frmCasaCambio

*/

public frmCasaCambio() {

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();


txtSoles = new javax.swing.JTextField();

txtDolares = new javax.swing.JTextField();

txtMarcos = new javax.swing.JTextField();

btnProcesar = new javax.swing.JButton();

btnLimpiar = new javax.swing.JButton();

btnSalir = new javax.swing.JButton();

jScrollPane1 = new javax.swing.JScrollPane();

lstResumen = new javax.swing.JList<>();

jLabel2 = new javax.swing.JLabel();

jLabel3 = new javax.swing.JLabel();

jLabel4 = new javax.swing.JLabel();

btnimagen = new javax.swing.JButton();

label = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

jLabel1.setForeground(new java.awt.Color(0, 0, 204));

jLabel1.setText("CONTROL DE CAMBIOS - CASA DE CAMBIOS");

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

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

txtMarcosActionPerformed(evt);

});

btnProcesar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

btnProcesar.setForeground(new java.awt.Color(0, 153, 51));

btnProcesar.setText("Procesar");

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

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


btnProcesarActionPerformed(evt);

});

btnLimpiar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

btnLimpiar.setForeground(new java.awt.Color(0, 0, 255));

btnLimpiar.setText("Limpiar");

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

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

btnLimpiarActionPerformed(evt);

});

btnSalir.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

btnSalir.setForeground(new java.awt.Color(255, 0, 0));

btnSalir.setText("Salir");

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

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

btnSalirActionPerformed(evt);

});

lstResumen.setModel(new javax.swing.AbstractListModel<String>() {

String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };

public int getSize() { return strings.length; }

public String getElementAt(int i) { return strings[i]; }

});

jScrollPane1.setViewportView(lstResumen);

jLabel2.setForeground(new java.awt.Color(0, 0, 255));

jLabel2.setText("VALOR SOLES");
jLabel3.setForeground(new java.awt.Color(0, 0, 255));

jLabel3.setText("VALOR DOLARES");

jLabel4.setForeground(new java.awt.Color(0, 0, 204));

jLabel4.setText("VALOR MARCOS");

btnimagen.setText("Imagen");

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

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

btnimagenActionPerformed(evt);

});

label.setIcon(new
javax.swing.ImageIcon("C:\\Users\\LENOVO\\OneDrive\\Documentos\\NetBeansProjects\\gui
a14\\build\\classes\\imagen03.png")); // NOI18N

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()

.addGap(182, 182, 182)

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


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(layout.createSequentialGroup()

.addGap(23, 23, 23)

.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 306,


javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()

.addGap(80, 80, 80)

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

.addComponent(txtSoles)

.addComponent(btnProcesar, javax.swing.GroupLayout.DEFAULT_SIZE, 111,


Short.MAX_VALUE)

.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

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

.addGroup(layout.createSequentialGroup()

.addGap(95, 95, 95)

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

.addComponent(txtDolares, javax.swing.GroupLayout.PREFERRED_SIZE,
100, javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel3)))

.addGroup(layout.createSequentialGroup()

.addGap(36, 36, 36)

.addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 100,


javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGap(48, 48, 48)

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

.addGroup(layout.createSequentialGroup()

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

.addComponent(jLabel4)

.addComponent(txtMarcos, javax.swing.GroupLayout.PREFERRED_SIZE,
111, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGap(113, 113, 113))

.addGroup(layout.createSequentialGroup()

.addComponent(btnimagen)

.addGap(18, 18, 18)


.addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 91,
javax.swing.GroupLayout.PREFERRED_SIZE))))

.addGroup(layout.createSequentialGroup()

.addGap(462, 462, 462)

.addComponent(label, javax.swing.GroupLayout.PREFERRED_SIZE, 258,


javax.swing.GroupLayout.PREFERRED_SIZE)))

.addContainerGap(114, Short.MAX_VALUE))

);

layout.setVerticalGroup(

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

.addGroup(layout.createSequentialGroup()

.addGap(20, 20, 20)

.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 31,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(41, 41, 41)

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

.addComponent(jLabel2)

.addComponent(jLabel3)

.addComponent(jLabel4))

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

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

.addComponent(txtSoles, javax.swing.GroupLayout.PREFERRED_SIZE, 36,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(txtDolares, javax.swing.GroupLayout.PREFERRED_SIZE, 39,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(txtMarcos, javax.swing.GroupLayout.PREFERRED_SIZE, 39,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 53,
Short.MAX_VALUE)

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

.addComponent(btnProcesar, javax.swing.GroupLayout.PREFERRED_SIZE, 42,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(btnLimpiar, javax.swing.GroupLayout.PREFERRED_SIZE, 42,


javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 42,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(btnimagen))

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

.addGroup(layout.createSequentialGroup()

.addGap(33, 33, 33)

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

.addGroup(layout.createSequentialGroup()

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

.addComponent(label, javax.swing.GroupLayout.PREFERRED_SIZE, 186,


javax.swing.GroupLayout.PREFERRED_SIZE)))

.addContainerGap())

);

pack();

}// </editor-fold>

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

// TODO add your handling code here:

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

// TODO add your handling code here:

try {

// Validación de campos vacíos

if (txtSoles.getText().trim().isEmpty() || txtDolares.getText().trim().isEmpty() ||
txtMarcos.getText().trim().isEmpty()) {

JOptionPane.showMessageDialog(this, "Por favor, inserte datos en todos los campos.",


"Insertar datos", JOptionPane.WARNING_MESSAGE);

return;

}
// Convertir los textos a números

double soles = Double.parseDouble(txtSoles.getText());

double dolares = Double.parseDouble(txtDolares.getText());

double marcos = Double.parseDouble(txtMarcos.getText());

// Validación de valores negativos

if (soles < 0 || dolares < 0 || marcos < 0) {

JOptionPane.showMessageDialog(this, "Error: Inserte datos positivos.", "Error",


JOptionPane.ERROR_MESSAGE);

return;

// Crear una instancia de Casa y establecer los valores

Casa objC = new Casa();

objC.soles = soles;

objC.dolares = dolares;

objC.marcos = marcos;

// Calcular el monto en euros

double euros = objC.CalculaMontoEuros();

// Preparar y mostrar el resumen

DefaultListModel<String> moR = new DefaultListModel<>();

moR.addElement("** RESUMEN DE CAMBIO **");

moR.addElement("_______________________");

moR.addElement("MONTO EN SOLES: " + String.format("%.2f", objC.soles));

moR.addElement("MONTO EN DOLARES: " + String.format("%.2f", objC.dolares));

moR.addElement("MONTO EN MARCOS: " + String.format("%.2f", objC.marcos));

moR.addElement("_______________________");

moR.addElement("MONTO EN TOTAL EN EUROS: " + String.format("%.2f", euros));

lstResumen.setModel(moR);
} catch (NumberFormatException e) {

// Manejo de errores si los datos no son números válidos

JOptionPane.showMessageDialog(this, "Error: Inserte valores numéricos válidos.", "Error",


JOptionPane.ERROR_MESSAGE);

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

// TODO add your handling code here:

txtSoles.setText("");

txtDolares.setText("");

txtMarcos.setText("");

txtSoles.requestFocus();

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

// TODO add your handling code here:

int r=JOptionPane.showOptionDialog(this,"estas seguro de salir...?","casa de


cambio",JOptionPane.YES_NO_OPTION,

JOptionPane.QUESTION_MESSAGE,null,null,null);

if (r==0)

System.exit(0);

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

// TODO add your handling code here:

// Ruta de la imagen (ajusta según tu sistema operativo)

// Ruta de la imagen (ajusta según tu sistema operativo)


ImageIcon imageIcon = new
ImageIcon("C:\\Users\\TuUsuario\\Downloads\\imagen03.png"); // Para Windows

// ImageIcon imageIcon = new ImageIcon("/Users/TuUsuario/Downloads/imagen.png"); //


Para macOS/Linux

// Crear un JLabel con la imagen

// Mostrar la imagen en un JOptionPane

JOptionPane.showMessageDialog(null, label, "Imagen", JOptionPane.PLAIN_MESSAGE);

/**

* @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(frmCasaCambio.class.getName()).log(java.util.logging.Level.
SEVERE, null, ex);

} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(frmCasaCambio.class.getName()).log(java.util.logging.Level.
SEVERE, null, ex);

} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(frmCasaCambio.class.getName()).log(java.util.logging.Level.
SEVERE, null, ex);

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(frmCasaCambio.class.getName()).log(java.util.logging.Level.
SEVERE, null, ex);

//</editor-fold>

/* Create and display the form */

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

public void run() {

new frmCasaCambio().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton btnLimpiar;

private javax.swing.JButton btnProcesar;

private javax.swing.JButton btnSalir;

private javax.swing.JButton btnimagen;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;


private javax.swing.JLabel jLabel4;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JLabel label;

private javax.swing.JList<String> lstResumen;

private javax.swing.JTextField txtDolares;

private javax.swing.JTextField txtMarcos;

private javax.swing.JTextField txtSoles;

// End of variables declaration

Diagrama:

2. Prueba, captura de pantalla de la ejecución

Prueba con private y protected


Prueba de vacio

Negativos
Positivos

Apretamos botón imagen

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy