Add Maker methods
This commit is contained in:
parent
dd5284972c
commit
8429d5d7ae
@ -2,6 +2,7 @@ package part5;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
|
||||
public class aufg {
|
||||
@ -33,7 +34,7 @@ public class aufg {
|
||||
}
|
||||
|
||||
public void loadDesign(){
|
||||
addLabeledTextField("TextBox");
|
||||
addLabeledTextField("TextBox", false);
|
||||
addMenuBar();
|
||||
addPasswordField();
|
||||
addImage("Medien/Bilder/info_I.png");
|
||||
@ -76,45 +77,88 @@ public class aufg {
|
||||
}
|
||||
|
||||
public void addLabel(String text){
|
||||
this.contentPane.add(makeLabel(text));
|
||||
}
|
||||
public JLabel makeLabel(String text){
|
||||
JLabel label = new JLabel(text);
|
||||
this.contentPane.add(label);
|
||||
return label;
|
||||
}
|
||||
|
||||
public void addTextField(int columns){
|
||||
this.contentPane.add(makeTextField(columns));
|
||||
}
|
||||
public JTextField makeTextField(int columns){
|
||||
JTextField textField = new JTextField(columns);
|
||||
this.contentPane.add(textField);
|
||||
return textField;
|
||||
}
|
||||
|
||||
public void addLabeledTextField(String labelText){
|
||||
addLabel(labelText);
|
||||
addTextField(10);
|
||||
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(){
|
||||
JPasswordField passwordField = new JPasswordField(10);
|
||||
this.contentPane.add(passwordField);
|
||||
return passwordField;
|
||||
}
|
||||
|
||||
public void addLabeledPasswordField(String label){
|
||||
addLabel(label);
|
||||
addPasswordField();
|
||||
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){
|
||||
JTextArea textArea = new JTextArea(rows, cols);
|
||||
this.contentPane.add(textArea);
|
||||
return textArea;
|
||||
}
|
||||
|
||||
public void addImage(String link){
|
||||
Icon i = new ImageIcon(link);
|
||||
JButton grafik = new JButton(i);
|
||||
this.contentPane.add(grafik);
|
||||
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());
|
||||
// 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);
|
||||
@ -123,6 +167,7 @@ public class aufg {
|
||||
}
|
||||
|
||||
b.add(Box.createVerticalStrut(10));
|
||||
this.contentPane.add(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user