summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java
diff options
context:
space:
mode:
authorSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
committerSven Eisenhauer <sven@sven-eisenhauer.net>2023-11-10 15:11:48 +0100
commit33613a85afc4b1481367fbe92a17ee59c240250b (patch)
tree670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java
downloadStudium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz
Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/Listing3110.java90
1 files changed, 90 insertions, 0 deletions
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