Sie sind auf Seite 1von 5

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package prova;
import
import
import
import
import

java.sql.Connection;
java.sql.DriverManager;
java.sql.SQLException;
java.sql.Statement;
javax.swing.JOptionPane;

/**
*
* @author Marcela
*/
public class guiEquipamento extends javax.swing.JFrame {
/**
* Creates new form guiEquipamento
*/
public guiEquipamento() {
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() {
jLabel1 = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jLabel6 = new javax.swing.JLabel();
txtequipamento = new javax.swing.JTextField();
txtempresa = new javax.swing.JTextField();
txtsetor = new javax.swing.JTextField();
txtmanutencao = new javax.swing.JTextField();
txtmaterial = new javax.swing.JTextField();
btnincluir = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
jList1 = new javax.swing.JList();
jLabel7 = new javax.swing.JLabel();
jLabel1.setText("jLabel1");
jButton1.setText("jButton1");

jButton2.setText("jButton2");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel2.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
jLabel2.setText("Equipamento");
jLabel3.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
jLabel3.setText("Empresa");
jLabel4.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
jLabel4.setText("Setor");
jLabel5.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
jLabel5.setText("Manutencao");
jLabel6.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
jLabel6.setText("Material");
btnincluir.setFont(new java.awt.Font("Monospaced", 0, 14)); // NOI18N
btnincluir.setText("Incluir");
btnincluir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnincluirActionPerformed(evt);
}
});
jScrollPane1.setViewportView(jList1);
jLabel7.setFont(new java.awt.Font("Monotype Corsiva", 3, 18)); // NOI18N
jLabel7.setText("Ficha de Cadastro de Equipamentos");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentP
ane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jLabel5)
.addComponent(jLabel6)
.addComponent(jLabel4)
.addComponent(jLabel3)))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel2)))
.addGap(37, 37, 37)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.LEADING)
.addComponent(txtequipamento)
.addGroup(layout.createSequentialGroup()
.addComponent(txtempresa)
.addGap(5, 5, 5))
.addComponent(txtsetor)

.addComponent(txtmanutencao)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLa
yout.Alignment.LEADING)
.addComponent(jLabel7)
.addGroup(layout.createSequentialGroup()
.addComponent(txtmaterial, javax.swing.GroupLayo
ut.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnincluir)))
.addGap(0, 0, Short.MAX_VALUE)))
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SI
ZE, 480, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(18, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING
)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 3
3, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(txtequipamento, javax.swing.GroupLayout.PREFER
RED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRE
D_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.TRAILING)
.addComponent(jLabel3)
.addComponent(txtempresa, javax.swing.GroupLayout.PREFERRED_
SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SI
ZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.TRAILING)
.addComponent(jLabel4)
.addComponent(txtsetor, javax.swing.GroupLayout.PREFERRED_SI
ZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE
))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.TRAILING)
.addComponent(jLabel5)
.addComponent(txtmanutencao, javax.swing.GroupLayout.PREFERR
ED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED
_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELA
TED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Ali
gnment.BASELINE)
.addComponent(jLabel6)

.addComponent(txtmaterial, javax.swing.GroupLayout.PREFERRED
_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_S
IZE)
.addComponent(btnincluir))
.addGap(14, 14, 14)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SI
ZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(48, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void btnincluirActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String url = "jdbc:postgresql://localhost:5432/dbaula1";
try{
Class.forName("org.postgresql.Driver");
} catch (java.lang.ClassNotFoundException e){
JOptionPane.showMessageDialog (null, "Classe de banco no encontrad
a");
}
Connection db = null;
try{
db = DriverManager.getConnection(url, "postgres", "postgres");
} catch (SQLException ex) {
JOptionPane.showMessageDialog (null, "Nao foi possivel conectar ao b
anco ");
}
String
String
String
String
String

equipamento = txtequipamento.getText();
empresa = txtempresa.getText();
setor = txtsetor.getText();
manutencao = txtmanutencao.getText();
material = txtmaterial.getText();

String sql = "insert into Equipamento (Equipamento, Empresa, Setor, Manu


teno, Material) values ('" + equipamento +" ',' "+ empresa +
" ',' ' "+ setor +" ',' "+ manutencao +" ',' " + material +" ')";
Statement st = null;
try{
st = db.createStatement ();
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
return;
}
try {
st.executeUpdate (sql);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
/**
* @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 cod
e (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the d
efault look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lo
okandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIMana
ger.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(guiEquipamento.class.getName()).l
og(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(guiEquipamento.class.getName()).l
og(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(guiEquipamento.class.getName()).l
og(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(guiEquipamento.class.getName()).l
og(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new guiEquipamento().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton btnincluir;
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JList jList1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextField txtempresa;
private javax.swing.JTextField txtequipamento;
private javax.swing.JTextField txtmanutencao;
private javax.swing.JTextField txtmaterial;
private javax.swing.JTextField txtsetor;
// End of variables declaration
}

Das könnte Ihnen auch gefallen