Alguns dias atras o Caximbs perguntou algo sobre isso.
Como o banco de dados teve um problema, estou repostando os fontes:
package frameobject;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
/**
*
* @author Luiz Augusto Prado
*/
public class FrameObject
{
public void openFrame(Object classname) throws ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException
{
Class<?> c = Class.forName(classname.getClass().getName() + "JFrame");
Object o = (Object) c.newInstance();
Method m1 = c.getDeclaredMethod("abrir", new Class[]{ boolean.class });
//c.getDeclaredField("teste").
Method m2 = c.getDeclaredMethod("setData", new Class[]{ Object.class });
m1.invoke(o, true);
m2.invoke(o, classname);
}
public FrameObject()
{
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
try
{
// invento qualquer classe aqui
exemplo e = new exemplo();
openFrame(e);
}
catch (ClassNotFoundException ex)
{
Logger.getLogger(FrameObject.class.getName()).log(Level.SEVERE, null, ex);
}
catch (NoSuchMethodException ex)
{
Logger.getLogger(FrameObject.class.getName()).log(Level.SEVERE, null, ex);
}
catch (InstantiationException ex)
{
Logger.getLogger(FrameObject.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IllegalAccessException ex)
{
Logger.getLogger(FrameObject.class.getName()).log(Level.SEVERE, null, ex);
}
catch (InvocationTargetException ex)
{
Logger.getLogger(FrameObject.class.getName()).log(Level.SEVERE, null, ex);
}
catch (IllegalArgumentException ex)
{
Logger.getLogger(FrameObject.class.getName()).log(Level.SEVERE, null, ex);
}
catch (SecurityException ex)
{
Logger.getLogger(FrameObject.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
FrameObject f = new FrameObject();
}
}
package frameobject;
/**
*
* @author Luiz Augusto Prado
*/
public class exemplo
{
public String nome;
public exemplo()
{
this.nome = "To_Caximbs ";
}
}
package frameobject;
/**
*
* @author Luiz Augusto prado
*/
public class exemploJFrame extends javax.swing.JFrame
{
public void setData( Object a1)
{
this.txt_nome.setText(((exemplo)a1).nome);
}
public void abrir( boolean v)
{
setVisible(true);
}
/** Creates new form exemploJFrame */
public exemploJFrame()
{
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() {
txt_nome = new javax.swing.JTextField();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
txt_nome.setText("jTextField1");
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(txt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, 245, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(62, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(txt_nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(91, Short.MAX_VALUE))
);
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(exemploJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (InstantiationException ex)
{
java.util.logging.Logger.getLogger(exemploJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (IllegalAccessException ex)
{
java.util.logging.Logger.getLogger(exemploJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
catch (javax.swing.UnsupportedLookAndFeelException ex)
{
java.util.logging.Logger.getLogger(exemploJFrame.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 exemploJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField txt_nome;
// End of variables declaration
}