Abrindo JFrame por JButton

Olá,eu consegui abrir uma janela por um JButton mas quando
eu quero adicionar um botão dentro da janela ou um ImageIcon,simplesmente não aparece nada na janela,no máximo apareceu o botão,mas ocupou a área inteira,eu estudo JAVA pelo livro online da caelum fj11 e por aulas de vídeos e mesmo assim não tive sucesso em achar uma resposta.
Aqui está meu código:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;

public class Aula extends JFrame implements ActionListener{
public Aula() {
this.setLayout(new FlowLayout(FlowLayout.LEFT));
JRadioButton Teste = new JRadioButton(“Só teste mesmo”);
JButton Goku = new JButton(“Goku Sprite”);
this.add(Teste);
this.setSize(500,400);
this.setVisible(true);
this.add(Goku);
Goku.setBounds(33,30,100,200);
Goku.addActionListener(this);

}
public void actionPerformed(ActionEvent e ) {
ImageIcon GokuImagem = new ImageIcon(getClass().getResource(“p.png”));
JRadioButton Botão = new JRadioButton(“F”);
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 400);
this.setLayout(new FlowLayout(FlowLayout.LEFT));
this.add(Botão);

}
public static void main(String[] args) {
new Aula();
Aula jr = new Aula();
jr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

}

PS:Não teve como,no ActionPerformed tive que nomear a nova JFrame,já testei os métodos da mesma sem o nome do JFrame como:
add(botão);
e até ia mas não aparecia nada

Você não esta adicionando o botão ou o ImageIcon ao JFrame correto

No Action Performed muda isso:

Por isso:
frame.add(Botão);
frame.add(new JLabel(GokuImagem));

1 curtida

Me ajudou muito!Obrigado

1 curtida