Professional Documents
Culture Documents
Paredes_Danny_T2_P2_POO
Paredes_Danny_T2_P2_POO
FECHA:
07/JULIO
TEMA:
ING:
JAVIER MONTALUISA
MATERIA:
import javax.swing.JComboBox;
/**
*
* @author Servidor
*/
public class Mascota {
private String codigo;
private String nombre;
private String categoria;
private String edad;
private String propietario;
public Mascota(String codigo, String nombre, String categoria, String edad, String
propietario) {
this.codigo = codigo;
this.nombre = nombre;
this.categoria = categoria;
this.edad = edad;
this.propietario = propietario;
}
@Override
public String toString() {
return "{" + codigo + "," + nombre + "," + categoria + "," + edad + "," + propietario
+ '}';
}
}
JFramMASCOTAS
/*
* 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 formulario;
import gestion.GestionMascotas;
import java.util.Vector;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
/**
*
* @author Servidor
*/
public class JFrmMascotas extends javax.swing.JFrame {
GestionMascotas gm = new GestionMascotas();
/**
* Creates new form JFrmMascotas
*/
public JFrmMascotas() {
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() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(" MASCOTAS "));
jLabel1.setText("CODIGO:");
jLabel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.Bev
elBorder.RAISED));
jLabel2.setText("NOMBRE:");
jLabel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.Bev
elBorder.RAISED));
jLabel3.setText("CATEGORIA");
jLabel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.Bev
elBorder.RAISED));
jLabel4.setText("EDAD");
jLabel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.Bev
elBorder.RAISED));
jLabel5.setText("PROPIETARIO");
jLabel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.Bev
elBorder.RAISED));
txtprop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtpropActionPerformed(evt);
}
});
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel1,
javax.swing.GroupLayout.PREFERRED_SIZE, 85,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtcod))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3,
javax.swing.GroupLayout.PREFERRED_SIZE, 85,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbcat, 0,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel2,
javax.swing.GroupLayout.PREFERRED_SIZE, 85,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtnom))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel4,
javax.swing.GroupLayout.PREFERRED_SIZE, 85,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbedad, 0,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(0, 103, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE,
85, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtprop)))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addComponent(txtcod, javax.swing.GroupLayout.DEFAULT_SIZE, 30,
Short.MAX_VALUE)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(12, 12, 12)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtnom, javax.swing.GroupLayout.DEFAULT_SIZE, 30,
Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addComponent(cmbcat, javax.swing.GroupLayout.DEFAULT_SIZE, 30,
Short.MAX_VALUE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(cmbedad, javax.swing.GroupLayout.DEFAULT_SIZE, 30,
Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING, false)
.addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(txtprop, javax.swing.GroupLayout.DEFAULT_SIZE, 30,
Short.MAX_VALUE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);
btngrabar.setText("GRABAR");
btngrabar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btngrabarActionPerformed(evt);
}
});
btnlistar.setText("LISTAR");
txtlistarmascotas.setColumns(20);
txtlistarmascotas.setRows(5);
jScrollPane4.setViewportView(txtlistarmascotas);
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane4)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(45, 45, 45)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(btngrabar,
javax.swing.GroupLayout.PREFERRED_SIZE, 100,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btnlistar,
javax.swing.GroupLayout.PREFERRED_SIZE, 100,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 46, Short.MAX_VALUE)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(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))
.addGroup(layout.createSequentialGroup()
.addGap(67, 67, 67)
.addComponent(btngrabar, javax.swing.GroupLayout.PREFERRED_SIZE,
40, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(40, 40, 40)
.addComponent(btnlistar, javax.swing.GroupLayout.PREFERRED_SIZE,
40, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 182,
Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
}
private void txtpropActionPerformed(java.awt.event.ActionEvent 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(JFrmMascotas.class.getName()).log(java.util.logging.L
evel.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(JFrmMascotas.class.getName()).log(java.util.logging.L
evel.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(JFrmMascotas.class.getName()).log(java.util.logging.L
evel.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(JFrmMascotas.class.getName()).log(java.util.logging.L
evel.SEVERE, null, ex);
}
//</editor-fold>
import datos.Mascota;
import java.util.Vector;
import javax.swing.JComboBox;
/**
*
* @author Servidor
*/
public class GestionMascotas {
private Vector mascotas;
public GestionMascotas(){
mascotas = new Vector();
}
public void insertarMascota(String cod, String nom, String cat, String edad, String
prop){
Mascota m = new Mascota(cod, nom, cat, edad, prop);
mascotas.addElement(m);
}
public Vector getMascotas() {
return mascotas;
}