Estou precisando de uma ajuda. Não consigo chamar corretamente uma classe de formulário dentro para um JInternalFrame. Segue os códigos:
//DesktopFrame.java
public class DesktopFrame extends JFrame {
private static final long serialVersionUID = 1L;
private JDesktopPane theDesktop;
// set up GUI
public DesktopFrame()
{
super( "SysStock" );
JMenuBar bar = new JMenuBar(); // create menu bar
JMenu addMenu = new JMenu( "Add" ); // create Add menu
JMenuItem newFrame = new JMenuItem( "Internal Frame" );
addMenu.add( newFrame ); // add new frame item to Add menu
bar.add( addMenu ); // add Add menu to menu bar
setJMenuBar( bar ); // set menu bar for this application
theDesktop = new JDesktopPane(); // create desktop pane
add( theDesktop ); // add desktop pane to frame
// set up listener for newFrame menu item
newFrame.addActionListener(
new ActionListener() // anonymous inner class
{
// display new internal window
public void actionPerformed( ActionEvent event )
{
// create internal frame
JInternalFrame frame = new JInternalFrame("Frame Interno", true, true, true,true);
//JInternalFrame frame = new JInternalFrame();
/*
Formulario f = new Formulario();
f.show();
*/
Formulario panel = new Formulario(); // create new panel
setContentPane(panel);
frame.add( panel, BorderLayout.CENTER ); // add panel
frame.pack(); // set internal frame to size of contents
theDesktop.add( frame ); // attach internal frame
try {
frame.setMaximum(true);
frame.setSelected(true);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
frame.setVisible( true ); // show internal frame
} // end method actionPerformed
} // end anonymous inner class
); // end call to addActionListener
} // end constructor DesktopFrame
} // end class DesktopFrame
A classe q chama o JInternalFrame:
//DesktopTest.java
public class DesktopTest
{
public static void main( String args[] )
{
DesktopFrame desktopFrame = new DesktopFrame();
desktopFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
desktopFrame.setSize( 600, 480 ); // set frame size
desktopFrame.setVisible( true ); // display frame
} // end main
} // end class DesktopTest
O formulário chamado:
//Formulario.java
public class Formulario extends JFrame implements ActionListener{
private JLabel lblNome;
private JTextField txtNome;
private JLabel lblNascimento;
private JTextField txtNascimento;
private JLabel lblIdade;
private JTextField txtIdade;
private JButton bInserir;
private JButton bPesquisar;
private JButton bCancelar;
public Formulario(){
super("Cadastro");
this.setSize(500,150);
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
this.getContentPane().setLayout(new BorderLayout());
lblNome = new JLabel("Nome");
txtNome = new JTextField("");
lblNascimento = new JLabel("Nascimento");
txtNascimento = new JTextField("");
lblIdade = new JLabel("Idade");
txtIdade = new JTextField("");
bInserir = new JButton("Inserir");
bPesquisar = new JButton("Pesquisar");
bCancelar = new JButton("Cancelar");
bInserir.addActionListener(this);
bPesquisar.addActionListener(this);
bCancelar.addActionListener(this);
JPanel form = new JPanel(new GridLayout(3,2));
form.add(lblNome);
form.add(txtNome);
form.add(lblNascimento);
form.add(txtNascimento);
form.add(lblIdade);
form.add(txtIdade);
JPanel botoes = new JPanel(new FlowLayout());
botoes.add(bInserir);
botoes.add(bPesquisar);
botoes.add(bCancelar);
//QuadroNegro qn = new QuadroNegro();
this.getContentPane().add(form,BorderLayout.NORTH);
this.getContentPane().add(botoes,BorderLayout.CENTER);
//this.getContentPane().add(qn,BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand().equals("Inserir")){
JOptionPane.showMessageDialog(this,"bla");//implementa a ação do botão inserir
}else if(e.getActionCommand().equals("Pesquisar")){
JOptionPane.showMessageDialog(this,"ble");
txtNome.setText("Eduardo");
txtIdade.setText("27");
txtNascimento.setText("02/02/1977");
}else{
JOptionPane.showMessageDialog(this,"bli");
}
}
}
Quando ele abre o JInternalFrame, aparece só um quadrado branco. Alguém sabe pq???