Ir ao conteúdo
  • Cadastre-se

Erro na Criação de JFrame


JorgeReidinaldo

Posts recomendados

RESOLVIDO

Galera é o seguinte sou iniciante em java porém ao compilar o meu codigo apareceu a seguinte mensagem do compilador

Exception in thread "main" java.lang.NullPointerException

at javax.swing.ImageIcon.<init>(ImageIcon.java:155)

at frame.LabelFrame.<init>(LabelFrame.java:32)

at frame.LabelTest.main(LabelTest.java:7)



package frame;

import java.awt.FlowLayout;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

public class LabelFrame extends JFrame{
private JLabel label1;
private JLabel label2;
private JLabel label3;

// metodo construtor
public LabelFrame()
{
super("Teste JLabel");
setLayout(new FlowLayout());

// Construtor JLabel com argumento String
label1 = new JLabel("Label with text");
label1.setToolTipText("This is Label");
add(label1);// Adiciona o Label ao JFrame

//Construtor JLabel com String, Icon e argumentos de alinhamento
Icon bug = new ImageIcon(getClass().getResource("key.png"));
label2 =new JLabel("Label with text and icon",bug,SwingConstants.LEFT);
label2.setToolTipText("This is label2");
add(label2);
label3 = new JLabel();
label3.setText("Label with icon and text at buttom");
label3.setIcon(bug);
label3.setHorizontalTextPosition(SwingConstants.CENTER);
label3.setVerticalTextPosition(SwingConstants.BOTTOM);
label3.setToolTipText("This is Label3");
add(label3);






}


}




package frame;

import javax.swing.JFrame;

public class LabelTest {
public static void main(String[] args){
LabelFrame labelFrame = new LabelFrame();
labelFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
labelFrame.setSize(275, 180);
labelFrame.setVisible(true);


}

}

Link para o comentário
Compartilhar em outros sites

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!