PRIMEIRO FORM:
package projeto;
import java.awt.Font;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
public Formulario() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
lblProduto = new javax.swing.JLabel();
txtProduto = new javax.swing.JTextField();
btnPesquisar = new javax.swing.JButton();
btnLimpar = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jScrollPane2 = new javax.swing.JScrollPane();
jListHistorico = new javax.swing.JList();
lblHist = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Projeto Buscapé");
lblProduto.setText("Digite o Produto:");
btnPesquisar.setText("Pesquisar");
btnPesquisar.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
btnPesquisar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnPesquisarActionPerformed(evt);
}
});
btnLimpar.setText("Limpar");
btnLimpar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnLimparActionPerformed(evt);
}
});
jList1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jList1MouseClicked(evt);
}
});
jList1.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
jList1ValueChanged(evt);
}
});
jScrollPane1.setViewportView(jList1);
jListHistorico.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jListHistoricoMouseClicked(evt);
}
});
jListHistorico.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
jListHistoricoValueChanged(evt);
}
});
jScrollPane2.setViewportView(jListHistorico);
lblHist.setText("Histórico");
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(lblProduto)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(txtProduto, javax.swing.GroupLayout.PREFERRED_SIZE, 358, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(25, 25, 25)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(btnPesquisar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btnLimpar))
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addComponent(lblHist)
.addGap(53, 53, 53)))))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblProduto)
.addComponent(txtProduto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(29, 29, 29)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btnPesquisar)
.addComponent(btnLimpar))
.addGap(18, 18, 18)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(lblHist)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 335, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnPesquisarActionPerformed(java.awt.event.ActionEvent evt) {
if(txtProduto.getText().equals("")){
JOptionPane.showMessageDialog(null,“Erro! Digite algo!”);
}
else{
DefaultListModel listaNova = new DefaultListModel();
listaNova.clear();
//Obj p1
Produto p1 = new Produto();
p1.setNomeproduto("Iphone 3G");
p1.setPreco("R$900,00");
p1.setDescricao("O iPhone 3GS da Apple vem com sistema operacional iOS 4 e tem como destaques as funções de multitarefas, pastas e iBooks");
listaNova.addElement(p1.getNomeproduto());
jList1.setModel(listaNova);
}
}
private void btnLimparActionPerformed(java.awt.event.ActionEvent evt) {
//Limpar lista
DefaultListModel listaNova = new DefaultListModel();
listaNova.clear();
jList1.setModel(listaNova);
//Limpar txt
txtProduto.setText(null);
}
//Ao der dois cliques o jlist vai abrir o outro form
private void jList1MouseClicked(java.awt.event.MouseEvent evt) {
FormularioProduto telaproduto = new FormularioProduto();
telaproduto.setVisible(true);
DefaultListModel listahistorico = new DefaultListModel();
listahistorico.addElement("Iphone 3G");
jListHistorico.setModel(listahistorico);
}
private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) {
}
private void jListHistoricoValueChanged(javax.swing.event.ListSelectionEvent evt) {
// TODO add your handling code here:
}
private void jListHistoricoMouseClicked(java.awt.event.MouseEvent evt) {
FormularioProduto telaproduto = new FormularioProduto();
telaproduto.setVisible(true);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Formulario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Formulario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Formulario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Formulario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Formulario().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnLimpar;
private javax.swing.JButton btnPesquisar;
private javax.swing.JList jList1;
private javax.swing.JList jListHistorico;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JLabel lblHist;
private javax.swing.JLabel lblProduto;
private javax.swing.JTextField txtProduto;
// End of variables declaration
}
SEGUNDO FORM:
package projeto;
/**
*
-
@author Adm
*/
public class FormularioProduto extends javax.swing.JFrame {
/**
-
Creates new form FormularioProduto
*/
public FormularioProduto() {
initComponents();
//quebra de linha do txt area
txtDesc2.setLineWrap(true);
txtDesc2.setWrapStyleWord(true);
// txtDesc2.setEditable(false);
//txtNomeprod2.setEditable(false);
//txtPreco2.setEditable(false);
}
/**
-
This method is called from within the constructor to initialize the form.
-
WARNING: Do NOT modify this code. The content of this method is always
-
regenerated by the Form Editor.
*/
@SuppressWarnings(“unchecked”)
//
private void initComponents() {
Painel2 = new javax.swing.JPanel();
lblNomeproduto2 = new javax.swing.JLabel();
txtNomeprod2 = new javax.swing.JTextField();
lblPreco = new javax.swing.JLabel();
txtPreco2 = new javax.swing.JTextField();
lblDesc2 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
txtDesc2 = new javax.swing.JTextArea();
btnVoltar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle(“Projeto Buscapé”);
lblNomeproduto2.setText(“Nome:”);
txtNomeprod2.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));
txtNomeprod2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
txtNomeprod2ActionPerformed(evt);
}
});
lblPreco.setText(“Preço:”);
txtPreco2.setText(“R$900,00”);
lblDesc2.setText(“Descrição:”);
txtDesc2.setColumns(20);
txtDesc2.setRows(5);
txtDesc2.setText(“O iPhone 3GS da Apple vem com sistema operacional iOS 4 e tem como destaques as funções de multitarefas, pastas e iBooks”);
jScrollPane1.setViewportView(txtDesc2);
btnVoltar.setText(“Voltar”);
btnVoltar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnVoltarActionPerformed(evt);
}
});
javax.swing.GroupLayout Painel2Layout = new javax.swing.GroupLayout(Painel2);
Painel2.setLayout(Painel2Layout);
Painel2Layout.setHorizontalGroup(
Painel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(Painel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(Painel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(Painel2Layout.createSequentialGroup()
.addComponent(lblNomeproduto2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtNomeprod2, javax.swing.GroupLayout.PREFERRED_SIZE, 405, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(Painel2Layout.createSequentialGroup()
.addComponent(lblPreco)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(txtPreco2, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(Painel2Layout.createSequentialGroup()
.addComponent(lblDesc2)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 339, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(70, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, Painel2Layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btnVoltar)
.addGap(24, 24, 24))
);
Painel2Layout.setVerticalGroup(
Painel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(Painel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(Painel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblNomeproduto2)
.addComponent(txtNomeprod2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(Painel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lblPreco)
.addComponent(txtPreco2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(Painel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lblDesc2)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 43, Short.MAX_VALUE)
.addComponent(btnVoltar)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Painel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(Painel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pack();
}//
private void btnVoltarActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void txtNomeprod2ActionPerformed(java.awt.event.ActionEvent evt) {
}
/**
-
@param args the command line arguments
/
public static void main(String args[]) {
/ Set the Nimbus look and feel /
//
/ If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if (“Nimbus”.equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FormularioProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FormularioProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FormularioProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FormularioProduto.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FormularioProduto().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel Painel2;
private javax.swing.JButton btnVoltar;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel lblDesc2;
private javax.swing.JLabel lblNomeproduto2;
private javax.swing.JLabel lblPreco;
private javax.swing.JTextArea txtDesc2;
private javax.swing.JTextField txtNomeprod2;
private javax.swing.JTextField txtPreco2;
// End of variables declaration