From 33613a85afc4b1481367fbe92a17ee59c240250b Mon Sep 17 00:00:00 2001 From: Sven Eisenhauer Date: Fri, 10 Nov 2023 15:11:48 +0100 Subject: add new repo --- .../hjp5/examples/Listing3106.java | 74 ++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3106.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3106.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3106.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3106.java new file mode 100644 index 0000000..49a0237 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3106.java @@ -0,0 +1,74 @@ +/* Listing3106.java */ + +import java.awt.*; +import java.awt.event.*; + +public class Listing3106 +extends Frame +{ + public static void main(String[] args) + { + Listing3106 wnd = new Listing3106(); + wnd.setVisible(true); + } + + public Listing3106() + { + super("Test GridBagLayout"); + setBackground(Color.lightGray); + addWindowListener(new WindowClosingAdapter(true)); + //Layout setzen und Komponenten hinzufügen + GridBagLayout gbl = new GridBagLayout(); + GridBagConstraints gbc; + setLayout(gbl); + + //List hinzufügen + List list = new List(); + for (int i = 0; i < 20; ++i) { + list.add("This is item " + i); + } + gbc = makegbc(0, 0, 1, 3); + gbc.weightx = 100; + gbc.weighty = 100; + gbc.fill = GridBagConstraints.BOTH; + gbl.setConstraints(list, gbc); + add(list); + //Zwei Labels und zwei Textfelder + for (int i = 0; i < 2; ++i) { + //Label + gbc = makegbc(1, i, 1, 1); + gbc.fill = GridBagConstraints.NONE; + Label label = new Label("Label " + (i + 1)); + gbl.setConstraints(label, gbc); + add(label); + //Textfeld + gbc = makegbc(2, i, 1, 1); + gbc.weightx = 100; + gbc.fill = GridBagConstraints.HORIZONTAL; + TextField field = new TextField("TextField " + (i +1)); + gbl.setConstraints(field, gbc); + add(field); + } + //Ende-Button + Button button = new Button("Ende"); + gbc = makegbc(2, 2, 0, 0); + gbc.fill = GridBagConstraints.NONE; + gbc.anchor = GridBagConstraints.SOUTHEAST; + gbl.setConstraints(button, gbc); + add(button); + //Dialogelemente layouten + pack(); + } + + private GridBagConstraints makegbc( + int x, int y, int width, int height) + { + GridBagConstraints gbc = new GridBagConstraints(); + gbc.gridx = x; + gbc.gridy = y; + gbc.gridwidth = width; + gbc.gridheight = height; + gbc.insets = new Insets(1, 1, 1, 1); + return gbc; + } +} \ No newline at end of file -- cgit v1.2.3