Add Images / RadioButtons
This commit is contained in:
parent
ba814ad400
commit
dd5284972c
BIN
Medien/Bilder/info_I.png
Normal file
BIN
Medien/Bilder/info_I.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 750 B |
@ -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);
|
||||
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user