Add graphical user interface

master
Moritz 2026-11-15 16:57:27 +01:00
parent 1e5f800c26
commit a62112bbfa
2 changed files with 40 additions and 4 deletions

View File

@ -18,11 +18,11 @@ public class config_editor {
verify_config_file();
config_file_type();
parse_config_file();
if (args.length > 1 && args[1].equals("--Gui")) {
return;
if (args.length > 1 && args[1].equals("--gui")) {
graphical_user_interface.run(config_data);
} else {
config_data_edited = user_interface.run(config_data);
}
config_data_edited = user_interface.run(config_data);
}
static void verify_config_file() {

View File

@ -0,0 +1,36 @@
import javax.swing.*;
import java.util.Map;
public class graphical_user_interface {
public static void run(Map<String, Object> config_data) {
final int LABEL_HEIGHT = 30;
final int LABEL_WIDTH = 200;
final int SPACING_VERTICAL = 10;
final int SPACING_HORIZONTAL = 10;
int last_vertical_position = 10;
JFrame frame = new JFrame("Config Editor");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(null);
frame.setSize(440, 600);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setLayout(null);
scrollPane.setBounds(0, 0, frame.getWidth(), frame.getHeight());
for (Map.Entry<String, Object> entry : config_data.entrySet()) {
for (Map.Entry<String, Object> subEntry : ((Map<String, Object>) entry.getValue()).entrySet()) {
JLabel label = new JLabel(subEntry.getKey());
label.setBounds(10, last_vertical_position, LABEL_WIDTH, LABEL_HEIGHT);
scrollPane.add(label);
JTextField textField = new JTextField(subEntry.getValue().toString());
textField.setBounds(10 + LABEL_WIDTH + SPACING_HORIZONTAL, last_vertical_position + SPACING_VERTICAL,
LABEL_WIDTH, LABEL_HEIGHT);
scrollPane.add(textField);
last_vertical_position += LABEL_HEIGHT + SPACING_VERTICAL;
}
}
frame.add(scrollPane);
frame.setVisible(true);
}
}