Alguem me ajuda com swing

2 respostas
O
eu fiz o seguinte codigo que peguei num tutorial

package biblioteca;

import java.awt.*;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.awt.event.WindowListener;
import javax.swing.*;

public class Sswing extends JFrame{

JLabel l1,l2,l3,l4;

ImageIcon icone = new ImageIcon(c:/windows/cafezinho.bmp);

Sswing(){

setTitle(Inserindo Icones);

setSize(350,120);

setLocation(50,50);

getContentPane().setBackground(new Color(220,220,220));

l1 = new JLabel(" Aprendendo a Ser Otario",JLabel.LEFT);

l1.setForeground(Color.blue);

l2 = new JLabel(icone);

l2 = new JLabel("inserir ",JLabel.RIGHT);

l3.setForeground(Color.GRAY);

l4=new JLabel(Label/Imagens,icone,JLabel.CENTER);

l4.setFont(new Font(Serif,Font.BOLD,20));

l4.setForeground(Color.BLACK);

getContentPane().setLayout(new GridLayout(4,1));

// 4 linhas e 1 coluna

getContentPane().add(l1);

getContentPane().add(l2);

getContentPane().add(l3);

getContentPane().add(l4);

}

public static void main(String[] args) {

JFrame Janela = new Sswing();

Janela.show();

WindowListener x = new WindowAdapter(){

public void windowClosing(WindowEvent e){

System.exit(0);

}

};

Janela.addWindowListener(x);

}

}

  • qdo executo ele da o seguinte erro
    Exception in thread “main” java.lang.NullPointerException
    at biblioteca.Sswing.(Sswing.java:20)
    at biblioteca.Sswing.main(Sswing.java:32)

alguem sabe oque pode ta errado ?
um abraço

2 Respostas

cassio

Vc está fazendo

label = new JLabel();

para l1, l2 e l4, mas não está fazendo para l3
Com isso, quando vc faz

getContentPane().add(l3);

dá esse erro…

Abraço!

O

opa vlw cassio resolvi aki =**

Criado 5 de setembro de 2006
Ultima resposta 5 de set. de 2006
Respostas 2
Participantes 2