package view;
import java.awt.GridLayout;
import java.util.ArrayList;
import javax.swing.*;
import custom_swing.JBGPanel;
import data_model.gambler;
import database.DatabaseConnection;
import database.ProblemwithDataApplication;
public class player_choose_main extends JPanel {
/**
*
*/
private static final long serialVersionUID = 1L;
JBGPanel right = new JBGPanel("./src/img/BG_Stone.png");
JPanel left = new JPanel();
GridLayout grid = new GridLayout(1,2);
ArrayList<String> gambler;
int rows = 5;
public player_choose_main() {
super();
try {
addEntrys();
} catch (ProblemwithDataApplication e) {
e.printStackTrace();
}
this.setOpaque(false);
grid.setHgap(100);
this.setLayout(grid);
left.setOpaque(false);
GridLayout gridi = new GridLayout(rows+2,1,0,26);
left.setLayout(gridi);
this.add(left);
this.add(right);
}
public void addEntrys() throws ProblemwithDataApplication{
DatabaseConnection con = DatabaseConnection.getInstance();
con.connect();
left.removeAll();
try {
gambler = con.getAllGamblers();
} catch (ProblemwithDataApplication e) {
e.printStackTrace();
}
int count = gambler.size();
int count_new = rows-count;
left.add(new JLabel());
if(count>0){
for(int i=0;i<count;i++){
String gambler_name = gambler.get(i);
try {
gambler player = con.getGambler(gambler_name);
left.add(new player_choose_entry(this,player.getId(),player.getName(),player.getMoney(),player.getStyle()));
} catch (ProblemwithDataApplication e) {
e.printStackTrace();
}
}
}
if(count_new>0)left.add(new player_choose_entry(this));
left.add(new JLabel());
con.shutdown();
this.setVisible(false);
this.setVisible(true);
}
}