package view;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.*;
import data_model.gambler;
import database.DatabaseConnection;
import database.ProblemwithDataApplication;
public class player_choose_new extends JFrame implements ActionListener{
/**
*
*/
private static final long serialVersionUID = 1L;
String asia_string = "Asia";
String myth_string = "Mythology";
String medieval_string = "Medieval";
String western_string = "Western";
String starter_deck1_string = "Starter-Deck 1";
String starter_deck2_string = "Starter-Deck 2";
String starter_deck3_string = "Starter-Deck 3";
String style = asia_string;
String deck = starter_deck1_string;
JRadioButton asia = new JRadioButton(asia_string);
JRadioButton myth = new JRadioButton(myth_string);
JRadioButton medieval = new JRadioButton(medieval_string);
JRadioButton western = new JRadioButton(western_string);
JRadioButton starter_deck1 = new JRadioButton(starter_deck1_string);
JRadioButton starter_deck2 = new JRadioButton(starter_deck2_string);
JRadioButton starter_deck3 = new JRadioButton(starter_deck3_string);
ButtonGroup style_choose = new ButtonGroup();
ButtonGroup deck_choose = new ButtonGroup();
JButton confirm = new JButton("Erstellen");
JButton cancel = new JButton("Abbrechen");
JTextField name_field = new JTextField();
DatabaseConnection con = DatabaseConnection.getInstance();
player_choose_entry owner;
player_choose_main main_owner;
public player_choose_new(player_choose_entry owner,player_choose_main main_owner){
this.owner = owner;
if(main_owner==null)System.out.println("Kein Owner Owner");
this.main_owner = main_owner;
try {
con.connect();
} catch (ProblemwithDataApplication e) {
e.printStackTrace();
}
starter_deck1.setActionCommand(starter_deck1_string);
starter_deck2.setActionCommand(starter_deck2_string);
starter_deck3.setActionCommand(starter_deck3_string);
deck_choose.add(starter_deck1);
deck_choose.add(starter_deck2);
deck_choose.add(starter_deck3);
starter_deck1.setSelected(true);
starter_deck1.addActionListener(this);
starter_deck2.addActionListener(this);
starter_deck3.addActionListener(this);
JPanel deck_pane = new JPanel(new GridLayout(1,0));
deck_pane.add(starter_deck1);
deck_pane.add(starter_deck2);
deck_pane.add(starter_deck3);
asia.setActionCommand(asia_string);
myth.setActionCommand(medieval_string);
medieval.setActionCommand(medieval_string);
western.setActionCommand(western_string);
style_choose.add(asia);
style_choose.add(myth);
style_choose.add(medieval);
style_choose.add(western);
asia.setSelected(true);
asia.addActionListener(this);
myth.addActionListener(this);
medieval.addActionListener(this);
western.addActionListener(this);
JPanel style_pane = new JPanel(new GridLayout(1,0));
style_pane.add(asia);
style_pane.add(myth);
style_pane.add(medieval);
style_pane.add(western);
JPanel choose_pane = new JPanel(new GridLayout(0,1));
choose_pane.add(style_pane);
choose_pane.add(deck_pane);
JPanel menu = new JPanel(new GridLayout(0,1));
menu.add(confirm);
menu.add(cancel);
confirm.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
try {
confirmActionPerformed(evt);
} catch (ProblemwithDataApplication e) {
e.printStackTrace();
}
}
});
cancel.addMouseListener(new java.awt.event.MouseAdapter() {
public void mousePressed(java.awt.event.MouseEvent evt) {
try {
cancelActionPerformed(evt);
} catch (ProblemwithDataApplication e) {
e.printStackTrace();
}
}
});
this.setSize(new Dimension(400,200));
this.setLayout(new BorderLayout());
this.setLocation(620,50);
this.add(name_field,BorderLayout.NORTH);
this.add(choose_pane,BorderLayout.CENTER);
this.add(menu,BorderLayout.SOUTH);
this.setVisible(true);
}
private void confirmActionPerformed(java.awt.event.MouseEvent evt) throws ProblemwithDataApplication {
if(con == null)System.out.println("Keine Konnektion");
con.insertGambler(new gambler(1,name_field.getText(),100,1,null,null,Color.gray));
System.out.println("Spieler hinzugef�gt");
con.shutdown();
System.out.println("Verbindung geschlossen");
if(owner!=null && main_owner!=null){
main_owner.addEntrys();
}
else{
if(owner==null)System.out.println("Kein Owner");
if(main_owner==null)System.out.println("Kein Owner Owner");
}
this.setVisible(false);
this.dispose();
}
private void cancelActionPerformed(java.awt.event.MouseEvent evt) throws ProblemwithDataApplication {
con.shutdown();
this.setVisible(false);
this.dispose();
}
public void actionPerformed(ActionEvent ev) {
String res = ev.getSource().toString();
if(res.contains(asia_string))style = asia_string;
if(res.contains(myth_string))style = myth_string;
if(res.contains(medieval_string))style = medieval_string;
if(res.contains(western_string))style = western_string;
if(res.contains(starter_deck1_string))deck = starter_deck1_string;
if(res.contains(starter_deck2_string))deck = starter_deck2_string;
if(res.contains(starter_deck3_string))deck = starter_deck3_string;
}
}