Scrollbar funktioniert nicht

MJannek

Mitglied
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
 

MJannek

Mitglied
ich habe in einem Orderner getWorkingDir() + "/Fussball/Vereine" u.a. diese Dateien und im Ordner dir + "/Saison 2022-2023/Spieltage/01. Spieltag Dateien nach dem Muster "home-away.match" mit dem Spielergebnis als Inhalt (z.B. 0-0)
 

Anhänge

  • 1. FC Kaiserslautern.txt
    62 Bytes · Aufrufe: 0
  • 1. FC Nürnberg.txt
    62 Bytes · Aufrufe: 0
  • 1. FC Union Berlin.txt
    62 Bytes · Aufrufe: 1
  • 1. FSV Mainz 05.txt
    62 Bytes · Aufrufe: 0
  • Bayer 04 Leverkusen.txt
    62 Bytes · Aufrufe: 0
  • Borussia Dortmund.txt
    62 Bytes · Aufrufe: 0
  • Borussia Mönchengladbach.txt
    62 Bytes · Aufrufe: 0
  • DSC Arminia Bielefeld.txt
    62 Bytes · Aufrufe: 0

KonradN

Super-Moderator
Mitarbeiter
Code bitte immer in Code Tags posten. Dazu am einfachsten den Knopf </> links oberhalb des Eingabebereiches nutzen.
 

MJannek

Mitglied
Java:
Java - Hilfe | Java-Forum.org
 AWT, Swing, JavaFX & SWT
Scrollbar funktioniert nicht
 ThemenstarterMJannek  BeginndatumHeute um 21:29
Springe zu neuem
Nicht weiter beobachten
Neues Thema erstellen
MJannek
Mitglied
Heute um 21:29
Add bookmark
#1
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();
}

}

}
}
}
 

KonradN

Super-Moderator
Mitarbeiter
Es bringt nichts, den Code aus dem Post in Code-Tags zu kopieren.
a) bekommt man dadurch keine Formatierung
b) kommen so z.B. die [i] nicht zurück

Beispiel:
Aus Deinem Code
for (int i = 0; i < farrsp.length; i++){
matches = farrsp.toString().replace("/","\\");

}
würde dann bestimmt
Java:
for (int i = 0; i < farrsp.length; i++){
    matches[i] = farrsp[i].toString().replace("/","\\");
}
werden.

Ich habe mir den Code gestern noch etwas angesehen und er ist so nur sehr schwer zu lesen. Selbst mit der Behebung offensichtlicher Probleme wie diese fehlenden Array Zugriffe und einer vernünftigen Formatierung:
a) Die Fehlerbeschreibung ist extrem dürftig. Ich vermute, dass es um die ScollPane geht, die Du in Zeile 101 - 105 setzt:
Code:
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);
Aber die Beschreibung ist zu dürftig um da dann über die Beschreibung etwas zu finden.

b) Du hast einige Klassen, die wir nicht haben. Damit können wir das auch nicht irgendwie ausprobieren um zu schauen, ob wir sehen, was Du uns eben nicht gesagt hast.

Daher ist es zumindest mir nicht möglich, da irgend einen Fehler zu finden.

Vielleicht ein paar Tipps:
  • Mache Dich etwas mit den Layouts vertraut. https://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html oder selbst mal danach suchen. Das ist deutlich besser, als da immer absolute Werte bei den Controls anzugeben. Das hat diverse Vorteile - z.B. dass die Komponenten sauber angeordnet werden (auch bei Skallierungen und so).
  • Die ganzen static solltest Du Dir dringend abgewöhnen. Das macht Code schlicht unwartbar und begrenzt auch die Nutzbarkeit stark ein.
 

KonradN

Super-Moderator
Mitarbeiter
Im gezeigten Code setzt du nirgends den Inhalt des Scrollpanes
Das wird doch im Konstruktor übergeben. Da übergibt er doch panel0. Und es gibt auch Code, da zu panel0 Controls hinzu fügt.

Und das sollte doch eigentlich prinzipiell ausreichen - denn was anderes macht doch z.B. dieses Tutorial auch nicht:
 

Neumi5694

Top Contributor
Da kommt mir ein Gedanke ... die Größe von panelO wurde mit setBounds festgelegt. Funktioniert das so überhaupt? Gilt das denn nicht nur in einem Null- ober Absolutelayout?
Ich hätte - falls ich überhaupt eine fixe Größe zuweisen wollte - den Weg über PreferredSize gewählt.
 
Ähnliche Java Themen
  Titel Forum Antworten Datum
CptK Ordentlicher Code & Panel ab bestimmter Komponentenzahl scrollbar machen AWT, Swing, JavaFX & SWT 12
ralfb1105 jTextArea Scrollbar hinzufügen - mit Jigloo erstellt AWT, Swing, JavaFX & SWT 7
G Wie Scrollbar einfügen? AWT, Swing, JavaFX & SWT 1
A Swing Panel mit ScrollBar AWT, Swing, JavaFX & SWT 7
M JavaFX TextArea disabled - ScrollBar enabled AWT, Swing, JavaFX & SWT 3
H JavaFX Abstand rechts zur scrollbar AWT, Swing, JavaFX & SWT 1
I Swing Scrollbar AWT, Swing, JavaFX & SWT 2
W Scrollbar in Registerkarte AWT, Swing, JavaFX & SWT 1
M eigene horizontale Scrollbar AWT, Swing, JavaFX & SWT 1
M JTable horizontale scrollbar löschen AWT, Swing, JavaFX & SWT 3
G Scrollbar AWT, Swing, JavaFX & SWT 13
G Scrollbar für das Fenster einfügen AWT, Swing, JavaFX & SWT 3
M Swing JTextArea mit ScrollBar AWT, Swing, JavaFX & SWT 9
A JScrollPane - ScrollBar Buttongröße verändern AWT, Swing, JavaFX & SWT 1
A Scrollbar gestalten AWT, Swing, JavaFX & SWT 2
E JavaFX ScrollBar in TableView bei Column Resize AWT, Swing, JavaFX & SWT 2
T Swing JScrollPane Farbe der Scrollbar AWT, Swing, JavaFX & SWT 3
B Export eines Panel mit ScrollBar AWT, Swing, JavaFX & SWT 4
5 Scrollbar AWT, Swing, JavaFX & SWT 4
M Swing JTextPane + Scrollbar = Fragen AWT, Swing, JavaFX & SWT 15
H Swing JTextPane hat unästhetisches Scrollbar AWT, Swing, JavaFX & SWT 3
M Horizontal Scrollbar wird ignoriert AWT, Swing, JavaFX & SWT 10
M Swing Scrollbar im JFrame (JPanel?) AWT, Swing, JavaFX & SWT 6
W jTable Scrollbar Problem AWT, Swing, JavaFX & SWT 2
A Swing JPanel in JScrollBar scrollbar machen AWT, Swing, JavaFX & SWT 4
M SWT Table disabled und Scrollbar enabled AWT, Swing, JavaFX & SWT 11
P Scrollbar JTextArea AWT, Swing, JavaFX & SWT 23
S SWT GridLayout scrollbar machen? AWT, Swing, JavaFX & SWT 7
0 2D-Grafik Screenshot von ScrollBar-Inhalt AWT, Swing, JavaFX & SWT 2
D JList Scrollbar machen geht nicht AWT, Swing, JavaFX & SWT 4
D Scrollbar für Tabelle AWT, Swing, JavaFX & SWT 2
J Beliebtes Problem: Scrollbar in JTextArea AWT, Swing, JavaFX & SWT 4
S SWT ScrollBar Bug AWT, Swing, JavaFX & SWT 5
B GridLayout und scrollbar AWT, Swing, JavaFX & SWT 5
L Scrollbar übermalt AWT, Swing, JavaFX & SWT 2
H JList in JScrollPane -> ScrollBar ans Ende setzen AWT, Swing, JavaFX & SWT 5
M SWT keine Scrollbar bei widgets.List und GridLayout AWT, Swing, JavaFX & SWT 2
N Swing JTable Überschrift ohen scrollbar? AWT, Swing, JavaFX & SWT 2
R Scrollbar nur ohne STRG AWT, Swing, JavaFX & SWT 4
D Swing Spaltenköpfe verschieben sich nicht mit, wenn man an horizontaler Scrollbar zieht AWT, Swing, JavaFX & SWT 9
A SWT Table hat keine Scrollbar AWT, Swing, JavaFX & SWT 12
P JTextbox mit Scrollbar AWT, Swing, JavaFX & SWT 6
Roumeo Swing jTable mit Scrollbar AWT, Swing, JavaFX & SWT 13
D Swing [Erledigt]Panel mit ScrollBar , anpassbare Größe AWT, Swing, JavaFX & SWT 15
velocity Swing JList Scrollbar passt sich an AWT, Swing, JavaFX & SWT 4
S Scrollbar in einem JTabbedPane AWT, Swing, JavaFX & SWT 4
slawaweis JXTreeTable, jede Spalte einzeln scrollbar machen? AWT, Swing, JavaFX & SWT 2
Spot84 scrollbar die linksbündig angezeigt wird nur anzeigen wenn sie gebraucht wird AWT, Swing, JavaFX & SWT 5
K Größe einer Scrollbar im Dialogfenster ändern AWT, Swing, JavaFX & SWT 2
S Seltsam: SWT Table zeigt keine Scrollbar an AWT, Swing, JavaFX & SWT 12
T JList ScrollBar AWT, Swing, JavaFX & SWT 2
T ScrollBar aus ScrollPane verstecken AWT, Swing, JavaFX & SWT 2
J JList ohne vertikale Scrollbar AWT, Swing, JavaFX & SWT 3
M Scrollbar anpassen (Position) AWT, Swing, JavaFX & SWT 6
T Scrollbar wird nicht angezeigt - aber warum? AWT, Swing, JavaFX & SWT 3
O ScrollBar.setValue(int value); ? AWT, Swing, JavaFX & SWT 3
A JTable Header + ScrollBar AWT, Swing, JavaFX & SWT 4
N eine Zeichnung scrollbar machen AWT, Swing, JavaFX & SWT 4
DeeDee0815 JDesktopPane scrollbar AWT, Swing, JavaFX & SWT 2
ModellbahnerTT Problem mit Scrollbar AWT, Swing, JavaFX & SWT 10
S JTextArea soll mit Scrollbar ausgestattet sein AWT, Swing, JavaFX & SWT 4
Tom299 JScrollPane(JTextArea) Scrollbar soll am Anfang stehen AWT, Swing, JavaFX & SWT 2
S ScrollBar, bitte helft mir! AWT, Swing, JavaFX & SWT 9
G ScrollBar mit Frame verbinden? AWT, Swing, JavaFX & SWT 8
G Scrollbar hinzufügen AWT, Swing, JavaFX & SWT 10
C Grafikkomponente und Scrollbar AWT, Swing, JavaFX & SWT 5
N Scrollbar zu einem Dialog hinzufügen AWT, Swing, JavaFX & SWT 4
M Scrollbar AWT, Swing, JavaFX & SWT 4
L scrollbar von rot nach greun AWT, Swing, JavaFX & SWT 2
L Mehrere Scrollbar objekte miteinander verbinden AWT, Swing, JavaFX & SWT 3
G Wieso wird meine Scrollbar nicht angezeigt? AWT, Swing, JavaFX & SWT 3
M Scrollbar AWT, Swing, JavaFX & SWT 1
W Rat zur GUI - Scrollbar (SWT) AWT, Swing, JavaFX & SWT 2
A SWT: Group Scrollbar machen. AWT, Swing, JavaFX & SWT 5
G Scrollbar größe regeln AWT, Swing, JavaFX & SWT 18
A vertikale Scrollbar AWT, Swing, JavaFX & SWT 6
lhein Breite der Scrollbar in einer Combobox ändern AWT, Swing, JavaFX & SWT 5
K Mouse Events der Scrollbar/pane AWT, Swing, JavaFX & SWT 2
S JTextArea mit Scrollbar,append Text mit Fokus? AWT, Swing, JavaFX & SWT 5
A Update von Frameinhalt und Scrollbar AWT, Swing, JavaFX & SWT 11
M JTextPane mit ScrollBar AWT, Swing, JavaFX & SWT 5
K Scrollbar funzt net :-/ AWT, Swing, JavaFX & SWT 4
T JScrollPane Scrollbar-Position AWT, Swing, JavaFX & SWT 2
R JScrollPane die ScrollBar manipulieren ? AWT, Swing, JavaFX & SWT 3
S keine ScrollBar AWT, Swing, JavaFX & SWT 15
lin Startposition einer ScrollBar AWT, Swing, JavaFX & SWT 2
S scrollbar AWT, Swing, JavaFX & SWT 2
D JList ohne Scrollbar-ich weiss es ist durchgelutscht,aber. AWT, Swing, JavaFX & SWT 3
G Bei JScrollpane statt Scrollbar eine Vorschau verwenden AWT, Swing, JavaFX & SWT 3
B einzelne Zellen scrollbar machen innerhalb einer Tabelle AWT, Swing, JavaFX & SWT 3
javasdann Vertical ScrollBar in JTable verfälscht anzeigen. AWT, Swing, JavaFX & SWT 12
D Scrollbar AWT, Swing, JavaFX & SWT 6
Student JTable - eine fixe Spalte, der Rest scrollbar AWT, Swing, JavaFX & SWT 18
P Scrollbar/Pane auch mit negativen x,y - Werten AWT, Swing, JavaFX & SWT 2
R Wert von ScrollBar ausgeben AWT, Swing, JavaFX & SWT 7
M Scrollbar: Scrollbalken versetzen AWT, Swing, JavaFX & SWT 2
L JTextArea Scrollbar-Problem! AWT, Swing, JavaFX & SWT 2
chik Scrollbar AWT, Swing, JavaFX & SWT 26
L Probleme mit Scrollbar und LayoutManager AWT, Swing, JavaFX & SWT 3
N 2 Fragen (zu binärem Suchen und Scrollbar) AWT, Swing, JavaFX & SWT 6

Ähnliche Java Themen

Neue Themen


Oben