Dprne3 U1 A2
Dprne3 U1 A2
UNIDAD: 2
ACTIVIDAD 3: CONTENEDORES Y
CONTROLADORES
Introducción …………………………………………………………………………………………………………………………………3
Capturas de pantalla
…………………………………………………………………………………………………………………….16
Conclusión ……………………………………………………………………………………………………………………………………
17
Bibliografía …………………………………………………………………………………………………………………………………..16
Introducción
Código
Clase principal
package po2;
package po2;
public menu() {
initComponents();
}
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jMenu1.setText("VENTAS");
jMenuItem_ventas.setText("ventas");
jMenuItem_ventas.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem_ventasActionPerformed(evt);
}
});
jMenu1.add(jMenuItem_ventas);
jMenuBar1.add(jMenu1);
jMenu2.setText("INVENTARIO");
jMenuBar1.add(jMenu2);
jMenu3.setText("PERSONAL");
jMenuBar1.add(jMenu3);
jMenu4.setText("SALIR");
jMenuBar1.add(jMenu4);
setJMenuBar(jMenuBar1);
pack();
}// </editor-fold>
/**
* @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(menu.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(menu.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(menu.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(menu.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
}
//</editor-fold>
package po2;
import java.util.ArrayList;
/**
* 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.
*/
//componenete hechos por el GUI
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("VENTAS");
jLabel2.setText("Articulo");
jLabel3.setText("Precio");
jLabel4.setText("Marca");
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel4, javax.swing.GroupLayout.Alignment.LEADING))
.addGap(26, 26, 26))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)
.addGap(13, 13, 13)
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jLabel4)
.addContainerGap(23, Short.MAX_VALUE))
);
txtMarca.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtMarcaActionPerformed(evt);
}
});
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(txtArticulo)
.addComponent(txtPrecio)
.addComponent(txtMarca, javax.swing.GroupLayout.DEFAULT_SIZE, 111,
Short.MAX_VALUE))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(6, 6, 6)
.addComponent(txtArticulo, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtPrecio, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtMarca, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(17, Short.MAX_VALUE))
);
tabla_ventas.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"Articulo", "Precio", "Marca"
}
));
jScrollPane1.setViewportView(tabla_ventas);
Btnguardar.setText("Guardar");
Btnguardar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BtnguardarActionPerformed(evt);
}
});
pack();
}// </editor-fold>
{
String matris[][]=new String[lista.size()][3];
for (int i=0; i<lista.size(); i++){
matris[i][0]= lista.get(i).getArticulo();
matris[i][1]= lista.get(i).getPrecio();
matris[i][2]= lista.get(i).getMarca();
}
//para que llene la tabla deacuerdo a la matris
tabla_ventas.setModel(new javax.swing.table.DefaultTableModel(
matris,
new String [] {
"Articulo", "Precio", "Marca"
}
));
}
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(ventas.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(ventas.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(ventas.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(ventas.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
}
//</editor-fold>
Captura de pantalla
El programa se ejecuta con Jframe el cual sirve de contenedor que a la vez muestra el menú con
un submenú de venta
Cuando se selecciona el submenú ventas se abre otro jframe que sirve de contenedor para
algunos componentes como se muestra a continuación
Conclusión
La presente actividad pudimos analizar sobre los contenedores y controladores que existen en java
y a la vez poder poner nuestros conocimientos en práctica sobre estos temas estudiados que son
indispensables para el momento de estar desarrollando un programa ya que facilitan el trabajo del
desarrollador gracias a la interfaces graficas que son más amigables para estar desarrollando
código ya que ella va escribiendo códigos según vayamos agregando componentes a la interface.
Bibliografía
Ceballos, F.. (septiembre 2015). interface grafica y aplicaciones para internet. febrero 25, 2017, de
RA-MA. S.A Sitio web: https://books.google.com.mx/books?hl=es&lr=&id=A7E-
DwAAQBAJ&oi=fnd&pg=PT6&dq=contenedores+java&ots=gDlvsWFE2a&sig=Ew0q8yKeUxJgFuYU9
olJ8NkqMm0#v=onepage&q&f=true
Henao, C.. (octubre 8, 2013). Contenedores Java Swing. febrero 25, 2013, del Sitio web:
http://codejavu.blogspot.mx/2013/10/contenedores-java-swing.html