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/Listing3110.java | 90 ++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java') diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java new file mode 100644 index 0000000..c785bb7 --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java @@ -0,0 +1,90 @@ +/* Listing3110.java */ + +import java.awt.*; +import java.awt.event.*; + +class YesNoDialog +extends Dialog +implements ActionListener +{ + boolean result; + + public YesNoDialog(Frame owner, String msg) + { + super(owner, "Ja-/Nein-Auswahl", true); + //Fenster + setBackground(Color.lightGray); + setLayout(new BorderLayout()); + setResizable(false); //Hinweis im Text beachten + Point parloc = owner.getLocation(); + setLocation(parloc.x + 30, parloc.y + 30); + //Message + add(new Label(msg), BorderLayout.CENTER); + //Buttons + Panel panel = new Panel(); + panel.setLayout(new FlowLayout(FlowLayout.CENTER)); + Button button = new Button("Ja"); + button.addActionListener(this); + panel.add(button); + button = new Button("Nein"); + button.addActionListener(this); + panel.add(button); + add(panel, BorderLayout.SOUTH); + pack(); + } + + public void actionPerformed(ActionEvent event) + { + result = event.getActionCommand().equals("Ja"); + setVisible(false); + dispose(); + } + + public boolean getResult() + { + return result; + } +} + +public class Listing3110 +extends Frame +implements ActionListener +{ + public static void main(String[] args) + { + Listing3110 wnd = new Listing3110(); + wnd.setVisible(true); + } + + public Listing3110() + { + super("Modale Dialoge"); + setLayout(new FlowLayout()); + setBackground(Color.lightGray); + Button button = new Button("Ende"); + button.addActionListener(this); + add(button); + setLocation(100,100); + setSize(300,200); + setVisible(true); + } + + public void actionPerformed(ActionEvent event) + { + String cmd = event.getActionCommand(); + if (cmd.equals("Ende")) { + YesNoDialog dlg; + dlg = new YesNoDialog( + this, + "Wollen Sie das Programm wirklich beenden?" + ); + dlg.setVisible(true); + //Auf das Schließen des Dialogs warten... + if (dlg.getResult()) { + setVisible(false); + dispose(); + System.exit(0); + } + } + } +} \ No newline at end of file -- cgit v1.2.3