Ta dando erro na linha 154, no ForEach, e na linha 159. Alguem ai pode dar um help!!???
-
import java.sql.Connection;
-
import java.sql.ResultSet;
-
import java.sql.Statement;
-
import java.util.ArrayList;
-
import java.util.Arrays;
-
import javax.swing.DefaultListModel;
-
/*
-
- 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.
-
*/
-
/**
-
-
- @author tigones
-
*/
-
public class MeusAlunos extends javax.swing.JFrame {
-
/**
-
* Creates new form MeusAlunos
-
*/
-
public MeusAlunos() {
-
initComponents();
-
atualizaAlunos();
-
}
-
/**
-
* 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() {
-
jRadioButton1 = new javax.swing.JRadioButton();
-
jLabel1 = new javax.swing.JLabel();
-
jScrollPane1 = new javax.swing.JScrollPane();
-
jList1 = new javax.swing.JList<>();
-
btnAdicionar = new javax.swing.JButton();
-
btnExcluir = new javax.swing.JButton();
-
btnVoltar = new javax.swing.JButton();
-
jRadioButton1.setText("jRadioButton1");
-
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
-
jLabel1.setFont(new java.awt.Font("Ubuntu", 0, 36)); // NOI18N
-
jLabel1.setText("ALUNOS");
-
jList1.setModel(new javax.swing.AbstractListModel<String>() {
-
String[] strings = { "Aluno 1", "Aluno 2", "Aluno 3", "Aluno 4", "Aluno 5", "Aluno 6", "Aluno 7", "Aluno 8", "Aluno9" };
-
public int getSize() { return strings.length; }
-
public String getElementAt(int i) { return strings[i]; }
-
});
-
jScrollPane1.setViewportView(jList1);
-
btnAdicionar.setText("Adicionar");
-
btnExcluir.setText("Excluir");
-
btnVoltar.setText("Voltar");
-
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(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 77, Short.MAX_VALUE)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addComponent(btnAdicionar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(btnExcluir, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addComponent(btnVoltar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
-
.addContainerGap())
-
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
-
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(jLabel1)
-
.addGap(112, 112, 112))
-
);
-
layout.setVerticalGroup(
-
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
-
.addGroup(layout.createSequentialGroup()
-
.addContainerGap(26, Short.MAX_VALUE)
-
.addComponent(jLabel1)
-
.addGap(18, 18, 18)
-
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
-
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
-
.addGroup(layout.createSequentialGroup()
-
.addComponent(btnAdicionar)
-
.addGap(18, 18, 18)
-
.addComponent(btnExcluir)
-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
-
.addComponent(btnVoltar)))
-
.addContainerGap())
-
);
-
pack();
-
}// </editor-fold>
-
/**
-
* @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(MeusAlunos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-
} catch (InstantiationException ex) {
-
java.util.logging.Logger.getLogger(MeusAlunos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-
} catch (IllegalAccessException ex) {
-
java.util.logging.Logger.getLogger(MeusAlunos.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
-
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
-
java.util.logging.Logger.getLogger(MeusAlunos.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 MeusAlunos().setVisible(true);
-
}
-
});
-
}
-
// Variables declaration - do not modify
-
private javax.swing.JButton btnAdicionar;
-
private javax.swing.JButton btnExcluir;
-
private javax.swing.JButton btnVoltar;
-
private javax.swing.JLabel jLabel1;
-
private javax.swing.JList<String> jList1;
-
private javax.swing.JRadioButton jRadioButton1;
-
private javax.swing.JScrollPane jScrollPane1;
-
// End of variables declaration
-
private void atualizaAlunos() {
-
//ArrayList<String> bandas = new ArrayList<String>
-
ArrayList alunos = new ArrayList();
-
Connection conexao = Conexao.getInstance().sqlConnection;
-
//fill client list
-
String query = “SELECT nome, cpf FROM aluno”;
-
Statement stmt = null;
-
try{
-
stmt = conexao.createStatement();
-
ResultSet rs = stmt.executeQuery(query);
-
while(rs.next()){
-
String nome = rs.getString(“nome”);
-
String cpf = rs.getString(“cpf”);
-
//adiciona cliente na lista
-
aluno.add(new aluno(nome, cpf));
-
}
-
}catch(Exception e){
-
e.printStackTrace();
-
}
-
DefaultListModel listModel = new DefaultListModel();
-
- for(Alunos c : alunos){
-
- listModel.addElement(new String(c.getNome() + " - " + c.getCPF()));
-
- System.out.println("Aluno name: " + c.getNome());
-
- }
-
-
- listAlunos.setModel(listModel);
-
- }
-
-
}
-
-
- }