O código:
<blockquote>import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class Cliente extends JFrame implements ActionListener{
JTextField tfnome = new JTextField (40);
JTextField tfcpf = new JTextField (11);
JButton btsalvar = new JButton ("Salvar");
JButton btcancelar = new JButton ("Cancelar");
public Cliente(){
setLocationRelativeTo (null);
setTitle ("Cadastro de clientes");
setSize (250, 250);
setDefaultCloseOperation (EXIT_ON_CLOSE);
JLabel lbnome = new JLabel ("Nome");
JLabel lbcpf = new JLabel ("Cpf");
setLayout (new FlowLayout());
add (tfnome);
add (tfcpf);
add (btsalvar);
add (btcancelar);
add (lbnome);
add (lbcpf);
btsalvar.addActionListener (this);
btcancelar.addActionListener (this);
}
public void actionPerformed (ActionEvent evt){
Object obj = evt.getSource();
if (obj == btcancelar)
System.exit (0);
}
public static void main (String args [])
{
new Cliente();
}
}
Não dá erro, apenas não aparece nada, ou seja, aparece a tela preta do dos, com a mensagem ‘aperte uma tecla pra continuar’, sem painel, botões, nada.