hola,tengo el siguiente codigo, que le llamo desde otra clase mediante:
new frame().setVisible(true);
yo creo que me deberia de crear una nueva ventana con una tabla en la que yo creo las
columnas y las filas y voy rellenando con filas,pero no me lo hace..alguien sabe que puede pasar??
Código PHP:
public class frame extends javax.swing.JFrame {
/** Creates new form frame */
public frame() {
initComponents();
System.out.println("cargando...");
cargarTablas();
}
/** 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() {
scroll = new javax.swing.JScrollPane();
tabla = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setAlwaysOnTop(true);
scroll.setViewportView(tabla);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(scroll, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(15, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(14, Short.MAX_VALUE)
.addComponent(scroll, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
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(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(frame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(frame.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 frame().setVisible(true);
}
});
}
public void cargarTablas(){
System.out.println("estoy cargando las tablas");
DefaultTableModel modelo = new DefaultTableModel();
{
modelo.addColumn("IP");
modelo.addColumn("Puerto");
modelo.addColumn("Numero Errores");
modelo.addColumn("Ultima fecha Reinicio");
}
tabla = new JTable(modelo);
scroll=new JScrollPane(tabla);
add(scroll,BorderLayout.CENTER);
try
{
DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
java.sql.Connection conexion = DriverManager.getConnection ("jdbc:mysql://localhost/conexion","user", "pass");
java.sql.Statement s = conexion.createStatement();
ResultSet rs = s.executeQuery ("select ip,numPuerto,eTotalCrc,fechaReinicio from errores");
Object[] fila=new Object[4];
while (rs.next())
{
fila[0]=rs.getString ("ip");
fila[1]=rs.getString ("numPuerto");
fila[2]=rs.getString("eTotalCrc");
fila[3]=rs.getString("fechaReinicio");
System.out.println("introduciendo"+fila[0]+" "+fila[1]+" "+fila[2]+" "+fila[3]);
modelo.addRow(fila);
}
conexion.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Variables declaration - do not modify
public static javax.swing.JScrollPane scroll;
public static javax.swing.JTable tabla;
// End of variables declaration
}