package myjava.sport;
import myjava.awt.MyColor;
import myjava.swing.*;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.text.MaskFormatter;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import static myjava.awt.MyColor.hexToRgb;
import static myjava.data.MyFile.getWorkingDir;
import static myjava.sport.BundesligaGames.length;
public class BundesligaStartup extends MyFrame {
private static int startXPl = 10, startYPl = 10, widthLPl = 320, widthTFPl = 200, heightPl = 30;
private static JPanel panelCB = new JPanel();
private static JPanel panelO = new JPanel();
private static JComboBox<String> comboBoxSaison = new JComboBox<>(new String[]{"Saison"});
private static JComboBox<String> comboBoxSpieltage = new JComboBox<>(new String[]{"Spieltag"});
private static String dirPl = getWorkingDir() + "/Fussball/Saisons/";
private static String home,away,goalsH,goalsA;
private static String selItSaison,selItSpieltage;
private static String[] itemsSaison,itemsSpieltage,matches;
private static String create = "ERSTELLEN";
private static String edit = "BEARBEITEN";
private static String settings = "EINSTELLUNGEN";
private static String player = "SPIELER";
private static String manager = "TRAINER";
private static String team = "VEREIN";
private static MyLabel [] labelHome = new MyLabel[100], labelAway = new MyLabel[100],labelGoalsHome = new MyLabel[100], labelGoalsAway = new MyLabel[100];
public static Font font = new Font("Bundesliga", Font.BOLD, 20);
public static Font goalFont = new Font(font.getName(),font.getStyle(),50);
public static Font menuFont = new Font(font.getName(), font.getStyle(), 15);
private static MyButton createBtnPl = new MyButton("Erstellen");
private static MyFrame framePl = new MyFrame("Neuen Spieler erstellen");
private static String dateFormat = "##.##.####", rnFormat = "##", persFormat = "###";
private static String vnPl, nnPl, aliasPl, teamPl, posPl, gebDatPl, saisonSPl, saisonEPl, grPl, gewPl, rnPl;
private static MyLabel vnLPl = new MyLabel("Vorname:"), nnLPl = new MyLabel("Nachname:"),
aliasLPl = new MyLabel("Alias:"), gebDatLPl = new MyLabel("Geburtsdatum:"),
grLPl = new MyLabel("Größe (cm):"), gewLPl = new MyLabel("Gewicht (kg):"),
teamLPl = new MyLabel("Verein:"), rnLPl = new MyLabel("Rückennummer:"),
posLPl = new MyLabel("Position:"),
saisonSLPl = new MyLabel("Im Verein seit (nur aktuelle Saison):"),
saisonELPl = new MyLabel("Im Verein bis (nur aktuelle Saison):");
private static MyTextField vnTFPl = new MyTextField(), nnTFPl = new MyTextField(),
aliasTFPl = new MyTextField(),
teamTFPl = new MyTextField(),
posTFPl = new MyTextField();
private static MyFormattedTextField
gebDatTFPl = new MyFormattedTextField(createFormatter(dateFormat)),
grTFPl = new MyFormattedTextField(createFormatter(persFormat)),
gewTFPl = new MyFormattedTextField(createFormatter(persFormat)),
rnTFPl = new MyFormattedTextField(createFormatter(rnFormat)),
saisonSTFPl = new MyFormattedTextField(createFormatter(dateFormat)),
saisonETFPl = new MyFormattedTextField(createFormatter(dateFormat));
public BundesligaStartup(int width,int height) {
setBounds(0, 0, width, height);
setTitle("Startmenü");
NullLayout();
EXIT_ON_CLOSE();
notResizable();
createMenu();
panelCB.setBounds(0,0,width,50);
panelO.setBounds(0,50,width, height);
JScrollPane scrollPane = new JScrollPane(panelO);
scrollPane.setBounds(0, 50, 900, height - 300);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
add(scrollPane);
addComboBoxActionListener();
panelCB.setLayout(null);
panelO.setLayout(null);
comboBoxSaison.setBounds(10,10,125,30);
comboBoxSaison.setFont(new Font(font.getName(),font.getStyle(),12));
comboBoxSpieltage.setBounds(140,10,110,30);
comboBoxSpieltage.setFont(new Font(font.getName(),font.getStyle(),12));
panelCB.add(comboBoxSaison);
panelCB.add(comboBoxSpieltage);
add(panelCB);
open();
}
private void addComboBoxActionListener() {
String dir = getWorkingDir() + "/Fussball/Spiele/Saisons";
File f = new File(dir);
File[] farr = f.listFiles();
itemsSaison = new String[f.listFiles().length];
for (int i = 0; i < farr.length; i++){
itemsSaison = farr.toString().replace("/","\\");
}
for (int i = 0; i < farr.length; i++){
String d = dir.replace("/","\\");
itemsSaison = itemsSaison.replace(d + "\\","");
}
comboBoxSaison.setModel(new DefaultComboBoxModel<>(itemsSaison));
comboBoxSaison.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selItSaison = (String) comboBoxSaison.getSelectedItem();
String dirs = dir + "/" + selItSaison + "/Spieltage";
File fs = new File(dirs);
File[] farrs = fs.listFiles();
itemsSpieltage = new String[fs.listFiles().length];
for (int i = 0; i < farrs.length; i++){
itemsSpieltage = farrs.toString().replace("/","\\");
}
for (int i = 0; i < farrs.length; i++){
String d = dirs.replace("/","\\");
itemsSpieltage = itemsSpieltage.replace(d + "\\","");
}
comboBoxSpieltage.setModel(new DefaultComboBoxModel<>(itemsSpieltage));
}
});
comboBoxSpieltage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selItSpieltage = (String) comboBoxSpieltage.getSelectedItem();
String dirsp = dir + "/" + selItSaison + "/Spieltage/" + selItSpieltage;
File fsp = new File(dirsp);
File[] farrsp = fsp.listFiles();
matches = new String[fsp.listFiles().length];
labelHome = new MyLabel[matches.length];
labelAway = new MyLabel[matches.length];
labelGoalsHome = new MyLabel[matches.length];
labelGoalsAway = new MyLabel[matches.length];
for (int i = 0; i < farrsp.length; i++){
matches = farrsp.toString().replace("/","\\");
}
for (int i = 0; i < farrsp.length; i++){
int sXH = 10, width = 75, sXA = sXH + width, heightT = 100;
String d = dirsp.replace("/","\\");
matches = matches.replace(d + "\\","");
home = matches.substring(0,matches.indexOf("-"));
away = matches.substring(matches.indexOf("-") + 1,matches.indexOf(".match"));
labelHome = new MyLabel();
labelAway = new MyLabel();
labelGoalsHome = new MyLabel();
labelGoalsAway = new MyLabel();
labelHome.setBounds(sXH,heightT * (i + 1) + 20,100,10);
System.out.println(labelHome.getX());
System.out.println(labelHome.getX());
labelAway.setBounds(sXA,heightT * (i + 1) + 20,100,10);
panelO.add(labelHome);
panelO.add(labelAway);
labelHome.setText(home);
labelGoalsHome.setBounds(sXH + 2 * width,labelHome.getY(),width,heightT);
labelGoalsAway.setBounds(sXA + 2 * width,labelAway.getY(),width,heightT);
panelO.add(labelGoalsHome);
panelO.add(labelGoalsAway);
createLabel(i, sXH,sXA,home,away,labelHome,labelGoalsHome,labelAway,labelGoalsAway);
panelO.add(labelAway);
String text = readSoccerFiles(dirsp + "/" + matches);
if(text.endsWith("\n")) {
text = text.substring(0,text.length() - 1);
}
String[] goals = text.split("-");
goalsH = goals[0];
goalsA = goals[1];
MyColor homebc = new MyColor(labelHome.getBackground().getRed(),labelHome.getBackground().getGreen(),labelHome.getBackground().getBlue());
MyColor homefc = new MyColor(labelHome.getForeground().getRed(),labelHome.getForeground().getGreen(),labelHome.getForeground().getBlue());
MyColor awaybc = new MyColor(labelAway.getBackground().getRed(),labelAway.getBackground().getGreen(),labelAway.getBackground().getBlue());
MyColor awayfc = new MyColor(labelAway.getForeground().getRed(),labelAway.getForeground().getGreen(),labelAway.getForeground().getBlue());
labelGoalsHome.setFont(goalFont);
labelGoalsHome.setText(goalsH);
labelGoalsHome.centerText();
labelGoalsHome.setOpaque(true);
labelGoalsHome.setBackground(homebc);
labelGoalsHome.setForeground(homefc);
labelGoalsAway.setFont(goalFont);
labelGoalsAway.setText(goalsA);
labelGoalsAway.centerText();
labelGoalsAway.setOpaque(true);
labelGoalsAway.setBackground(awaybc);
labelGoalsAway.setForeground(awayfc);
panelO.add(labelGoalsHome);
panelO.add(labelGoalsAway);
}
}
});
}
private void createMenu() {
JMenuBar menuBar = new JMenuBar();
//Settings-Menu
JMenu settingsMenu = new JMenu(settings);
settingsMenu.setFont(menuFont);
//Player-Menu
JMenuItem playerItem = new JMenu(player);
playerItem.setFont(menuFont);
JMenuItem createPlayerItem = new JMenuItem(create);
createPlayerItem.setFont(menuFont);
playerItem.add(createPlayerItem);
JMenuItem editPlayerItem = new JMenuItem(edit);
editPlayerItem.setFont(menuFont);
playerItem.add(editPlayerItem);
//Manager-Menu
JMenuItem managerItem = new JMenu(manager);
managerItem.setFont(menuFont);
JMenuItem createManagerItem = new JMenuItem(create);
createManagerItem.setFont(menuFont);
managerItem.add(createManagerItem);
JMenuItem editManagerItem = new JMenuItem(edit);
editManagerItem.setFont(menuFont);
managerItem.add(editManagerItem);
//Team-Menu
JMenuItem teamItem = new JMenu(team);
teamItem.setFont(menuFont);
JMenuItem createTeamItem = new JMenuItem(create);
createTeamItem.setFont(menuFont);
teamItem.add(createTeamItem);
JMenuItem editTeamItem = new JMenuItem(edit);
editTeamItem.setFont(menuFont);
teamItem.add(editTeamItem);
//add to Settings
settingsMenu.add(playerItem);
settingsMenu.add(managerItem);
settingsMenu.add(teamItem);
//add functions
addCreatePlayer(createPlayerItem);
addEditPlayer(editPlayerItem);
addCreateManager(createManagerItem);
addCreateTeam(createTeamItem);
menuBar.add(settingsMenu);
setJMenuBar(menuBar);
}
private void addCreateTeam(JMenuItem createTeamItem) {
}
private void addCreateManager(JMenuItem createManagerItem) {
}
private void addCreatePlayer(JMenuItem createPlayerItem) {
createPlayerItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
framePl.setSize(600, 550);
framePl.NullLayout();
framePl.HIDE_ON_CLOSE();
framePl.notResizable();
setFontPlayer();
setBoundsPlayer();
addToPlayerFrame();
addActionListenerCreatePlayerButton();
framePl.open();
}
});
}
private void addEditPlayer(JMenuItem editPlayerItem) {
editPlayerItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser();
File startDir = new File(getWorkingDir() + "/Fussball/Saisons");
jfc.setCurrentDirectory(startDir);
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File f) {
String fileName = f.getName();
return fileName.endsWith(".player") || f.isDirectory();
}
@Override
public String getDescription() {
return "Player files (*.player)";
}
};
jfc.setFileFilter(filter);
int res = jfc.showOpenDialog(null);
if (res == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
String textPl = readSoccerFiles(selectedFile.getAbsolutePath());
String[] splitedPl = textPl.split("\n");
framePl.setTitle("vorhandenen Spieler bearbeiten");
vnTFPl.setText(text(splitedPl, 0, ":", 2));
nnTFPl.setText(text(splitedPl, 1, ":", 2));
aliasTFPl.setText(text(splitedPl, 2, ":", 2));
gebDatTFPl.setText(text(splitedPl, 3, ":", 2));
grTFPl.setText(text(splitedPl, 4, ":", 2));
gewTFPl.setText(text(splitedPl, 5, ":", 2));
teamTFPl.setText(text(splitedPl, 6, ":", 2));
rnTFPl.setText(text(splitedPl, 7, ":", 2));
posTFPl.setText(text(splitedPl, 8, ":", 2));
saisonSTFPl.setText(text(splitedPl, 9, ":", 2));
saisonETFPl.setText(text(splitedPl, 10, ":", 2));
framePl.setSize(600, 550);
framePl.NullLayout();
framePl.HIDE_ON_CLOSE();
framePl.notResizable();
setFontPlayer();
setBoundsPlayer();
addToPlayerFrame();
addActionListenerCreatePlayerButton();
framePl.open();
} else if (res == JFileChooser.CANCEL_OPTION) {
}
}
});
}
public static String text(String[] s, int i, String find, int add) {
if (add >= 0) {
return s.substring(s.indexOf(find) + add);
} else {
return s.substring(s.indexOf(find) - add);
}
}
private void addActionListenerCreatePlayerButton() {
createBtnPl.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
vnPl = vnTFPl.getString();
nnPl = nnTFPl.getString();
aliasPl = aliasTFPl.getString();
gebDatPl = gebDatTFPl.getString();
grPl = grTFPl.getString();
gewPl = gewTFPl.getString();
teamPl = teamTFPl.getString();
rnPl = rnTFPl.getString();
posPl = posTFPl.getString();
saisonSPl = saisonSTFPl.getString();
saisonEPl = saisonETFPl.getString();
if (rnPl.startsWith("0")) {
rnPl.replaceFirst("0", "");
}
if (gewPl.startsWith("0")) {
gewPl.replaceFirst("0", "");
}
String ges = vnLPl.getText() + " " + vnPl + "\n"
+ nnLPl.getText() + " " + nnPl + "\n"
+ aliasLPl.getText() + " " + aliasPl + "\n"
+ gebDatLPl.getText() + " " + gebDatPl + "\n"
+ grLPl.getText() + " " + grPl + "\n"
+ gewLPl.getText() + " " + gewPl + "\n"
+ teamLPl.getText() + " " + teamPl + "\n"
+ rnLPl.getText() + " " + rnPl + "\n"
+ posLPl.getText() + " " + posPl + "\n"
+ saisonSLPl.getText() + " " + saisonSPl + "\n"
+ saisonELPl.getText() + " " + saisonEPl + "\n";
int m = Integer.parseInt(saisonSPl.substring(3, 5));
int j = Integer.parseInt(saisonSPl.substring(6, 10));
String datName;
new Player(vnPl, nnPl, aliasPl, gebDatPl, grPl, gewPl, teamPl, rnPl, posPl, saisonSPl, saisonEPl);
if (m < 7) {
dirPl += "Saison " + (j - 1) + "-" + j + "/";
} else {
dirPl += "Saison " + j + "-" + (j + 1) + "/";
}
dirPl += teamPl + "/Spieler/";
if (aliasPl.equals("")) {
datName = vnPl + " " + nnPl + ".player";
} else {
datName = aliasPl + ".player";
}
File plFile = new File(dirPl + datName);
if (!plFile.exists()) {
try {
plFile.createNewFile();
writePlayerFile(dirPl + datName, ges);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} else {
writePlayerFile(dirPl + datName, ges);
}
framePl.close();
}
});
}
public static void cursorBounds(MyLabel hl, MyLabel al, MyLabel ghl, MyLabel gal){
ghl.setBounds(hl.getX() + hl.getWidth(), hl.getY(),ghl.getWidth(),hl.getHeight());
gal.setBounds(ghl.getX() + ghl.getWidth(),hl.getY(),gal.getWidth(),hl.getHeight());
al.setBounds(gal.getX() + gal.getWidth(),hl.getY(),hl.getWidth(),hl.getHeight());
}
private void addToPlayerFrame() {
framePl.add(vnLPl);
framePl.add(nnLPl);
framePl.add(aliasLPl);
framePl.add(gebDatLPl);
framePl.add(grLPl);
framePl.add(gewLPl);
framePl.add(teamLPl);
framePl.add(rnLPl);
framePl.add(posLPl);
framePl.add(saisonSLPl);
framePl.add(saisonELPl);
framePl.add(vnTFPl);
framePl.add(nnTFPl);
framePl.add(aliasTFPl);
framePl.add(gebDatTFPl);
framePl.add(grTFPl);
framePl.add(gewTFPl);
framePl.add(teamTFPl);
framePl.add(rnTFPl);
framePl.add(posTFPl);
framePl.add(saisonSTFPl);
framePl.add(saisonETFPl);
framePl.add(createBtnPl);
}
private void setBoundsPlayer() {
vnLPl.setBounds(startXPl, startYPl, widthLPl, heightPl);
nnLPl.setBounds(startXPl, startYPl + heightPl + startXPl, widthLPl, heightPl);
aliasLPl.setBounds(startXPl, startYPl + 2 * (heightPl + startXPl), widthLPl, heightPl);
gebDatLPl.setBounds(startXPl, startYPl + 3 * (heightPl + startXPl), widthLPl, heightPl);
grLPl.setBounds(startXPl, startYPl + 4 * (heightPl + startXPl), widthLPl, heightPl);
gewLPl.setBounds(startXPl, startYPl + 5 * (heightPl + startXPl), widthLPl, heightPl);
teamLPl.setBounds(startXPl, startYPl + 6 * (heightPl + startXPl), widthLPl, heightPl);
rnLPl.setBounds(startXPl, startYPl + 7 * (heightPl + startXPl), widthLPl, heightPl);
posLPl.setBounds(startXPl, startYPl + 8 * (heightPl + startXPl), widthLPl, heightPl);
saisonSLPl.setBounds(startXPl, startYPl + 9 * (heightPl + startXPl), widthLPl, heightPl);
saisonELPl.setBounds(startXPl, startYPl + 10 * (heightPl + startXPl), widthLPl, heightPl);
vnTFPl.setBounds(startXPl + widthLPl + 10, startYPl, widthTFPl, heightPl);
nnTFPl.setBounds(startXPl + widthLPl + 10, startYPl + heightPl + startXPl, widthTFPl, heightPl);
aliasTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 2 * (heightPl + startXPl), widthTFPl, heightPl);
gebDatTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 3 * (heightPl + startXPl), widthTFPl, heightPl);
grTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 4 * (heightPl + startXPl), widthTFPl, heightPl);
gewTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 5 * (heightPl + startXPl), widthTFPl, heightPl);
teamTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 6 * (heightPl + startXPl), widthTFPl, heightPl);
rnTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 7 * (heightPl + startXPl), widthTFPl, heightPl);
posTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 8 * (heightPl + startXPl), widthTFPl, heightPl);
saisonSTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 9 * (heightPl + startXPl), widthTFPl, heightPl);
saisonETFPl.setBounds(startXPl + widthLPl + 10, startYPl + 10 * (heightPl + startXPl), widthTFPl, heightPl);
createBtnPl.setBounds(startXPl + widthLPl + 10, startYPl + 11 * (heightPl + startXPl), widthTFPl, heightPl);
}
private void setFontPlayer() {
vnLPl.setFont(font);
nnLPl.setFont(font);
aliasLPl.setFont(font);
gebDatLPl.setFont(font);
grLPl.setFont(font);
gewLPl.setFont(font);
teamLPl.setFont(font);
rnLPl.setFont(font);
posLPl.setFont(font);
saisonSLPl.setFont(font);
saisonELPl.setFont(font);
vnTFPl.setFont(font);
nnTFPl.setFont(font);
aliasTFPl.setFont(font);
gebDatTFPl.setFont(font);
grTFPl.setFont(font);
gewTFPl.setFont(font);
teamTFPl.setFont(font);
rnTFPl.setFont(font);
posTFPl.setFont(font);
saisonSTFPl.setFont(font);
saisonETFPl.setFont(font);
createBtnPl.setFont(font);
}
private static MaskFormatter createFormatter(String s) {
MaskFormatter formatter = null;
try {
formatter = new MaskFormatter(s);
} catch (java.text.ParseException e) {
System.exit(-1);
}
return formatter;
}
private static String getLines(String fileName) {
String ges = "";
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = reader.readLine()) != null) {
ges += line;
ges += "\n";
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error reading file: " + e.getMessage(), "FEHLERMELDUNG", JOptionPane.ERROR_MESSAGE);
}
if (ges.endsWith("\n")) {
ges = ges.substring(0, ges.length() - 1);
}
return ges;
}
public static void formatLabel(MyLabel hl, MyLabel ghl,MyLabel al, MyLabel gal,int sX, int sY, int wS, int wL, int h, int hG, String textSH, String textLH, String textSA, String textLA) {
hl.addMouseListener(new MouseListener() {
@Override
public void mouseEntered(MouseEvent e) {
int gray = 92, white = 255;
hl.setText(textLH.toUpperCase());
hl.setBounds(sX, sY, wL, h);
hl.centerText();
cursorBounds(hl,al,ghl,gal);
panelO.add(ghl);
ghl.setFont(hl.getFont());
ghl.setBackground(new Color(gray,gray,gray));
ghl.setForeground(new Color(white,white,white));
gal.setFont(hl.getFont());
gal.setBackground(new Color(gray,gray,gray));
gal.setForeground(new Color(white,white,white));
al.setText(textLA.toUpperCase());
}
@Override
public void mouseExited(MouseEvent e) {
hl.setText(textSH.toUpperCase());
hl.setBounds(sX, sY, wS, h);
hl.centerText();
ghl.setBounds(sX,sY + h,wS,hG);
ghl.setFont(goalFont);
ghl.setBackground(hl.getBackground());
ghl.setForeground(hl.getForeground());
al.setText(textSA.toUpperCase());
al.setBounds(sX + wS,sY,wS,h);
gal.setBounds(sX + wS,sY + h,wS,hG);
gal.setFont(goalFont);
gal.setBackground(al.getBackground());
gal.setForeground(al.getForeground());
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
});
al.addMouseListener(new MouseListener() {
@Override
public void mouseEntered(MouseEvent e) {
int gray = 92, white = 255;
hl.setText(textLH.toUpperCase());
hl.setBounds(sX, sY, wL, h);
hl.centerText();
cursorBounds(hl,al,ghl,gal);
panelO.add(ghl);
ghl.setFont(hl.getFont());
ghl.setBackground(new Color(gray,gray,gray));
ghl.setForeground(new Color(white,white,white));
gal.setFont(hl.getFont());
gal.setBackground(new Color(gray,gray,gray));
gal.setForeground(new Color(white,white,white));
al.setText(textLA.toUpperCase());
}
@Override
public void mouseExited(MouseEvent e) {
hl.setText(textSH.toUpperCase());
hl.setBounds(sX, sY, wS, h);
hl.centerText();
ghl.setBounds(sX,sY + h,wS,hG);
ghl.setFont(goalFont);
ghl.setBackground(hl.getBackground());
ghl.setForeground(hl.getForeground());
al.setText(textSA.toUpperCase());
al.setBounds(sX + wS,sY,wS,h);
gal.setBounds(sX + wS,sY + h,wS,hG);
gal.setFont(goalFont);
gal.setBackground(al.getBackground());
gal.setForeground(al.getForeground());
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
});
}
private static void createLabel(int i, int sXH,int sXA,String home, String away, MyLabel hl, MyLabel ghl, MyLabel al, MyLabel gal) {
int widthS = 75, widthL = 300, height = 40, heightG = 60;
String shortnameH, shortnameA;
String dirh = getWorkingDir() + "/Fussball/Vereine/" + home + ".txt";
String dira = getWorkingDir() + "/Fussball/Vereine/" + away + ".txt";
String colorsH = getLines(dirh);
String colorsA = getLines(dira);
String[] colH = colorsH.split("\n");
String[] colA = colorsA.split("\n");
colH[0] = colH[0].substring(colH[0].indexOf("farbe: ") + length("farbe: "));
colH[1] = colH[1].substring(colH[1].indexOf("farbe: ") + length("farbe: "));
colH[2] = colH[2].substring(colH[2].indexOf("Kürzel: ") + length("Kürzel: "));
colA[0] = colA[0].substring(colA[0].indexOf("farbe: ") + length("farbe: "));
colA[1] = colA[1].substring(colA[1].indexOf("farbe: ") + length("farbe: "));
colA[2] = colA[2].substring(colA[2].indexOf("Kürzel: ") + length("Kürzel: "));
shortnameH = colH[2];
shortnameA = colA[2];
int[] fontcodeH = hexToRgb(colH[0]);
int[] bgcodeH = hexToRgb(colH[1]);
int[] fontcodeA = hexToRgb(colA[0]);
int[] bgcodeA = hexToRgb(colA[1]);
MyColor fontcH = new MyColor(fontcodeH[0], fontcodeH[1], fontcodeH[2]);
MyColor bgcH = new MyColor(bgcodeH[0], bgcodeH[1], bgcodeH[2]);
MyColor fontcA = new MyColor(fontcodeA[0], fontcodeA[1], fontcodeA[2]);
MyColor bgcA = new MyColor(bgcodeA[0], bgcodeA[1], bgcodeA[2]);
hl.setText(shortnameH);
hl.centerText();
hl.setBackground(bgcH);
hl.setForeground(fontcH);
hl.setFont(font);
hl.setBounds(sXH, i * (heightG + height) + 50, widthS, height);
hl.setOpaque(true);
al.setText(shortnameA);
al.centerText();
al.setBackground(bgcA);
al.setForeground(fontcA);
al.setFont(font);
al.setBounds(sXA, i * (heightG + height) + 50, widthS, height);
al.setOpaque(true);
ghl.setBounds(sXH, i * (heightG + height) + height + 50, widthS, heightG);
gal.setBounds(sXA, i * (heightG + height) + height + 50, widthS, heightG);
formatLabel(hl, ghl, al, gal, sXH, i * (heightG + height) + 50, widthS, widthL, height, heightG,shortnameH, home, shortnameA,away);
}
private String readSoccerFiles(String path) {
String ges = "";
try (FileReader fileReader = new FileReader(path);
BufferedReader bufferedReader = new BufferedReader(fileReader)) {
String line;
while ((line = bufferedReader.readLine()) != null) {
ges += line + "\n";
}
} catch (IOException e) {
System.out.println("Error reading file: " + e.getMessage());
}
return ges;
}
private static void writePlayerFile(String path, String text) {
try {
FileWriter writer = new FileWriter(path);
writer.write(text);
writer.close();
} catch (IOException e) {
System.out.println("Fehler beim Schreiben des Textes in die Datei: " + e.getMessage());
}
}
public static void createMD(){
int teams = 0;
for(int i = 1963; i < 2023; i++){
String dir = getWorkingDir() + "/Fussball/Saisons/Saison " + i + "-" + (i + 1) + "/Spieltage";
if(i < 1965){
teams = 16;
}else if(i > 1964 && i != 1991){
teams = 18;
}else{
teams = 20;
}
for(int j = 1; j <= (teams - 1) * 2; j ++){
String js = Integer.toString(j);
if(js.length() == 1){
js = "0" + js;
}
File f = new File(dir + "/" + js + ". Spieltag");
if (!f.exists()){
f.mkdir();
}
}
}
}
}
Meine Scrollbar funktioniert leider nicht und ich finde den Fehler nicht
import myjava.awt.MyColor;
import myjava.swing.*;
import javax.swing.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.text.MaskFormatter;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import static myjava.awt.MyColor.hexToRgb;
import static myjava.data.MyFile.getWorkingDir;
import static myjava.sport.BundesligaGames.length;
public class BundesligaStartup extends MyFrame {
private static int startXPl = 10, startYPl = 10, widthLPl = 320, widthTFPl = 200, heightPl = 30;
private static JPanel panelCB = new JPanel();
private static JPanel panelO = new JPanel();
private static JComboBox<String> comboBoxSaison = new JComboBox<>(new String[]{"Saison"});
private static JComboBox<String> comboBoxSpieltage = new JComboBox<>(new String[]{"Spieltag"});
private static String dirPl = getWorkingDir() + "/Fussball/Saisons/";
private static String home,away,goalsH,goalsA;
private static String selItSaison,selItSpieltage;
private static String[] itemsSaison,itemsSpieltage,matches;
private static String create = "ERSTELLEN";
private static String edit = "BEARBEITEN";
private static String settings = "EINSTELLUNGEN";
private static String player = "SPIELER";
private static String manager = "TRAINER";
private static String team = "VEREIN";
private static MyLabel [] labelHome = new MyLabel[100], labelAway = new MyLabel[100],labelGoalsHome = new MyLabel[100], labelGoalsAway = new MyLabel[100];
public static Font font = new Font("Bundesliga", Font.BOLD, 20);
public static Font goalFont = new Font(font.getName(),font.getStyle(),50);
public static Font menuFont = new Font(font.getName(), font.getStyle(), 15);
private static MyButton createBtnPl = new MyButton("Erstellen");
private static MyFrame framePl = new MyFrame("Neuen Spieler erstellen");
private static String dateFormat = "##.##.####", rnFormat = "##", persFormat = "###";
private static String vnPl, nnPl, aliasPl, teamPl, posPl, gebDatPl, saisonSPl, saisonEPl, grPl, gewPl, rnPl;
private static MyLabel vnLPl = new MyLabel("Vorname:"), nnLPl = new MyLabel("Nachname:"),
aliasLPl = new MyLabel("Alias:"), gebDatLPl = new MyLabel("Geburtsdatum:"),
grLPl = new MyLabel("Größe (cm):"), gewLPl = new MyLabel("Gewicht (kg):"),
teamLPl = new MyLabel("Verein:"), rnLPl = new MyLabel("Rückennummer:"),
posLPl = new MyLabel("Position:"),
saisonSLPl = new MyLabel("Im Verein seit (nur aktuelle Saison):"),
saisonELPl = new MyLabel("Im Verein bis (nur aktuelle Saison):");
private static MyTextField vnTFPl = new MyTextField(), nnTFPl = new MyTextField(),
aliasTFPl = new MyTextField(),
teamTFPl = new MyTextField(),
posTFPl = new MyTextField();
private static MyFormattedTextField
gebDatTFPl = new MyFormattedTextField(createFormatter(dateFormat)),
grTFPl = new MyFormattedTextField(createFormatter(persFormat)),
gewTFPl = new MyFormattedTextField(createFormatter(persFormat)),
rnTFPl = new MyFormattedTextField(createFormatter(rnFormat)),
saisonSTFPl = new MyFormattedTextField(createFormatter(dateFormat)),
saisonETFPl = new MyFormattedTextField(createFormatter(dateFormat));
public BundesligaStartup(int width,int height) {
setBounds(0, 0, width, height);
setTitle("Startmenü");
NullLayout();
EXIT_ON_CLOSE();
notResizable();
createMenu();
panelCB.setBounds(0,0,width,50);
panelO.setBounds(0,50,width, height);
JScrollPane scrollPane = new JScrollPane(panelO);
scrollPane.setBounds(0, 50, 900, height - 300);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
add(scrollPane);
addComboBoxActionListener();
panelCB.setLayout(null);
panelO.setLayout(null);
comboBoxSaison.setBounds(10,10,125,30);
comboBoxSaison.setFont(new Font(font.getName(),font.getStyle(),12));
comboBoxSpieltage.setBounds(140,10,110,30);
comboBoxSpieltage.setFont(new Font(font.getName(),font.getStyle(),12));
panelCB.add(comboBoxSaison);
panelCB.add(comboBoxSpieltage);
add(panelCB);
open();
}
private void addComboBoxActionListener() {
String dir = getWorkingDir() + "/Fussball/Spiele/Saisons";
File f = new File(dir);
File[] farr = f.listFiles();
itemsSaison = new String[f.listFiles().length];
for (int i = 0; i < farr.length; i++){
itemsSaison = farr.toString().replace("/","\\");
}
for (int i = 0; i < farr.length; i++){
String d = dir.replace("/","\\");
itemsSaison = itemsSaison.replace(d + "\\","");
}
comboBoxSaison.setModel(new DefaultComboBoxModel<>(itemsSaison));
comboBoxSaison.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selItSaison = (String) comboBoxSaison.getSelectedItem();
String dirs = dir + "/" + selItSaison + "/Spieltage";
File fs = new File(dirs);
File[] farrs = fs.listFiles();
itemsSpieltage = new String[fs.listFiles().length];
for (int i = 0; i < farrs.length; i++){
itemsSpieltage = farrs.toString().replace("/","\\");
}
for (int i = 0; i < farrs.length; i++){
String d = dirs.replace("/","\\");
itemsSpieltage = itemsSpieltage.replace(d + "\\","");
}
comboBoxSpieltage.setModel(new DefaultComboBoxModel<>(itemsSpieltage));
}
});
comboBoxSpieltage.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
selItSpieltage = (String) comboBoxSpieltage.getSelectedItem();
String dirsp = dir + "/" + selItSaison + "/Spieltage/" + selItSpieltage;
File fsp = new File(dirsp);
File[] farrsp = fsp.listFiles();
matches = new String[fsp.listFiles().length];
labelHome = new MyLabel[matches.length];
labelAway = new MyLabel[matches.length];
labelGoalsHome = new MyLabel[matches.length];
labelGoalsAway = new MyLabel[matches.length];
for (int i = 0; i < farrsp.length; i++){
matches = farrsp.toString().replace("/","\\");
}
for (int i = 0; i < farrsp.length; i++){
int sXH = 10, width = 75, sXA = sXH + width, heightT = 100;
String d = dirsp.replace("/","\\");
matches = matches.replace(d + "\\","");
home = matches.substring(0,matches.indexOf("-"));
away = matches.substring(matches.indexOf("-") + 1,matches.indexOf(".match"));
labelHome = new MyLabel();
labelAway = new MyLabel();
labelGoalsHome = new MyLabel();
labelGoalsAway = new MyLabel();
labelHome.setBounds(sXH,heightT * (i + 1) + 20,100,10);
System.out.println(labelHome.getX());
System.out.println(labelHome.getX());
labelAway.setBounds(sXA,heightT * (i + 1) + 20,100,10);
panelO.add(labelHome);
panelO.add(labelAway);
labelHome.setText(home);
labelGoalsHome.setBounds(sXH + 2 * width,labelHome.getY(),width,heightT);
labelGoalsAway.setBounds(sXA + 2 * width,labelAway.getY(),width,heightT);
panelO.add(labelGoalsHome);
panelO.add(labelGoalsAway);
createLabel(i, sXH,sXA,home,away,labelHome,labelGoalsHome,labelAway,labelGoalsAway);
panelO.add(labelAway);
String text = readSoccerFiles(dirsp + "/" + matches);
if(text.endsWith("\n")) {
text = text.substring(0,text.length() - 1);
}
String[] goals = text.split("-");
goalsH = goals[0];
goalsA = goals[1];
MyColor homebc = new MyColor(labelHome.getBackground().getRed(),labelHome.getBackground().getGreen(),labelHome.getBackground().getBlue());
MyColor homefc = new MyColor(labelHome.getForeground().getRed(),labelHome.getForeground().getGreen(),labelHome.getForeground().getBlue());
MyColor awaybc = new MyColor(labelAway.getBackground().getRed(),labelAway.getBackground().getGreen(),labelAway.getBackground().getBlue());
MyColor awayfc = new MyColor(labelAway.getForeground().getRed(),labelAway.getForeground().getGreen(),labelAway.getForeground().getBlue());
labelGoalsHome.setFont(goalFont);
labelGoalsHome.setText(goalsH);
labelGoalsHome.centerText();
labelGoalsHome.setOpaque(true);
labelGoalsHome.setBackground(homebc);
labelGoalsHome.setForeground(homefc);
labelGoalsAway.setFont(goalFont);
labelGoalsAway.setText(goalsA);
labelGoalsAway.centerText();
labelGoalsAway.setOpaque(true);
labelGoalsAway.setBackground(awaybc);
labelGoalsAway.setForeground(awayfc);
panelO.add(labelGoalsHome);
panelO.add(labelGoalsAway);
}
}
});
}
private void createMenu() {
JMenuBar menuBar = new JMenuBar();
//Settings-Menu
JMenu settingsMenu = new JMenu(settings);
settingsMenu.setFont(menuFont);
//Player-Menu
JMenuItem playerItem = new JMenu(player);
playerItem.setFont(menuFont);
JMenuItem createPlayerItem = new JMenuItem(create);
createPlayerItem.setFont(menuFont);
playerItem.add(createPlayerItem);
JMenuItem editPlayerItem = new JMenuItem(edit);
editPlayerItem.setFont(menuFont);
playerItem.add(editPlayerItem);
//Manager-Menu
JMenuItem managerItem = new JMenu(manager);
managerItem.setFont(menuFont);
JMenuItem createManagerItem = new JMenuItem(create);
createManagerItem.setFont(menuFont);
managerItem.add(createManagerItem);
JMenuItem editManagerItem = new JMenuItem(edit);
editManagerItem.setFont(menuFont);
managerItem.add(editManagerItem);
//Team-Menu
JMenuItem teamItem = new JMenu(team);
teamItem.setFont(menuFont);
JMenuItem createTeamItem = new JMenuItem(create);
createTeamItem.setFont(menuFont);
teamItem.add(createTeamItem);
JMenuItem editTeamItem = new JMenuItem(edit);
editTeamItem.setFont(menuFont);
teamItem.add(editTeamItem);
//add to Settings
settingsMenu.add(playerItem);
settingsMenu.add(managerItem);
settingsMenu.add(teamItem);
//add functions
addCreatePlayer(createPlayerItem);
addEditPlayer(editPlayerItem);
addCreateManager(createManagerItem);
addCreateTeam(createTeamItem);
menuBar.add(settingsMenu);
setJMenuBar(menuBar);
}
private void addCreateTeam(JMenuItem createTeamItem) {
}
private void addCreateManager(JMenuItem createManagerItem) {
}
private void addCreatePlayer(JMenuItem createPlayerItem) {
createPlayerItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
framePl.setSize(600, 550);
framePl.NullLayout();
framePl.HIDE_ON_CLOSE();
framePl.notResizable();
setFontPlayer();
setBoundsPlayer();
addToPlayerFrame();
addActionListenerCreatePlayerButton();
framePl.open();
}
});
}
private void addEditPlayer(JMenuItem editPlayerItem) {
editPlayerItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser jfc = new JFileChooser();
File startDir = new File(getWorkingDir() + "/Fussball/Saisons");
jfc.setCurrentDirectory(startDir);
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File f) {
String fileName = f.getName();
return fileName.endsWith(".player") || f.isDirectory();
}
@Override
public String getDescription() {
return "Player files (*.player)";
}
};
jfc.setFileFilter(filter);
int res = jfc.showOpenDialog(null);
if (res == JFileChooser.APPROVE_OPTION) {
File selectedFile = jfc.getSelectedFile();
String textPl = readSoccerFiles(selectedFile.getAbsolutePath());
String[] splitedPl = textPl.split("\n");
framePl.setTitle("vorhandenen Spieler bearbeiten");
vnTFPl.setText(text(splitedPl, 0, ":", 2));
nnTFPl.setText(text(splitedPl, 1, ":", 2));
aliasTFPl.setText(text(splitedPl, 2, ":", 2));
gebDatTFPl.setText(text(splitedPl, 3, ":", 2));
grTFPl.setText(text(splitedPl, 4, ":", 2));
gewTFPl.setText(text(splitedPl, 5, ":", 2));
teamTFPl.setText(text(splitedPl, 6, ":", 2));
rnTFPl.setText(text(splitedPl, 7, ":", 2));
posTFPl.setText(text(splitedPl, 8, ":", 2));
saisonSTFPl.setText(text(splitedPl, 9, ":", 2));
saisonETFPl.setText(text(splitedPl, 10, ":", 2));
framePl.setSize(600, 550);
framePl.NullLayout();
framePl.HIDE_ON_CLOSE();
framePl.notResizable();
setFontPlayer();
setBoundsPlayer();
addToPlayerFrame();
addActionListenerCreatePlayerButton();
framePl.open();
} else if (res == JFileChooser.CANCEL_OPTION) {
}
}
});
}
public static String text(String[] s, int i, String find, int add) {
if (add >= 0) {
return s.substring(s.indexOf(find) + add);
} else {
return s.substring(s.indexOf(find) - add);
}
}
private void addActionListenerCreatePlayerButton() {
createBtnPl.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
vnPl = vnTFPl.getString();
nnPl = nnTFPl.getString();
aliasPl = aliasTFPl.getString();
gebDatPl = gebDatTFPl.getString();
grPl = grTFPl.getString();
gewPl = gewTFPl.getString();
teamPl = teamTFPl.getString();
rnPl = rnTFPl.getString();
posPl = posTFPl.getString();
saisonSPl = saisonSTFPl.getString();
saisonEPl = saisonETFPl.getString();
if (rnPl.startsWith("0")) {
rnPl.replaceFirst("0", "");
}
if (gewPl.startsWith("0")) {
gewPl.replaceFirst("0", "");
}
String ges = vnLPl.getText() + " " + vnPl + "\n"
+ nnLPl.getText() + " " + nnPl + "\n"
+ aliasLPl.getText() + " " + aliasPl + "\n"
+ gebDatLPl.getText() + " " + gebDatPl + "\n"
+ grLPl.getText() + " " + grPl + "\n"
+ gewLPl.getText() + " " + gewPl + "\n"
+ teamLPl.getText() + " " + teamPl + "\n"
+ rnLPl.getText() + " " + rnPl + "\n"
+ posLPl.getText() + " " + posPl + "\n"
+ saisonSLPl.getText() + " " + saisonSPl + "\n"
+ saisonELPl.getText() + " " + saisonEPl + "\n";
int m = Integer.parseInt(saisonSPl.substring(3, 5));
int j = Integer.parseInt(saisonSPl.substring(6, 10));
String datName;
new Player(vnPl, nnPl, aliasPl, gebDatPl, grPl, gewPl, teamPl, rnPl, posPl, saisonSPl, saisonEPl);
if (m < 7) {
dirPl += "Saison " + (j - 1) + "-" + j + "/";
} else {
dirPl += "Saison " + j + "-" + (j + 1) + "/";
}
dirPl += teamPl + "/Spieler/";
if (aliasPl.equals("")) {
datName = vnPl + " " + nnPl + ".player";
} else {
datName = aliasPl + ".player";
}
File plFile = new File(dirPl + datName);
if (!plFile.exists()) {
try {
plFile.createNewFile();
writePlayerFile(dirPl + datName, ges);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
} else {
writePlayerFile(dirPl + datName, ges);
}
framePl.close();
}
});
}
public static void cursorBounds(MyLabel hl, MyLabel al, MyLabel ghl, MyLabel gal){
ghl.setBounds(hl.getX() + hl.getWidth(), hl.getY(),ghl.getWidth(),hl.getHeight());
gal.setBounds(ghl.getX() + ghl.getWidth(),hl.getY(),gal.getWidth(),hl.getHeight());
al.setBounds(gal.getX() + gal.getWidth(),hl.getY(),hl.getWidth(),hl.getHeight());
}
private void addToPlayerFrame() {
framePl.add(vnLPl);
framePl.add(nnLPl);
framePl.add(aliasLPl);
framePl.add(gebDatLPl);
framePl.add(grLPl);
framePl.add(gewLPl);
framePl.add(teamLPl);
framePl.add(rnLPl);
framePl.add(posLPl);
framePl.add(saisonSLPl);
framePl.add(saisonELPl);
framePl.add(vnTFPl);
framePl.add(nnTFPl);
framePl.add(aliasTFPl);
framePl.add(gebDatTFPl);
framePl.add(grTFPl);
framePl.add(gewTFPl);
framePl.add(teamTFPl);
framePl.add(rnTFPl);
framePl.add(posTFPl);
framePl.add(saisonSTFPl);
framePl.add(saisonETFPl);
framePl.add(createBtnPl);
}
private void setBoundsPlayer() {
vnLPl.setBounds(startXPl, startYPl, widthLPl, heightPl);
nnLPl.setBounds(startXPl, startYPl + heightPl + startXPl, widthLPl, heightPl);
aliasLPl.setBounds(startXPl, startYPl + 2 * (heightPl + startXPl), widthLPl, heightPl);
gebDatLPl.setBounds(startXPl, startYPl + 3 * (heightPl + startXPl), widthLPl, heightPl);
grLPl.setBounds(startXPl, startYPl + 4 * (heightPl + startXPl), widthLPl, heightPl);
gewLPl.setBounds(startXPl, startYPl + 5 * (heightPl + startXPl), widthLPl, heightPl);
teamLPl.setBounds(startXPl, startYPl + 6 * (heightPl + startXPl), widthLPl, heightPl);
rnLPl.setBounds(startXPl, startYPl + 7 * (heightPl + startXPl), widthLPl, heightPl);
posLPl.setBounds(startXPl, startYPl + 8 * (heightPl + startXPl), widthLPl, heightPl);
saisonSLPl.setBounds(startXPl, startYPl + 9 * (heightPl + startXPl), widthLPl, heightPl);
saisonELPl.setBounds(startXPl, startYPl + 10 * (heightPl + startXPl), widthLPl, heightPl);
vnTFPl.setBounds(startXPl + widthLPl + 10, startYPl, widthTFPl, heightPl);
nnTFPl.setBounds(startXPl + widthLPl + 10, startYPl + heightPl + startXPl, widthTFPl, heightPl);
aliasTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 2 * (heightPl + startXPl), widthTFPl, heightPl);
gebDatTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 3 * (heightPl + startXPl), widthTFPl, heightPl);
grTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 4 * (heightPl + startXPl), widthTFPl, heightPl);
gewTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 5 * (heightPl + startXPl), widthTFPl, heightPl);
teamTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 6 * (heightPl + startXPl), widthTFPl, heightPl);
rnTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 7 * (heightPl + startXPl), widthTFPl, heightPl);
posTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 8 * (heightPl + startXPl), widthTFPl, heightPl);
saisonSTFPl.setBounds(startXPl + widthLPl + 10, startYPl + 9 * (heightPl + startXPl), widthTFPl, heightPl);
saisonETFPl.setBounds(startXPl + widthLPl + 10, startYPl + 10 * (heightPl + startXPl), widthTFPl, heightPl);
createBtnPl.setBounds(startXPl + widthLPl + 10, startYPl + 11 * (heightPl + startXPl), widthTFPl, heightPl);
}
private void setFontPlayer() {
vnLPl.setFont(font);
nnLPl.setFont(font);
aliasLPl.setFont(font);
gebDatLPl.setFont(font);
grLPl.setFont(font);
gewLPl.setFont(font);
teamLPl.setFont(font);
rnLPl.setFont(font);
posLPl.setFont(font);
saisonSLPl.setFont(font);
saisonELPl.setFont(font);
vnTFPl.setFont(font);
nnTFPl.setFont(font);
aliasTFPl.setFont(font);
gebDatTFPl.setFont(font);
grTFPl.setFont(font);
gewTFPl.setFont(font);
teamTFPl.setFont(font);
rnTFPl.setFont(font);
posTFPl.setFont(font);
saisonSTFPl.setFont(font);
saisonETFPl.setFont(font);
createBtnPl.setFont(font);
}
private static MaskFormatter createFormatter(String s) {
MaskFormatter formatter = null;
try {
formatter = new MaskFormatter(s);
} catch (java.text.ParseException e) {
System.exit(-1);
}
return formatter;
}
private static String getLines(String fileName) {
String ges = "";
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {
String line;
while ((line = reader.readLine()) != null) {
ges += line;
ges += "\n";
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error reading file: " + e.getMessage(), "FEHLERMELDUNG", JOptionPane.ERROR_MESSAGE);
}
if (ges.endsWith("\n")) {
ges = ges.substring(0, ges.length() - 1);
}
return ges;
}
public static void formatLabel(MyLabel hl, MyLabel ghl,MyLabel al, MyLabel gal,int sX, int sY, int wS, int wL, int h, int hG, String textSH, String textLH, String textSA, String textLA) {
hl.addMouseListener(new MouseListener() {
@Override
public void mouseEntered(MouseEvent e) {
int gray = 92, white = 255;
hl.setText(textLH.toUpperCase());
hl.setBounds(sX, sY, wL, h);
hl.centerText();
cursorBounds(hl,al,ghl,gal);
panelO.add(ghl);
ghl.setFont(hl.getFont());
ghl.setBackground(new Color(gray,gray,gray));
ghl.setForeground(new Color(white,white,white));
gal.setFont(hl.getFont());
gal.setBackground(new Color(gray,gray,gray));
gal.setForeground(new Color(white,white,white));
al.setText(textLA.toUpperCase());
}
@Override
public void mouseExited(MouseEvent e) {
hl.setText(textSH.toUpperCase());
hl.setBounds(sX, sY, wS, h);
hl.centerText();
ghl.setBounds(sX,sY + h,wS,hG);
ghl.setFont(goalFont);
ghl.setBackground(hl.getBackground());
ghl.setForeground(hl.getForeground());
al.setText(textSA.toUpperCase());
al.setBounds(sX + wS,sY,wS,h);
gal.setBounds(sX + wS,sY + h,wS,hG);
gal.setFont(goalFont);
gal.setBackground(al.getBackground());
gal.setForeground(al.getForeground());
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
});
al.addMouseListener(new MouseListener() {
@Override
public void mouseEntered(MouseEvent e) {
int gray = 92, white = 255;
hl.setText(textLH.toUpperCase());
hl.setBounds(sX, sY, wL, h);
hl.centerText();
cursorBounds(hl,al,ghl,gal);
panelO.add(ghl);
ghl.setFont(hl.getFont());
ghl.setBackground(new Color(gray,gray,gray));
ghl.setForeground(new Color(white,white,white));
gal.setFont(hl.getFont());
gal.setBackground(new Color(gray,gray,gray));
gal.setForeground(new Color(white,white,white));
al.setText(textLA.toUpperCase());
}
@Override
public void mouseExited(MouseEvent e) {
hl.setText(textSH.toUpperCase());
hl.setBounds(sX, sY, wS, h);
hl.centerText();
ghl.setBounds(sX,sY + h,wS,hG);
ghl.setFont(goalFont);
ghl.setBackground(hl.getBackground());
ghl.setForeground(hl.getForeground());
al.setText(textSA.toUpperCase());
al.setBounds(sX + wS,sY,wS,h);
gal.setBounds(sX + wS,sY + h,wS,hG);
gal.setFont(goalFont);
gal.setBackground(al.getBackground());
gal.setForeground(al.getForeground());
}
@Override
public void mouseClicked(MouseEvent e) {
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
});
}
private static void createLabel(int i, int sXH,int sXA,String home, String away, MyLabel hl, MyLabel ghl, MyLabel al, MyLabel gal) {
int widthS = 75, widthL = 300, height = 40, heightG = 60;
String shortnameH, shortnameA;
String dirh = getWorkingDir() + "/Fussball/Vereine/" + home + ".txt";
String dira = getWorkingDir() + "/Fussball/Vereine/" + away + ".txt";
String colorsH = getLines(dirh);
String colorsA = getLines(dira);
String[] colH = colorsH.split("\n");
String[] colA = colorsA.split("\n");
colH[0] = colH[0].substring(colH[0].indexOf("farbe: ") + length("farbe: "));
colH[1] = colH[1].substring(colH[1].indexOf("farbe: ") + length("farbe: "));
colH[2] = colH[2].substring(colH[2].indexOf("Kürzel: ") + length("Kürzel: "));
colA[0] = colA[0].substring(colA[0].indexOf("farbe: ") + length("farbe: "));
colA[1] = colA[1].substring(colA[1].indexOf("farbe: ") + length("farbe: "));
colA[2] = colA[2].substring(colA[2].indexOf("Kürzel: ") + length("Kürzel: "));
shortnameH = colH[2];
shortnameA = colA[2];
int[] fontcodeH = hexToRgb(colH[0]);
int[] bgcodeH = hexToRgb(colH[1]);
int[] fontcodeA = hexToRgb(colA[0]);
int[] bgcodeA = hexToRgb(colA[1]);
MyColor fontcH = new MyColor(fontcodeH[0], fontcodeH[1], fontcodeH[2]);
MyColor bgcH = new MyColor(bgcodeH[0], bgcodeH[1], bgcodeH[2]);
MyColor fontcA = new MyColor(fontcodeA[0], fontcodeA[1], fontcodeA[2]);
MyColor bgcA = new MyColor(bgcodeA[0], bgcodeA[1], bgcodeA[2]);
hl.setText(shortnameH);
hl.centerText();
hl.setBackground(bgcH);
hl.setForeground(fontcH);
hl.setFont(font);
hl.setBounds(sXH, i * (heightG + height) + 50, widthS, height);
hl.setOpaque(true);
al.setText(shortnameA);
al.centerText();
al.setBackground(bgcA);
al.setForeground(fontcA);
al.setFont(font);
al.setBounds(sXA, i * (heightG + height) + 50, widthS, height);
al.setOpaque(true);
ghl.setBounds(sXH, i * (heightG + height) + height + 50, widthS, heightG);
gal.setBounds(sXA, i * (heightG + height) + height + 50, widthS, heightG);
formatLabel(hl, ghl, al, gal, sXH, i * (heightG + height) + 50, widthS, widthL, height, heightG,shortnameH, home, shortnameA,away);
}
private String readSoccerFiles(String path) {
String ges = "";
try (FileReader fileReader = new FileReader(path);
BufferedReader bufferedReader = new BufferedReader(fileReader)) {
String line;
while ((line = bufferedReader.readLine()) != null) {
ges += line + "\n";
}
} catch (IOException e) {
System.out.println("Error reading file: " + e.getMessage());
}
return ges;
}
private static void writePlayerFile(String path, String text) {
try {
FileWriter writer = new FileWriter(path);
writer.write(text);
writer.close();
} catch (IOException e) {
System.out.println("Fehler beim Schreiben des Textes in die Datei: " + e.getMessage());
}
}
public static void createMD(){
int teams = 0;
for(int i = 1963; i < 2023; i++){
String dir = getWorkingDir() + "/Fussball/Saisons/Saison " + i + "-" + (i + 1) + "/Spieltage";
if(i < 1965){
teams = 16;
}else if(i > 1964 && i != 1991){
teams = 18;
}else{
teams = 20;
}
for(int j = 1; j <= (teams - 1) * 2; j ++){
String js = Integer.toString(j);
if(js.length() == 1){
js = "0" + js;
}
File f = new File(dir + "/" + js + ". Spieltag");
if (!f.exists()){
f.mkdir();
}
}
}
}
}
Meine Scrollbar funktioniert leider nicht und ich finde den Fehler nicht