-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVisualizarJFrame.java
More file actions
202 lines (164 loc) · 7.84 KB
/
VisualizarJFrame.java
File metadata and controls
202 lines (164 loc) · 7.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package interfaceG;
//@LucasTavares
import java.awt.event.ActionEvent;
import javax.swing.JOptionPane;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;
public class VisualizarJFrame extends javax.swing.JFrame {
//referenciar a tela de cadastro
private CadastroJogadorJFrame telaCadastro;
//salvar os dados do jogador
private ArrayList<Jogador> array;
public VisualizarJFrame() {
initComponents();
//inicializa a tela de cadastro e visualizar
telaCadastro = new CadastroJogadorJFrame(this);
this.array = new ArrayList<Jogador>();
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
tabelaJogadores = new javax.swing.JTable();
btIncluir = new javax.swing.JButton();
btRemover = new javax.swing.JButton();
btVisualizar = new javax.swing.JButton();
btFechar = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
tabelaJogadores.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
},
new String [] {
"Nome", "Idade", "Salário", "Prêmio Individual", "Modalidade"
}
));
jScrollPane1.setViewportView(tabelaJogadores);
btIncluir.setText("Inserir");
btIncluir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btIncluirActionPerformed(evt);
}
});
btRemover.setText("Remover");
btRemover.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btRemoverActionPerformed(evt);
}
});
btVisualizar.setText("Visualizar");
btVisualizar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btVisualizarActionPerformed(evt);
}
});
btFechar.setText("Fechar");
btFechar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btFecharActionPerformed(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()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 666, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(btRemover)
.addGap(18, 18, 18)
.addComponent(btFechar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btVisualizar)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btIncluir)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 267, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btIncluir)
.addComponent(btRemover)
.addComponent(btVisualizar)
.addComponent(btFechar))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void btVisualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btVisualizarActionPerformed
int linhaSelecionda = tabelaJogadores.getSelectedRow();
if (linhaSelecionda < 0){
JOptionPane.showMessageDialog(this, "Por Favor, Selecione uma linha!"
+ "", "Aviso", JOptionPane.WARNING_MESSAGE);
}else{
this.telaCadastro.mostrarJogador(array.get(linhaSelecionda));
this.setVisible(false);
}
}//GEN-LAST:event_btVisualizarActionPerformed
private void btIncluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btIncluirActionPerformed
//torna a outra tela visível
this.telaCadastro.setVisible(true);
//torna esta tela invisível
this.setVisible(false);
}//GEN-LAST:event_btIncluirActionPerformed
private void btRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btRemoverActionPerformed
int selectedIndex = tabelaJogadores.getSelectedRow();
if (selectedIndex < 0){
//erro se nenhuma linha for selecionada
JOptionPane.showMessageDialog(this, "Por Favor, Selecione um item!","Aviso",JOptionPane.WARNING_MESSAGE);
}else{
//um item está selecionado, então remove
this.removeJogador(selectedIndex);
}//GEN-LAST:event_btRemoverActionPerformed
}
private void btFecharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFecharActionPerformed
System.exit(0);// TODO add your handling code here:
}//GEN-LAST:event_btFecharActionPerformed
public void addJogador(Jogador j){
this.array.add(j);
this.addJogadorToTable(j);
}
public void addJogadorToTable(Jogador j){
DefaultTableModel model = (DefaultTableModel)tabelaJogadores.getModel();
model.addRow(new Object[]{j.getnome(), j.getidade(), j.getsalario(), j.getpremioIndividual(), j.getmodalidade()});
}
public void removeJogador(int i) {
array.remove(i);
removeJogadorFromTable(i);
}
public void removeJogadorFromTable(int i){
DefaultTableModel model = (DefaultTableModel)tabelaJogadores.getModel();
model.removeRow(i);
}
public void redesenhaTabela(){
DefaultTableModel model = (DefaultTableModel)tabelaJogadores.getModel();
while (model.getRowCount() > 0){
model.removeRow(0);
}
for (Jogador j : array){
model.addRow(new Object[]{j.getnome(), j.getidade(), j.getsalario(), j.getpremioIndividual(), j.getmodalidade()});
}
}
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btFechar;
private javax.swing.JButton btIncluir;
private javax.swing.JButton btRemover;
private javax.swing.JButton btVisualizar;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable tabelaJogadores;
// End of variables declaration//GEN-END:variables
}