0% encontró este documento útil (0 votos)
16 vistas15 páginas

Practica N°1 Pilas - LOPEZ - ORTIZ 2

Este documento presenta el código para una aplicación de pilas utilizando Java. Incluye las clases Pila, VPadrePila, VHijaPush y VHIjaListar. VPadrePila contiene el menú principal con las opciones de "PUSH", "POP" y "LISTAR". VHijaPush permite agregar elementos a la pila. VHIjaListar muestra los elementos de la pila en una tabla y permite generar un reporte o regresar al menú principal. El documento explica brevemente cada parte del código.
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
0% encontró este documento útil (0 votos)
16 vistas15 páginas

Practica N°1 Pilas - LOPEZ - ORTIZ 2

Este documento presenta el código para una aplicación de pilas utilizando Java. Incluye las clases Pila, VPadrePila, VHijaPush y VHIjaListar. VPadrePila contiene el menú principal con las opciones de "PUSH", "POP" y "LISTAR". VHijaPush permite agregar elementos a la pila. VHIjaListar muestra los elementos de la pila en una tabla y permite generar un reporte o regresar al menú principal. El documento explica brevemente cada parte del código.
Derechos de autor
© © All Rights Reserved
Nos tomamos en serio los derechos de los contenidos. Si sospechas que se trata de tu contenido, reclámalo aquí.
Formatos disponibles
Descarga como PDF, TXT o lee en línea desde Scribd
Está en la página 1/ 15

TECNOLÓGICO NACIONAL DE MÉXICO

INSTITUTO TECNOLÓGICO DE LA PIEDAD

Tecnologías de información y comunicación

Estructura y Organización de Datos

UNIDAD 2
Actividad de Pilas

Profesora: Margarita Torres Figueroa


Alumno (a): Juan Luis Lopez Ortiz

LA PIEDAD, MICH. 19 de octubre de 2022


Tenemos que generar el codigo de la clase Articulo
Despues debemos de crear la clase pila en la cual tendremos que colocar los metodos tomando en
cuenta que los metodos que debmemos de agregar son los siguientes:

Pila…

pilaLlena…

pilaVacia…

al igual que un metodo de tipo String que regresara un String del tipo cadena…

Pop….

de la siguiente manera:
Generaremos el codigo de la clase Vpadre Pilas

private Pila p=new Pila(); /**

* Creates new form VPadrePila

*/
public VPadrePila() {

initComponents();

this.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() {

jDesktopPane1 = new javax.swing.JDesktopPane(); jMenuBar1 = new


javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();

jMenu3 = new javax.swing.JMenu();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jDesktopPane1.setBackground(new java.awt.Color(0, 0, 153));

javax.swing.GroupLayout jDesktopPane1Layout = new


javax.swing.GroupLayout(jDesktopPane1);

jDesktopPane1.setLayout(jDesktopPane1Layout);
jDesktopPane1Layout.setHorizontalGroup(

jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)

.addGap(0, 471, Short.MAX_VALUE) );

jDesktopPane1Layout.setVerticalGroup(
jDesktopPane1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LE
ADING)

public class VPadrePila extends javax.swing.JFrame {

.addGap(0, 385, Short.MAX_VALUE) );

jMenu1.setBackground(new java.awt.Color(102, 255, 204)); jMenu1.setText("PUSH");


jMenu1.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu1MouseClicked(evt);

} });

jMenuBar1.add(jMenu1);

jMenu2.setText("POP ");
jMenu2.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu2MouseClicked(evt);

} });

jMenuBar1.add(jMenu2);

jMenu3.setText("LISTAR ");
jMenu3.addMouseListener(new java.awt.event.MouseAdapter() {

public void mouseClicked(java.awt.event.MouseEvent evt) { jMenu3MouseClicked(evt);

} });

jMenuBar1.add(jMenu3);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout); layout.setHorizontalGroup(

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

.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)) );

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

.addComponent(jDesktopPane1, javax.swing.GroupLayout.PREFERRED_SIZE,

layout

= new

javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(0, 0, Short.MAX_VALUE)) );

}// </editor-fold>

private void jMenu1MouseClicked(java.awt.event.MouseEvent evt) { VHijaPush


vpush=new VHijaPush(p); jDesktopPane1.add(vpush);
vpush.setVisible(true);

vpush.show(); }

private void jMenu2MouseClicked(java.awt.event.MouseEvent evt) { p.pop();

private void jMenu3MouseClicked(java.awt.event.MouseEvent evt) { VHIjaListar


vhl=new VHIjaListar(p);
jDesktopPane1.add(vhl);
vhl.setVisible(true);

vhl.show(); }

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

pack();

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

} catch (InstantiationException ex) {

g.Level.SEVERE, null, ex);


} catch (IllegalAccessException ex) {

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

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

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

} //</editor-fold>

/* Create and display the form */ java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {


new VPadrePila().setVisible(true);

} });

}
// Variables declaration - do not modify
private javax.swing.JDesktopPane jDesktopPane1; private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar jMenuBar1;
// End of variables declaration

Y nos quedara un menu como la siguiente captura:

Despues generaremos el codigo de la clase Push


Quedando el diseño de la siguiente manera:

Ahora genetraremos el codigo de VhijaListar

public class VHIjaListar extends javax.swing.JInternalFrame { private Pila p;

/**
* Creates new form VHIjaListar */

public VHIjaListar(Pila p) { initComponents();


this.p=p; jTable1.setModel(p.ImprimirTabla());

/**
* 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() {
jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable();

jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton();

jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] {

{null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null}

},
new String [] {

"Title 1", "Title 2", "Title 3", "Title 4" }

)); jScrollPane1.setViewportView(jTable1);

jButton1.setText("Reporte");
jButton1.addActionListener(new java.awt.event.ActionListener() {

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


jButton1ActionPerformed(evt);

} });

jButton2.setText("Regresar");
jButton2.addActionListener(new java.awt.event.ActionListener() {

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


jButton2ActionPerformed(evt);
} });

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

.addGap(0, 10, Short.MAX_VALUE)

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


javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(layout.createSequentialGroup() .addGap(35, 35, 35)


.addComponent(jButton1)

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

.addComponent(jButton2)

.addGap(75, 75, 75)) );

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

layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,

Short.MAX_VALUE) .addComponent(jScrollPane1,

javax.swing.GroupLayout.PREFERRED_SIZE, 159,
javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(33, 33, 33)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASEL INE)

.addComponent(jButton1)

.addComponent(jButton2)) .addGap(68, 68, 68))


);

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

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

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


this.setVisible(false);

// Variables declaration - do not modify private javax.swing.JButton jButton1;


private javax.swing.JButton jButton2;
private javax.swing.JScrollPane jScrollPane1; private javax.swing.JTable jTable1;

// End of variables declaration }

Corrida del Programa “PILAS”:


Enseguida se presionó “POP” para eliminar. Y se vuelve a presionar “LISTAR”:

También podría gustarte