diff --git a/Medien/Bilder/info_I.png b/Medien/Bilder/info_I.png new file mode 100644 index 0000000..3d99958 Binary files /dev/null and b/Medien/Bilder/info_I.png differ diff --git a/src/part5/Demo.java b/src/part5/Demo.java index 9388e7f..da3b127 100644 --- a/src/part5/Demo.java +++ b/src/part5/Demo.java @@ -7,9 +7,8 @@ public class Demo { // w.display(); // } - aufg gudWindow = new aufg("Mein Geilo GUI", 300, 420); - gudWindow.addLabeledTextField("TextBox"); - gudWindow.addMenuBar(); + aufg gudWindow = new aufg("Mein Geilo GUI", 700, 420); + gudWindow.loadDesign(); gudWindow.display(true); } diff --git a/src/part5/aufg.java b/src/part5/aufg.java index 8b7da23..fc3e1ee 100644 --- a/src/part5/aufg.java +++ b/src/part5/aufg.java @@ -1,8 +1,8 @@ package part5; -import javax.management.remote.JMXAddressable; import javax.swing.*; -import java.util.random.RandomGenerator; +import java.awt.*; + public class aufg { private String title; @@ -32,6 +32,18 @@ public class aufg { } } + public void loadDesign(){ + addLabeledTextField("TextBox"); + addMenuBar(); + addPasswordField(); + addImage("Medien/Bilder/info_I.png"); + addImage("Medien/Bilder/HackerUnicorn_Schäbig.png"); + addLabel("First Set of Radiobuttons"); + addRadioButtons(new String[] {"Option1", "Choice2", "Variant3"}); + addLabel("Second Group of Options"); + addRadioButtons(new String[] {"Maybe this?", "Or that"}); + } + public void addMenuBar(){ JMenu file = new JMenu("File"); JMenuItem fileOpen = new JMenuItem("Open"); @@ -63,11 +75,54 @@ public class aufg { this.window.setJMenuBar(this.menubar); } - public void addLabeledTextField(String labelText){ - JLabel label = new JLabel(labelText); - JTextField textField = new JTextField(10); - + public void addLabel(String text){ + JLabel label = new JLabel(text); this.contentPane.add(label); + } + + public void addTextField(int columns){ + JTextField textField = new JTextField(columns); this.contentPane.add(textField); } -} + + public void addLabeledTextField(String labelText){ + addLabel(labelText); + addTextField(10); + } + + public void addPasswordField(){ + JPasswordField passwordField = new JPasswordField(10); + this.contentPane.add(passwordField); + } + + public void addLabeledPasswordField(String label){ + addLabel(label); + addPasswordField(); + } + + public void addTextArea(int rows, int cols){ + JTextArea textArea = new JTextArea(rows, cols); + this.contentPane.add(textArea); + } + + public void addImage(String link){ + Icon i = new ImageIcon(link); + JButton grafik = new JButton(i); + this.contentPane.add(grafik); + } + + public void addRadioButtons(String[] options){ + Box b = Box.createVerticalBox(); + ButtonGroup group = new ButtonGroup(); + this.contentPane.setLayout(new FlowLayout()); + + for (String option: options){ + JRadioButton button = new JRadioButton(option); + b.add(button); + group.add(button); + } + + b.add(Box.createVerticalStrut(10)); + this.contentPane.add(b); + } +} \ No newline at end of file