Estou tentando criar o form abaixo. Mas só aparece a janela, não aparece o botão nem o campo para digitar o texto.
package exemplos;
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.*;
import java.awt.event.*;
public class Form_layout3 extends JFrame {
private JTextField recebe_texto;
private JButton botao;
private JPanel painel1;
private JPanel painel2;
private JPanel painel3;
private JLabel texto;
private void initComponents(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600,600);
setLocation(100,100);
setTitle("Minha janela");
texto = new JLabel();
texto.setText("Texto Exemplo");
texto.setVisible(true);
recebe_texto = new JTextField();
recebe_texto.setText("Digite seu nome");
recebe_texto.setVisible(true);
botao = new JButton();
botao.setText("Botão");
botao.setMnemonic('E');
botao.setVisible(true);
botao.addActionListener(new BotaoListener());
painel1 = new JPanel();
painel1.setVisible(true);
painel1.setBackground(Color.BLUE);
painel2 = new JPanel();
painel2.setVisible(true);
painel2.setBackground(Color.YELLOW);
painel3 = new JPanel();
painel3.setVisible(true);
painel3.setBackground(Color.RED);
painel1.add(texto);
painel2.add(recebe_texto);
painel3.add(botao);
getContentPane().add(BorderLayout.NORTH, painel1);
getContentPane().add(BorderLayout.CENTER, painel2);
getContentPane().add(BorderLayout.SOUTH, painel3);
setLocationRelativeTo(null); // centralizar
setVisible(true);
}
public static void main(String[] args) {
Form_layout3 janela = new Form_layout3();
janela.setVisible(true);
janela.pack();
}
class BotaoListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null,"voce digitou: " + recebe_texto.getText() ,"Aviso",JOptionPane.INFORMATION_MESSAGE);
}
}
}