/*
* 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 gui;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import modelo.Aluno;
import modelo.sql.AlunoSQL;
/**
*
* @author Sidney
*/
public class AlunoGUI
extends javax.
swing.
JFrame {
/**
* Creates new form AlunoGUI
*/
AlunoSQL alunoSQL;
Aluno al;
initComponents();
this.alunoSQL = new AlunoSQL(con);
}
public AlunoGUI() {
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() {
label1
= new javax.
swing.
JLabel();
jLabel2
= new javax.
swing.
JLabel();
jList1 = new javax.swing.JList<>();
msg
= new javax.
swing.
JLabel();
jButton1
= new javax.
swing.
JButton();
public void windowOpened
(java.
awt.
event.
WindowEvent evt
) {
formWindowOpened(evt);
}
});
label1.setText("ID:");
jLabel2.setText("Nome:");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
nomeActionPerformed(evt);
}
});
idAluno.
setHorizontalAlignment(javax.
swing.
JTextField.
CENTER);
idAluno.setText("1");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
idAlunoActionPerformed(evt);
}
});
public void mouseClicked
(java.
awt.
event.
MouseEvent evt
) {
jList1MouseClicked(evt);
}
});
jScrollPane1.setViewportView(jList1);
jButton1.setText("Altera");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(label1)
.addGap(18, 18, 18)
.addComponent(idAluno, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.addComponent(jButton1))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.
addComponent(msg, javax.
swing.
GroupLayout.
DEFAULT_SIZE, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE)
.
addComponent(jScrollPane1, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
304,
Short.
MAX_VALUE)
.addComponent(nome))))
.
addContainerGap(35,
Short.
MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(label1)
.addComponent(idAluno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(nome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED,
30,
Short.
MAX_VALUE)
.addComponent(msg))
);
pack();
}// </editor-fold>
private void idAlunoActionPerformed
(java.
awt.
event.
ActionEvent evt
) {
nome.setText(null);
al
= alunoSQL.
buscaAluno(Integer.
parseInt(idAluno.
getText()));
if (al == null) {
nome.setText("Aluno não encontrado");
} else {
nome.setText(al.getNome());
}
}
private void formWindowOpened
(java.
awt.
event.
WindowEvent evt
) {
}
private void nomeActionPerformed
(java.
awt.
event.
ActionEvent evt
) {
jList1.setModel(alunoSQL.alunosBuscar(nome.getText()));
idAluno.setText(null);
nome.setText(null);
}
private void jList1MouseClicked
(java.
awt.
event.
MouseEvent evt
) {
if (evt.getClickCount() == 2) {
al = jList1.getSelectedValue();
idAluno.
setText(Integer.
toString(al.
getIdAluno()));
nome.setText(al.getNome());
}
}
private void jButton1ActionPerformed
(java.
awt.
event.
ActionEvent evt
) {
Object[] opcoes
= {"sim",
"não"};
"Deseja fazer a Alteração?",
"Finalização",
null,
opcoes,
"não");
if (!idAluno.getText().isEmpty() && resposta=="sim") {
alunoSQL.
alteraNome(Integer.
parseInt(idAluno.
getText()), nome.
getText());
}
}
/**
* @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 {
if ("Nimbus".equals(info.getName())) {
javax.
swing.
UIManager.
setLookAndFeel(info.
getClassName());
break;
}
}
java.util.logging.Logger.getLogger(AlunoGUI.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(AlunoGUI.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(AlunoGUI.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(AlunoGUI.class
.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
public void run() {
new AlunoGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.
swing.
JButton jButton1
;
private javax.
swing.
JLabel jLabel2
;
private javax.swing.JList<Aluno> jList1;
private javax.
swing.
JLabel label1
;
private javax.
swing.
JLabel msg
;
// End of variables declaration
}