You are on page 1of 13

package examfinal;

import javax.swing.JOptionPane;

import javax.swing.table.DefaultTableModel;

/**

* @author USER

*/

public class ventana extends javax.swing.JFrame {

DefaultTableModel Aplicacion ;

/**

* Creates new form ventana

*/

public ventana() {

initComponents();

Aplicacion=new DefaultTableModel();

Aplicacion.addColumn("Codigo");

Aplicacion.addColumn("Nombre");
Aplicacion.addColumn("Creditos");

Aplicacion.addColumn("Ciclo");

this.tabla.setModel(Aplicacion);

/**

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

txtcodigo = new javax.swing.JTextField();

jLabel2 = new javax.swing.JLabel();

txtnombre = new javax.swing.JTextField();

jLabel3 = new javax.swing.JLabel();

txtcredito = new javax.swing.JTextField();

jLabel4 = new javax.swing.JLabel();

txtciclo = new javax.swing.JTextField();

jScrollPane1 = new javax.swing.JScrollPane();

tabla = new javax.swing.JTable();

btnregistrar = new javax.swing.JButton();

btneliminar = new javax.swing.JButton();

btnmodificar = new javax.swing.JButton();

jLabel5 = new javax.swing.JLabel();

jLabel6 = new javax.swing.JLabel();


jLabel7 = new javax.swing.JLabel();

txtfila = new javax.swing.JTextField();

txtcolumna = new javax.swing.JTextField();

txtremplazar = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("Código");

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

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

txtcodigoActionPerformed(evt);

});

jLabel2.setText("Nombre");

jLabel3.setText("N.Creditos");

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

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

txtcreditoActionPerformed(evt);

});

jLabel4.setText("Ciclo");

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

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

txtcicloActionPerformed(evt);

}
});

tabla.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

},

new String [] {

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

));

jScrollPane1.setViewportView(tabla);

btnregistrar.setText("Registrar");

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

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

btnregistrarActionPerformed(evt);

});

btneliminar.setText("Eliminar");

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

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

btneliminarActionPerformed(evt);

});

btnmodificar.setText("Modificar");

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

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

btnmodificarActionPerformed(evt);

}
});

jLabel5.setText("FILA");

jLabel6.setText("COLUMNA");

jLabel7.setText("REMPLAZAR");

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

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

txtfilaActionPerformed(evt);

});

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

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

txtcolumnaActionPerformed(evt);

});

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

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

txtremplazarActionPerformed(evt);

});

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

.addComponent(btneliminar)

.addGap(53, 53, 53)

.addComponent(btnmodificar))

.addGroup(layout.createSequentialGroup()

.addGap(14, 14, 14)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.T
RAILING)

.addGroup(layout.createSequentialGroup()

.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 61,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNREL
ATED)

.addComponent(txtnombre, javax.swing.GroupLayout.PREFERRED_SIZE,
71, javax.swing.GroupLayout.PREFERRED_SIZE))

.addGroup(layout.createSequentialGroup()

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


javax.swing.GroupLayout.PREFERRED_SIZE)

.addGap(18, 18, 18)

.addComponent(txtcodigo, javax.swing.GroupLayout.PREFERRED_SIZE,
71, javax.swing.GroupLayout.PREFERRED_SIZE)))

.addGap(30, 30, 30)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.T
RAILING)

.addComponent(jLabel6)

.addComponent(jLabel7)

.addComponent(jLabel5)))

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TR
AILING)
.addComponent(btnregistrar)

.addGroup(layout.createSequentialGroup()

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen
t.LEADING)

.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 61,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 37,


javax.swing.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELA
TED)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignmen
t.LEADING)

.addComponent(txtciclo, javax.swing.GroupLayout.PREFERRED_SIZE, 71,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(txtcredito, javax.swing.GroupLayout.PREFERRED_SIZE,
71, javax.swing.GroupLayout.PREFERRED_SIZE)))))

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

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADI
NG)

.addComponent(txtfila, javax.swing.GroupLayout.PREFERRED_SIZE, 71,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(txtcolumna, javax.swing.GroupLayout.PREFERRED_SIZE, 71,


javax.swing.GroupLayout.PREFERRED_SIZE)

.addComponent(txtremplazar, javax.swing.GroupLayout.PREFERRED_SIZE, 71,


javax.swing.GroupLayout.PREFERRED_SIZE))

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

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


javax.swing.GroupLayout.PREFERRED_SIZE)))

.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))

);

layout.setVerticalGroup(

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

.addGroup(layout.createSequentialGroup()

.addContainerGap(25, Short.MAX_VALUE)

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

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)

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

.addComponent(jLabel1)

.addComponent(jLabel5)

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

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)

.addComponent(jLabel2)

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

.addComponent(jLabel6)

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

.addGap(26, 26, 26)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)

.addComponent(jLabel3)

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

.addComponent(jLabel7)

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

.addGap(18, 18, 18)

.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASE
LINE)

.addComponent(jLabel4)

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

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


javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(16, 16, 16)

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

.addComponent(btnmodificar)

.addComponent(btneliminar)

.addComponent(btnregistrar))

.addContainerGap(31, Short.MAX_VALUE))

);

pack();

}// </editor-fold>

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

// TODO add your handling code here:

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

// TODO add your handling code here:

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

// TODO add your handling code here:

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

// TODO add your handling code here:

String []info=new String[3];

info[0]=txtcodigo.getText();

info[1]=txtnombre.getText();

info[2]=txtcredito.getText();

info[3]=txtciclo.getText();
Aplicacion.addRow(info);

txtcodigo.setText("");

txtnombre.setText("");

txtcredito.setText("");

txtciclo.setText("");

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

// TODO add your handling code here:

int fila=tabla.getSelectedRow();

if (fila>=0){

Aplicacion.removeRow(fila);

}else{

JOptionPane.showMessageDialog(null,"Seleccionar Fila");

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

// TODO add your handling code here:

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

// TODO add your handling code here:

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


// TODO add your handling code here:

int fila=Integer.parseInt(txtfila.getText());

int columna=Integer.parseInt(txtcolumna.getText());

Aplicacion.setValueAt(txtremplazar.getText(),fila,columna);

private void txtremplazarActionPerformed(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(ventana.class.getName()).log(java.util.logging.Level.SEVERE,
null, ex);
} catch (InstantiationException ex) {

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

} catch (IllegalAccessException ex) {

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

} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(ventana.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 ventana().setVisible(true);

});

// Variables declaration - do not modify

private javax.swing.JButton btneliminar;

private javax.swing.JButton btnmodificar;

private javax.swing.JButton btnregistrar;

private javax.swing.JLabel jLabel1;

private javax.swing.JLabel jLabel2;

private javax.swing.JLabel jLabel3;

private javax.swing.JLabel jLabel4;

private javax.swing.JLabel jLabel5;

private javax.swing.JLabel jLabel6;


private javax.swing.JLabel jLabel7;

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JTable tabla;

private javax.swing.JTextField txtciclo;

private javax.swing.JTextField txtcodigo;

private javax.swing.JTextField txtcolumna;

private javax.swing.JTextField txtcredito;

private javax.swing.JTextField txtfila;

private javax.swing.JTextField txtnombre;

private javax.swing.JTextField txtremplazar;

// End of variables declaration

You might also like