GroupLayout cannot be resolved?

6 respostas
E

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){}

};

}

6 Respostas

fabiofalci

Ta usando java 6?

Marky.Vasconcelos

Você gerou isso pelo NetBeans e agora ta tentando compilar no DOS ou no Eclipse certo??
Tem um arquivo chamado swing-layout que o NetBeans gera não lembro onde consegui mas vou tentar upar e posto o link se você quiser

Se esse for seu problema é claro

fabiofalci

Assim, esse layout manager, GroupLayout.
Se estiver usando java 5, tem que usar o swing-layout*.jar que tem dentro do netbeans.

Se estiver usando o java 6, já tem na api do java.

Mas tem diferenças no pacote.
se java 6, então o teu import deve ser javax.swing.GroupLayout
se java 5, então o teu import deve ser org.jdesktop.layout.GroupLayout

No teu caso, não vejo nenhum import org.jdesktop…, apenas javax.swing.*
Verifica se está apontando para o java6!

Marky.Vasconcelos

Descupa não sabia que foi adicionado pro Java 6 o swing-layout

Obs: efcjunior quando postar códigos, poste entre as tags e

H

Estava com a mesma dúvida que a sua, efcjunior. Seguindo a dica do pessoal, resolvi modificar seu código fonte. Estou te mandando ele funcionando, agora usando a biblioteca swing-layout-1.0 e compatível com outras versões do java.

Abraço!
Helder


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.setVisible(true);
	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);
	org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
	getContentPane().setLayout(layout);
	layout.setHorizontalGroup(

			layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
			.add(layout.createSequentialGroup()
					.addContainerGap()
					.add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
							org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
							org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)

							.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
							.add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
									254, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
									.add(115, 115, 115))
									.add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3,
											org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 467, Short.MAX_VALUE)
	);
	layout.setVerticalGroup(

			layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
			.add(layout.createSequentialGroup()
					.addContainerGap()

					.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
							.add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
									239, Short.MAX_VALUE)
									.add(jPanel2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
											239, Short.MAX_VALUE))

											.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
											.add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
													org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
													org.jdesktop.layout.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){}

};

}
N

oi galera mais tbm estou com o mesmo problema , cannot find symbol class GroupLayout , esta dando pau , a versão que estou do java é jdk-1_5_0_06-windows-i586-p.exe , já tentei de tudo ate agora na tô case achando que essa class não existe rsrsrsrsrsr , bom se alguem souber de alguma solição … grato a todos :?:

Criado 28 de junho de 2007
Ultima resposta 10 de nov. de 2008
Respostas 6
Participantes 5