So wie du es beschreibst liegt es zu 90% an meinem schlechten Code, da ich noch ein relativer Programmieranfänger bin.
Der Code lautet wie folgt:
[Java]
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import javax.swing.*;
import java.util.*;
public class CreateWindow extends JFrame {
private static final long serialVersionUID = 1L;
Logic Program = new Logic();
ArrayList <String> salGetConfig = new ArrayList <String> (0);
ButtonGroup JRadioGroup = new ButtonGroup();
ArrayList <JRadioButton> JRButtons = new ArrayList <JRadioButton> (0);
JFrame frame = new JFrame("Vesp.imp Switcher");
JPanel panel = new JPanel();
String [] ICVersions = new String[2];
String sICVersion = "";
String sVespOrdner="";
String ConfigPath = System.getProperty("user.dir");;
String ICPath = "";
int iheight = 50;
String sTFVespFolder = "";
public CreateWindow() throws IOException{
ICVersions[0] = "IC71";
ICVersions[1] = "IC72";
frame.setBounds(460, 230, 300, 360);
frame.setVisible(true);
panel.setLayout(null);
File file = new File(ConfigPath+"/Config.ini");
if(file.exists()){
FileReader File = new FileReader(ConfigPath+"/Config.ini");
BufferedReader read = new BufferedReader(File);
String zeile = "";
while((zeile=read.readLine()) !=null ){
salGetConfig.add(zeile);
}
sTFVespFolder = salGetConfig.get(1);
ICPath = salGetConfig.get(0);
sVespOrdner = salGetConfig.get(1);
}
else{
FileWriter FWriter = new FileWriter(ConfigPath+"/Config.ini");
BufferedWriter Test = new BufferedWriter(FWriter);
Test.write("Erstkonfiguration");
Test.newLine();
Test.write("Erstkonfiguration");
ICPath="Erstkonfiguration";
sTFVespFolder = "Erstkonfiguration";
Test.close();
FWriter.close();
}
}
public void Window() throws IOException{
final JLabel Label = new JLabel("Vesp.imp Switcher") ;
Label.setBounds(90, 13, 178, 20);
frame.add(Label);
final JLabel VespFolder = new JLabel("Vesp Ordner:");
VespFolder.setBounds(30, 245, 105, 20);
frame.add(VespFolder);
final JLabel SetPath = new JLabel("IC Pfad:");
SetPath.setBounds(60, 272, 105, 20);
frame.add(SetPath);
final TextArea TACInf = new TextArea("Copy Information:"+'\n'+""+'\n');
TACInf.setBounds(5, 50, 140, 165);
TACInf.setEditable(false);
frame.add(TACInf);
final JFormattedTextField TFSetPath = new JFormattedTextField(ICPath);
TFSetPath.setBounds(115, 275, 175, 15);
frame.add(TFSetPath);
final JFormattedTextField TFVespFolder = new JFormattedTextField(sTFVespFolder);
TFVespFolder.setBounds(115, 248, 175, 15);
frame.add(TFVespFolder);
final JButton Exit = new JButton("Exit");
Exit.setBounds(220,300,60,20);
frame.add(Exit);
Exit.addActionListener( new ActionListener() {
@Override public void actionPerformed( ActionEvent e ) {
System.exit( 0 );
}
} );
final JComboBox ICVersion = new JComboBox(ICVersions);
ICVersion.setBounds(5, 220, 50, 20);
ICVersion.setSelectedIndex(1);
frame.add(ICVersion);
ICVersion.addActionListener( new ActionListener() {
@Override public void actionPerformed( ActionEvent e ) {
if(ICVersion.getSelectedIndex() == 0){
ICPath = System.getenv("Avaya_"+ICVersions[0]+"_HOME");
if(ICPath == null){
ICPath ="";
TFSetPath.setText(ICPath);
}
else{
if(ICPath == null){
ICPath ="";
TFSetPath.setText(ICPath);
}
else{
TFSetPath.setText(ICPath+"/etc");
}
}
TFSetPath.updateUI();
}
else if(ICVersion.getSelectedIndex() == 1){
ICPath = System.getenv("Avaya_"+ICVersions[1]+"_HOME");
if(ICPath == null){
ICPath ="";
TFSetPath.setText(ICPath);
}
else{
TFSetPath.setText(ICPath+"/etc");
}
}
}
} );
final JButton SaveConfig = new JButton("Save Config");
SaveConfig.setBounds(184, 220, 105, 20);
frame.add(SaveConfig);
SaveConfig.addActionListener( new ActionListener() {
@Override public void actionPerformed( ActionEvent e ) {
try {
Program.WriteConfig(TFSetPath.getText(),TFVespFolder.getText(),ConfigPath);
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
final JButton Refresh = new JButton("Refresh Vesps");
Refresh.setBounds(60, 220, 120, 20);
frame.add(Refresh);
Refresh.addActionListener( new ActionListener() {
@Override public void actionPerformed( ActionEvent e ) {
sVespOrdner = TFVespFolder.getText();
for(int i = 0;i<JRButtons.size();i++){
JRadioGroup.remove( JRButtons.get(i));
}
panel.removeAll();
frame.repaint();
JRButtons.clear();
JRadioGroup = new ButtonGroup();
refreshJRButtons();
}
});
final JButton Apply = new JButton("Apply");
Apply.setBounds(5, 300, 70, 20);
frame.add(Apply);
Apply.addActionListener( new ActionListener() {
@Override public void actionPerformed( ActionEvent e ) {
try {
String Choice = "";
for(int i = 0;i<JRButtons.size();i++){
JRadioButton JRButton = JRButtons.get(i);
if(JRButton.isSelected()){
Choice = JRButton.getName();
}
}
ArrayList <String> CopyInformation = Program.ChangeVesp(TFVespFolder.getText(),TFSetPath.getText(),Choice);
for(int i = 0; i<CopyInformation.size();i++){
TACInf.append(CopyInformation.get(i));
}
}
catch (Exception e1) {
e1.printStackTrace();
}}});
refreshJRButtons();
frame.add(panel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setVisible(true);
}
private void refreshJRButtons(){
iheight = 50;
String []saNumRButtons = Program.getVespsIn(sVespOrdner);
if(saNumRButtons != null){
for(int i =0;i<saNumRButtons.length;i++){
//erstellen des RButtons
JRadioButton RButton = new JRadioButton(saNumRButtons
);
RButton.setName(saNumRButtons);
RButton.setBounds(150, iheight, 400, 20);
//hinzufügen des RButtons
JRButtons.add(RButton);
panel.add(RButton);
JRadioGroup.add(RButton);
panel.repaint();
//Höhenbestimmung + selection
iheight = iheight + 20;
if(RButton.getName().equals("Vesp.imp")||RButton.getName().equals("vesp.imp")){
RButton.setSelected(true);
}
}
}
}
[/Java]
Ich führe repaint() auf die einzelnen Componenten aus, jedoch kein validate(), da es mir bei jedem mal als ich validate() aufgerufen habe meine komlette GUI zerschossen hat... warum auch immer.
Ihr könnt mir auch ruhig sagen, was man an dem Code besser machen kann (Da gibts denk ich ne ganze Menge :autsch