From dd5284972c51bb2420b4fa3978876512471f2a31 Mon Sep 17 00:00:00 2001 From: Matti Date: Thu, 6 Jun 2024 21:28:01 +0200 Subject: [PATCH] Add Images / RadioButtons --- Medien/Bilder/info_I.png | Bin 0 -> 750 bytes src/part5/Demo.java | 5 ++- src/part5/aufg.java | 69 +++++++++++++++++++++++++++++++++++---- 3 files changed, 64 insertions(+), 10 deletions(-) create mode 100644 Medien/Bilder/info_I.png diff --git a/Medien/Bilder/info_I.png b/Medien/Bilder/info_I.png new file mode 100644 index 0000000000000000000000000000000000000000..3d99958b269b15df8cb16897cc5d4b98d3ac4a72 GIT binary patch literal 750 zcmVDeZ;+=A z(7HjkNkSui)WB2YGp&4Z;^Q-P+9207&`wg~{|JHjKdP5%bSen>BJw>0yyZ%~OKcX9 z@1{olO3fbCzzZo5w|fG3UdHlD{!GmtH$X2_Cy&3=>V=Hyg}ls0Nb=^-CSSf>x5u0X z1W6k_Fse@EO_lEtk-XhaC%!Wf`LnallNxwq*a8gj)<7jz>b%Rqk6uUibE^}_!&i~x zeqcyMUQS1sL+W;;ZU08cT3c$g9ny$)inaEIB(p#5GGk9xBfB4uR~=UYc&b146`PYj z#bvNkmle3R)OOqpv@T6!PyV}IrTgZSy#MsA6GvsmZT8KtsBT~DBYmjsWv~>Yi1eVh z0N|xz6Ez2fMqcbGKrSBH6+mnKtbmtRc|W`e0N&`m0v;|YsR=-e{(k}H(5Ddk*~BTW zz*?{}nvMWo40e#Ev;q@71&HaCRRIQCSNm<|K4eXR272GOn;ZkZ`ee>DKf|b<4&9+ zsq<2{RcOfRC~e0ey_5V#BTptiVN*fH=EQUo-$r_Nxp>IUPTG;UC6Q;OH$UG^#9d_; gKC_N6f;#;80Tt@d@KW<`D*ylh07*qoM6N<$g0ARL=Kufz literal 0 HcmV?d00001 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