Okay dann hier nochmal mein aktueller Code:
GUI Klasse:
[Java]
import java.awt.Color;
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{
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.setLayout(null);
panel.setLayout(null);
frame.setBounds(460, 230, 300, 360);
panel.setBounds(150,50,150,165);
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 = 55;
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]
und jetzt die Logik Klasse:
[Java]
import java.io.*;
import java.nio.channels.ByteChannel;
import java.nio.channels.FileChannel;
import java.util.*;
public class Logic {
long lBuffer = ((1024*1024)/2);
public Logic(){
}
public void WriteConfig(String ICPath, String VespFolder, String ConfigPath) throws IOException{
try{
DeleteConfig();
FileWriter WriteConfig = new FileWriter(ConfigPath+"/Config.ini");
BufferedWriter writer = new BufferedWriter(WriteConfig);
writer.write(ICPath);
writer.newLine();
writer.write(VespFolder);
writer.close();
WriteConfig.close();
}
catch(FileNotFoundException e){
System.out.println("Die Datei konnte nicht gefunden werden");
}
}
private void DeleteConfig(){
File Config = new File("C:/Dokumente und Einstellungen/mallgaier/Desktop/Config.ini");
Config.delete();
}
public String[] getVespsIn(String sVespOrdner){
File dir = new File(sVespOrdner);
String[] Files = dir.list(new FilenameFilter() {
public boolean accept(File d, String name) {
return name.endsWith(".imp");
}
});
return Files;
}
public ArrayList <String> ChangeVesp(String SourcePath,String DestPath,String Choice) throws Exception{
ArrayList <String> CopyInformation = new ArrayList <String> (0);
File source = new File((SourcePath+"/"+Choice));
File destination = new File(DestPath+"/Vesp.imp");
FileInputStream fileInputStream = new FileInputStream(source);
FileOutputStream fileOutputStream = new FileOutputStream(destination);
FileChannel inputChannel = fileInputStream.getChannel();
FileChannel outputChannel = fileOutputStream.getChannel();
CopyInformation = transfer(inputChannel, outputChannel, source.length(), true);
fileInputStream.close();
fileOutputStream.close();
return CopyInformation;
}
private ArrayList <String> transfer(FileChannel fileChannel, ByteChannel byteChannel, long lengthInBytes, boolean verbose)throws IOException {
ArrayList <String> getcopytext = new ArrayList <String> (0);
long overallBytesTransfered = 0L;
long time = -System.currentTimeMillis();
while (overallBytesTransfered < lengthInBytes) {
long bytesTransfered = 0L;
bytesTransfered = fileChannel.transferTo(overallBytesTransfered, Math.min(lBuffer, lengthInBytes - overallBytesTransfered), byteChannel);
overallBytesTransfered += bytesTransfered;
if (verbose) {
getcopytext.add("Bytes transfered: " + overallBytesTransfered + " progress: " + (Math.round(overallBytesTransfered / ((double) lengthInBytes) * 100.0)) + "%"+'\n');
}
}
time += System.currentTimeMillis();
if (verbose) {
getcopytext.add("Transfered: " + overallBytesTransfered + " bytes in: " + (time / 1000) + " s "+'\n'+""+'\n');
}
return getcopytext;
}
}
[/Java]
Wenn du keinen Rat mehr hast... kannst du mir vllt nen Tipp geben wie du so ne GUI aufsetzen würdest?
Vor allem mit neuen Buttons die zu einem existierendne frame hinzugefügt werden.
Das wäre echt super =)