Compare commits
5 Commits
8c5e3a705a
...
59998680ad
Author | SHA1 | Date | |
---|---|---|---|
|
59998680ad | ||
|
8429d5d7ae | ||
|
dd5284972c | ||
|
ba814ad400 | ||
|
238759ad89 |
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 |
@ -2,9 +2,14 @@ package part5;
|
||||
|
||||
public class Demo {
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 2; i++) {
|
||||
Window w = new Window("My Java GUI");
|
||||
w.display();
|
||||
}
|
||||
// for (int i = 0; i < 2; i++) {
|
||||
// Window w = new Window("My Java GUI");
|
||||
// w.display();
|
||||
// }
|
||||
|
||||
aufg gudWindow = new aufg("Mein Geilo GUI", 700, 420);
|
||||
gudWindow.loadDesign();
|
||||
gudWindow.display(true);
|
||||
|
||||
}
|
||||
}
|
||||
|
181
src/part5/aufg.java
Normal file
181
src/part5/aufg.java
Normal file
@ -0,0 +1,181 @@
|
||||
package part5;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
||||
public class aufg {
|
||||
private String title;
|
||||
private int height;
|
||||
private int width;
|
||||
private JFrame window;
|
||||
private JPanel contentPane;
|
||||
private JMenuBar menubar;
|
||||
|
||||
public aufg(String title, int height, int width){
|
||||
this.title = title;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.window = new JFrame();
|
||||
this.contentPane = new JPanel();
|
||||
this.menubar = new JMenuBar();
|
||||
}
|
||||
|
||||
public void display(boolean exitOnClose){
|
||||
this.window.setTitle(this.title);
|
||||
this.window.setSize(this.width, this.height);
|
||||
this.window.setContentPane(this.contentPane);
|
||||
this.window.setVisible(true);
|
||||
|
||||
if (exitOnClose){
|
||||
this.window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
public void loadDesign(){
|
||||
addMenuBar();
|
||||
addLabeledTextField("TextBox", true);
|
||||
addLabeledPasswordField("Password", true);
|
||||
addImage("Medien/Bilder/info_I.png");
|
||||
addImage("Medien/Bilder/HackerUnicorn_Schäbig.png");
|
||||
addLabeledRadioButtons("First Set of radiobuttons", new String[] {"Option1", "Choice2", "Variant3"}, true);
|
||||
addLabeledRadioButtons("Second Group of Options", new String[] {"Maybe this?", "Or that"}, true);
|
||||
}
|
||||
|
||||
public void addMenuBar(){
|
||||
JMenu file = new JMenu("File");
|
||||
JMenuItem fileOpen = new JMenuItem("Open");
|
||||
JMenuItem fileEdit = new JMenuItem("Edit");
|
||||
JMenuItem fileClose = new JMenuItem("Close");
|
||||
file.add(fileOpen);
|
||||
file.add(fileEdit);
|
||||
file.add(fileClose);
|
||||
|
||||
JMenu help = new JMenu("Help");
|
||||
JMenuItem helpInfo = new JMenuItem("Info");
|
||||
JMenuItem helpUnsub = new JMenuItem("Unsubscribe");
|
||||
help.add(helpInfo);
|
||||
help.add(helpUnsub);
|
||||
|
||||
JMenu english = new JMenu("English");
|
||||
JMenuItem englishChangeTo = new JMenuItem("Change to English");
|
||||
english.add(englishChangeTo);
|
||||
|
||||
JMenu braile = new JMenu("Braile");
|
||||
JMenuItem braileChangeTo = new JMenuItem("Change to Braile");
|
||||
braile.add(braileChangeTo);
|
||||
|
||||
this.menubar.add(file);
|
||||
this.menubar.add(help);
|
||||
this.menubar.add(english);
|
||||
this.menubar.add(braile);
|
||||
|
||||
this.window.setJMenuBar(this.menubar);
|
||||
}
|
||||
|
||||
public void addLabel(String text){
|
||||
this.contentPane.add(makeLabel(text));
|
||||
}
|
||||
public JLabel makeLabel(String text){
|
||||
return new JLabel(text);
|
||||
}
|
||||
|
||||
public void addTextField(int columns){
|
||||
this.contentPane.add(makeTextField(columns));
|
||||
}
|
||||
public JTextField makeTextField(int columns){
|
||||
return new JTextField(columns);
|
||||
}
|
||||
|
||||
public void addLabeledTextField(String labelText, boolean makeVertical){
|
||||
this.contentPane.add(makeLabeledTextField(labelText,makeVertical));
|
||||
}
|
||||
public Box makeLabeledTextField(String labelText, boolean makeVertical){
|
||||
Box b;
|
||||
|
||||
if (makeVertical) {
|
||||
b = Box.createVerticalBox();
|
||||
}else{
|
||||
b = Box.createHorizontalBox();
|
||||
}
|
||||
|
||||
b.add(makeLabel(labelText));
|
||||
b.add(makeTextField(10));
|
||||
return b;
|
||||
}
|
||||
|
||||
public void addPasswordField(){
|
||||
this.contentPane.add(makePasswordField());
|
||||
}
|
||||
public JPasswordField makePasswordField(){
|
||||
return new JPasswordField(10);
|
||||
}
|
||||
|
||||
public void addLabeledPasswordField(String label, boolean makeVertical){
|
||||
this.contentPane.add(makeLabeledPasswordField(label,makeVertical));
|
||||
}
|
||||
public Box makeLabeledPasswordField(String label, boolean makeVertical){
|
||||
Box b;
|
||||
|
||||
if (makeVertical) {
|
||||
b = Box.createVerticalBox();
|
||||
}else{
|
||||
b = Box.createHorizontalBox();
|
||||
}
|
||||
|
||||
b.add(makeLabel(label));
|
||||
b.add(makePasswordField());
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
public void addTextArea(int rows, int cols){
|
||||
this.contentPane.add(makeTextArea(rows, cols));
|
||||
}
|
||||
public JTextArea makeTextArea(int rows, int cols){
|
||||
return new JTextArea(rows, cols);
|
||||
}
|
||||
|
||||
public void addImage(String link){
|
||||
this.contentPane.add(makeImage(link));
|
||||
}
|
||||
public JButton makeImage(String link){
|
||||
Icon i = new ImageIcon(link);
|
||||
return new JButton(i);
|
||||
}
|
||||
public void addRadioButtons(String[] options){
|
||||
this.contentPane.add(makeRadioButtons(options));
|
||||
}
|
||||
public Box makeRadioButtons(String[] options){
|
||||
Box b = Box.createVerticalBox();
|
||||
ButtonGroup group = new ButtonGroup();
|
||||
// this.contentPane.setLayout(new FlowLayout()); Don't know what this does,
|
||||
// Can't be bothered to look it up
|
||||
// Can be bothered to type this tho
|
||||
|
||||
for (String option: options){
|
||||
JRadioButton button = new JRadioButton(option);
|
||||
b.add(button);
|
||||
group.add(button);
|
||||
}
|
||||
|
||||
b.add(Box.createVerticalStrut(10));
|
||||
return b;
|
||||
}
|
||||
|
||||
public void addLabeledRadioButtons(String label, String[] options, boolean makeVertical){
|
||||
this.contentPane.add(makeLabeledRadioButtons(label, options, makeVertical));
|
||||
}
|
||||
public Box makeLabeledRadioButtons(String label, String[] options, boolean makeVertical){
|
||||
Box b;
|
||||
|
||||
if (makeVertical) {
|
||||
b = Box.createVerticalBox();
|
||||
}else{
|
||||
b = Box.createHorizontalBox();
|
||||
}
|
||||
b.add(makeLabel(label));
|
||||
b.add(makeRadioButtons(options));
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user