Pessoal estou dando uma estudada em JPA, e agora quero criar um jFrame para o bean que criei, quero cadastrar, listar todos os cadastrados, excluir, atualizar e tudo mais…
fiz alguns testes aqui com o netbeans, mas fiquei em dúvida com o Bind…
segue a classe
@Entity
@Table(name = "cliente")
@NamedQueries({@NamedQuery(name = "Cliente.findById", query = "SELECT c FROM Cliente c WHERE c.id = :id"),
@NamedQuery(name = "Cliente.findByNomeCliente", query = "SELECT c FROM Cliente c WHERE c.nomeCliente = :nomeCliente"),
@NamedQuery(name = "Cliente.findByIdade", query = "SELECT c FROM Cliente c WHERE c.idade = :idade")})
public class Cliente implements Serializable {
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id", nullable = false)
private Integer id;
@Column(name = "nome_cliente", nullable = false)
private String nomeCliente;
@Column(name = "idade", nullable = false)
private int idade;
public Cliente() {
}
public Cliente(Integer id) {
this.id = id;
}
public Cliente(Integer id, String nomeCliente, int idade) {
this.id = id;
this.nomeCliente = nomeCliente;
this.idade = idade;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
Integer oldId = this.id;
this.id = id;
changeSupport.firePropertyChange("id", oldId, id);
}
public String getNomeCliente() {
return nomeCliente;
}
public void setNomeCliente(String nomeCliente) {
String oldNomeCliente = this.nomeCliente;
this.nomeCliente = nomeCliente;
changeSupport.firePropertyChange("nomeCliente", oldNomeCliente, nomeCliente);
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
int oldIdade = this.idade;
this.idade = idade;
changeSupport.firePropertyChange("idade", oldIdade, idade);
}
@Override
public int hashCode() {
int hash = 0;
hash += (id != null ? id.hashCode() : 0);
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Cliente)) {
return false;
}
Cliente other = (Cliente) object;
if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
return false;
}
return true;
}
@Override
public String toString() {
return "testaeventos.beans.Cliente[id=" + id + "]";
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}
}
Bom vamos as dúvidas.
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
public void addPropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}
Aqui ele cria um campo @Transient que n vai ser salvo no banco “é claro”, e adiciona dois metodos, ate achei algum material, mas estava mei complexo.
Porque ele cria esses dois métodos?
Onde eu irei chamar esses metodos no meu frame?
Como eu interligo o meu jTextfield com o objeto selecionado em uma jTable?
Alguem tem algum exemplo simples, com uma classe e um jFrame?
Ate achei um material bom,
http://www.dsc.ufcg.edu.br/~jacques/cursos/map/html/comp/jb.htm
mas mesmo lendo o mesmo n entendi a ligação entre os metodos criados e os componentes do jFrame.
Desde já obrigado.