Abrindo JFrame por JButton

2 respostas Resolvido
programação
N
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( 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

2 Respostas

Bruno_Lippert
Solucao aceita

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));
N

Me ajudou muito!Obrigado

Criado 11 de fevereiro de 2018
Ultima resposta 12 de fev. de 2018
Respostas 2
Participantes 2