public class Gui {
// private static final long serialVersionUID = 1L;
int x=0, y=0, width=800, height = 600;
int zeile =0;
int anzahltextfield=0;
String[] textField;
static JLabel labels[] = null;
static JTextField valueEingabe[] = null;
static JPanel panel = new JPanel();
static JPanel panel2 = new JPanel();
static JPanel panel3 = new JPanel();
static GridBagLayout gbl=new GridBagLayout();
static GridBagConstraints gbc=new GridBagConstraints();
JButton convert = new JButton("Convert");
JButton save = new JButton("save");
static BoxLayout boxLayout = new BoxLayout(panel, BoxLayout.X_AXIS);
public static ArrayList<String> parameterArray = DataRead.getParameterArray();
public static ArrayList<String> valueArray = DataRead.getValueArray();
public static ArrayList<String> textFeldEingaben = new ArrayList<String>();
public Gui(){
JDialog meinJDialog = new JDialog();
panel2.setLayout(gbl);
panel3.setLayout(gbl);
panel.setLayout(boxLayout);
this.createLabel(panel2, parameterArray, valueArray);
this.createButton(panel2, valueArray);
panel.add(panel2);
panel.add(panel3);
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getScreenSize();
x = (int) ((dim.getWidth()-width)/2);
y = (int) ((dim.getHeight()-height)/2);
meinJDialog.setTitle("GUI");
meinJDialog.setBounds(0, 0, 800, 600);
JScrollPane scrollPane = new JScrollPane (panel,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
// // JScrollPane wird dem Dialog hinzugefügt
meinJDialog.add(scrollPane);
// // Wir lassen unseren Dialog anzeigen
meinJDialog.setVisible(true);
}
public void createLabel(JPanel panel_to_add, ArrayList<String> parameterArray, ArrayList<String> valueArray)
{
if(labels==null){
labels = new JLabel[DataRead.längeDerParameter];
}
if(valueEingabe==null){
valueEingabe = new JTextField[DataRead.längeDerParameter];
}
for(int i = 0, j =0; i<parameterArray.size();i++){
labels[i] = new JLabel (parameterArray.get(i), JLabel.TRAILING);
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(2,2,2,2);
gbc.gridx=0;
gbc.gridy=0+i;
panel_to_add.add(labels[i],gbc);
if(!parameterArray.get(i).startsWith("[")){
valueEingabe[j] = new JTextField(valueArray.get(j));
gbc.gridx=1;
gbc.gridy=0+i;
gbc.weightx = 3;
panel_to_add.add(valueEingabe[j],gbc);
j++;
anzahltextfield++;
}
zeile++;
}
System.out.println("valuearray:"+valueArray);
}
public void createButton(JPanel panel_to_add, final ArrayList<String> valueArray)
{
gbc.gridx=0;
gbc.gridy=zeile+1;
gbc.weightx = 3;
panel_to_add.add(convert, gbc);
gbc.gridx=1;
gbc.gridy=zeile+1;
gbc.weightx = 3;
panel_to_add.add(save, gbc);
save.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
for(int i = 0; i<anzahltextfield;i++){
textFeldEingaben.add(valueEingabe[i].getText());
}
System.out.println("textfieldeingabe:"+textFeldEingaben);
}
});
convert.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e ) {
String jetzt ;
String vorher;
for(int i=0; i<valueArray.size();i++){
jetzt= textFeldEingaben.get(i);
vorher = valueArray.get(i);
if(!jetzt.equals(vorher)){
System.out.println(textFeldEingaben.get(i));
System.out.println(valueArray.get(i));
DataRead.ersetze(textFeldEingaben.get(i));
}
}
try{
Desktop desktop = Desktop.getDesktop();
desktop.edit(new File("D:/eclipse/IKV/Example_Input.txt"));
}catch (Exception exp){
}
}
});
}
public static void main(String[] args) {
DataRead.speichern();
new Gui();
}
}