Galera, não estou conseguindo compilar este código porque não deixa instanciar um objeto com tipo GroupLayou.
import java.sql.<em>;
import java.awt.</em>;
import java.awt.event.<em>;
import javax.swing.</em>;
public class Cadastro extends JFrame implements ActionListener {
JLabel jLabel1, jLabel2, jLabel3, jLabel4;
JPanel jPanel1, jPanel2, jPanel3;
JButton jButton1, jButton2, jButton3, jButton4, jButton5;
static JTextField tfCodigo, tfProduto, tfMarca, tfCor;
JPanel painel=new JPanel();
private ResultSet rs;
private Statement MeuState;
public static void main(String args[]) {
JFrame cad=new Cadastro();
cad.show();
WindowListener x = new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
};
cad.addWindowListener(x);
}
public Cadastro() {
setTitle(“CADASTRAMENTO DE PRODUTOS”);
setSize(500,300);
setLocation(150,150);
setResizable(false);
jPanel1 = new JPanel();
jLabel1 = new JLabel();
jLabel2 = new JLabel();
jLabel3 = new JLabel();
jLabel4 = new JLabel();
jPanel2 = new JPanel();
tfCodigo = new JTextField();
tfProduto = new JTextField();
tfMarca = new JTextField();
tfCor = new JTextField();
jPanel3 = new JPanel();
jButton1 = new JButton();
jButton2 = new JButton();
jButton3 = new JButton();
jButton4 = new JButton();
jButton5 = new JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new GridLayout(5, 0, 20, 20));
jLabel1.setText(“Código de Barras”);
jPanel1.add(jLabel1);
jLabel2.setText(“Produto”);
jPanel1.add(jLabel2);
jLabel3.setText(“Marca”);
jPanel1.add(jLabel3);
jLabel4.setText(“Cor”);
jPanel1.add(jLabel4);
jPanel2.setLayout(new java.awt.GridLayout(5, 0, 40, 10));
jPanel2.add(tfCodigo);
jPanel2.add(tfProduto);
jPanel2.add(tfMarca);
jPanel2.add(tfCor);
jButton1.setText(“Salvar”);
jPanel3.add(jButton1);
jButton2.setText(“Cancelar”);
jPanel3.add(jButton2);
jButton3.setText(“Alterar”);
jPanel3.add(jButton3);
jButton4.setText(“Limpar”);
jPanel3.add(jButton4);
jButton5.setText(“Pesquisar”);
jPanel3.add(jButton5);
tfCodigo.addActionListener(this);
tfProduto.addActionListener(this);
tfMarca.addActionListener(this);
tfCor.addActionListener(this);
jButton4.addActionListener(this);
jButton3.addActionListener(this);
jButton2.addActionListener(this);
jButton1.addActionListener(this);
jButton5.addActionListener(this);
javax.swing.GroupLayout layout = new
javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE,
254, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(115, 115, 115))
.addComponent(jPanel3,
javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
239, Short.MAX_VALUE)
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE,
239, Short.MAX_VALUE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
String url = “jdbc:postgresql://localhost:5432/postgres”;
String username = “postgres”;
String senha = “marcelo”;
try {
Class.forName( “org.postgresql.Driver” );
Connection connection = DriverManager.getConnection(url,
username, senha);
MeuState =
connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = MeuState.executeQuery(“SELECT * FROM produtos”);
rs.first();
atualizaCampos();
} catch(ClassNotFoundException ex){
JOptionPane.showMessageDialog(null, “Driver do banco não foilocalizado”," Mensagem de informaçao",JOptionPane.INFORMATION_MESSAGE);
} catch(SQLException ex){
JOptionPane.showMessageDialog(null, “Problema na conexão com o banco de dados”,"",JOptionPane.INFORMATION_MESSAGE);
}
}
public void actionPerformed(ActionEvent e){
if (e.getSource()==jButton4){
limpaCampos();
return;
}
if (e.getSource()==jButton1)/* insere dados*/
{
try{
String SQL = “INSERT INTO produtos (codbarras, produto,marca, cor) VALUES (” + tfCodigo.getText() + " , ’ " + tfProduto.getText() +
" ’ , ’ " + tfMarca.getText() + " ’ , ’ " + tfCor.getText() + " ‘)";
MeuState.executeUpdate(SQL);
JOptionPane.showMessageDialog(null,“Gravação realizada com sucesso”," “, JOptionPane.INFORMATION_MESSAGE);
limpaCampos();
} catch(SQLException ex){
if (ex.getMessage().equals(“General error”))
JOptionPane.showMessageDialog(null, “Produto já cadastrado”,” ", JOptionPane.INFORMATION_MESSAGE);
}
}
if (e.getSource()==jButton3)/* altera dados*/
{
try{
String SQL = "UPDATE produtos SET produto=’ " +
tfProduto.getText()+"’,"+
“marca=’ " + tfMarca.getText()+”’,"+
“cor=’ " + tfCor.getText()+” ’ "+
“WHERE codbarras = " + tfCodigo.getText()+” “;
int r = MeuState.executeUpdate(SQL);
if (r==1)
JOptionPane.showMessageDialog(null, “Atualização realizada com sucesso”,” “, JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null,“Esse produto ainda não está cadastrado\n Pressione NOVO”,” “, JOptionPane.INFORMATION_MESSAGE);
} catch(SQLException ex){}
}
if (e.getSource()==jButton2)/* excluir dados */
{
try{
String SQL = “SELECT codbarras, produto FROM produtos WHERE codbarras = " + tfCodigo.getText()+””;
rs = MeuState.executeQuery(SQL);
String nome = “”;
try{
rs.next();
nome = “Deletar o produto: " + rs.getString(“produto”);
}
catch(SQLException ex1){
JOptionPane.showMessageDialog(null, “Produto não cadastrado!”,” “, JOptionPane.INFORMATION_MESSAGE);
}
int n = JOptionPane.showConfirmDialog(null, nome,” ",
JOptionPane.YES_NO_OPTION);
if (n == JOptionPane.YES_OPTION){
SQL = "DELETE FROM produtos WHERE codbarras = " +
tfCodigo.getText() + " “;
int r = MeuState.executeUpdate(SQL);
if (r==1)
JOptionPane.showMessageDialog(null, “Exclusão realizada com sucesso”,” “, JOptionPane.INFORMATION_MESSAGE);
else
JOptionPane.showMessageDialog(null, “Não foi possível excluir o produto”,” ", JOptionPane.INFORMATION_MESSAGE);
}
else
return;
limpaCampos();
}
catch(SQLException ex) {
limpaCampos();
}
}
if (e.getSource()== jButton5 || e.getSource()== tfCodigo)/* fazer
pesquisa*/
{
try {
String SQL = “SELECT * FROM produtos WHERE codbarras = " +
tfCodigo.getText() + " “;
rs = MeuState.executeQuery(SQL);
rs.next();
tfCodigo.setText(rs.getString(“codbarras”));
tfProduto.setText(rs.getString(“produto”));
tfMarca.setText(rs.getString(“marca”));
tfCor.setText(rs.getString(“cor”));
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, “Não foi possível localizar o produto”,” “, JOptionPane.INFORMATION_MESSAGE);
return;
}
}
}
public static void limpaCampos(){
tfCodigo.setText(””);
tfProduto.setText("");
tfMarca.setText("");
tfCor.setText("");
}
public void atualizaCampos(){
try{
tfCodigo.setText(rs.getString(“codbarras”));
tfProduto.setText(rs.getString(“produto”));
tfMarca.setText(rs.getString(“marca”));
tfCor.setText(rs.getString(“cor”));
}
catch(SQLException ex){}
};
}