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/Listing3302.java | 107 +++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3302.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3302.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3302.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3302.java new file mode 100644 index 0000000..122da09 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3302.java @@ -0,0 +1,107 @@ +/* Listing3302.java */ + +import java.awt.*; +import java.awt.event.*; + +class MyDialog3302 +extends Dialog +implements ActionListener +{ + public MyDialog3302(Frame parent) + { + super(parent,"MyDialog3302",true); + setBounds(100,100,400,300); + setBackground(Color.lightGray); + setLayout(new BorderLayout()); + Panel panel = new Panel(); + customizeLayout(panel); + add(panel, BorderLayout.CENTER); + //Ende-Button + Button button = new Button("Ende"); + button.addActionListener(this); + add(button, BorderLayout.SOUTH); + pack(); + //Window-Ereignisse + addWindowListener( + new WindowAdapter() { + public void windowClosing(WindowEvent event) + { + endDialog(); + } + } + ); + } + + private void customizeLayout(Panel panel) + { + panel.setLayout(new FlowLayout()); + panel.add(new Segment7(0)); + panel.add(new Segment7(1)); + panel.add(new Segment7(2)); + panel.add(new Segment7(3)); + panel.add(new Segment7(4)); + panel.add(new Segment7(5)); + panel.add(new Segment7(6)); + panel.add(new Segment7(7)); + panel.add(new Segment7(8)); + panel.add(new Segment7(9)); + } + + public void actionPerformed(ActionEvent event) + { + String cmd = event.getActionCommand(); + if (cmd.equals("Ende")) { + endDialog(); + } + } + + void endDialog() + { + setVisible(false); + dispose(); + ((Window)getParent()).toFront(); + getParent().requestFocus(); + } +} + +public class Listing3302 +extends Frame +implements ActionListener +{ + public static void main(String[] args) + { + Listing3302 wnd = new Listing3302(); + wnd.setSize(300,200); + wnd.setVisible(true); + } + + public Listing3302() + { + super("7-Segment-Anzeige"); + setBackground(Color.lightGray); + setLayout(new FlowLayout()); + //Dialog-Button + Button button = new Button("Dialog"); + button.addActionListener(this); + add(button); + //Ende-Button + button = new Button("Ende"); + button.addActionListener(this); + add(button); + //Window-Ereignisse + addWindowListener(new WindowClosingAdapter(true)); + } + + public void actionPerformed(ActionEvent event) + { + String cmd = event.getActionCommand(); + if (cmd.equals("Dialog")) { + MyDialog3302 dlg = new MyDialog3302(this); + dlg.setVisible(true); + } else if (cmd.equals("Ende")) { + setVisible(false); + dispose(); + System.exit(0); + } + } +} \ No newline at end of file -- cgit v1.2.3