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