diff options
| author | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
|---|---|---|
| committer | Sven Eisenhauer <sven@sven-eisenhauer.net> | 2023-11-10 15:11:48 +0100 |
| commit | 33613a85afc4b1481367fbe92a17ee59c240250b (patch) | |
| tree | 670b842326116b376b505ec2263878912fca97e2 /Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java | |
| download | Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.gz Studium-33613a85afc4b1481367fbe92a17ee59c240250b.tar.bz2 | |
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java')
| -rw-r--r-- | Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java new file mode 100644 index 0000000..22c3b5e --- /dev/null +++ b/Master/Reference Architectures and Patterns/hjp5/examples/Listing3111.java @@ -0,0 +1,129 @@ +/* Listing3111.java */
+
+import java.awt.*;
+import java.awt.event.*;
+import java.util.*;
+
+class ModalDialog
+extends Dialog
+implements ActionListener
+{
+ String result;
+
+ public static String OKDialog(Frame owner, String msg)
+ {
+ ModalDialog dlg;
+ dlg = new ModalDialog(owner,"Nachricht",msg,"OK");
+ dlg.setVisible(true);
+ return dlg.getResult();
+ }
+
+ public static String YesNoDialog(Frame owner, String msg)
+ {
+ ModalDialog dlg;
+ dlg = new ModalDialog(owner,"Frage",msg,"Ja,Nein");
+ dlg.setVisible(true);
+ return dlg.getResult();
+ }
+
+ public static String YesNoCancelDialog(Frame owner,String msg)
+ {
+ ModalDialog dlg;
+ dlg = new ModalDialog(owner,"Frage",msg,"Ja,Nein,Abbruch");
+ dlg.setVisible(true);
+ return dlg.getResult();
+ }
+
+ public ModalDialog(
+ Frame owner,
+ String title,
+ String msg,
+ String buttons
+ )
+ {
+ super(owner, title, true);
+ //Fenster
+ setBackground(Color.lightGray);
+ setLayout(new BorderLayout());
+ setResizable(false);
+ 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));
+ StringTokenizer strtok = new StringTokenizer(buttons,",");
+ while (strtok.hasMoreTokens()) {
+ Button button = new Button(strtok.nextToken());
+ button.addActionListener(this);
+ panel.add(button);
+ }
+ add(panel, BorderLayout.SOUTH);
+ pack();
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ result = event.getActionCommand();
+ setVisible(false);
+ dispose();
+ }
+
+ public String getResult()
+ {
+ return result;
+ }
+}
+
+public class Listing3111
+extends Frame
+implements ActionListener
+{
+ public static void main(String[] args)
+ {
+ Listing3111 wnd = new Listing3111();
+ wnd.setVisible(true);
+ }
+
+ public Listing3111()
+ {
+ super("Drei modale Standarddialoge");
+ setLayout(new FlowLayout());
+ setBackground(Color.lightGray);
+ Button button = new Button("OKDialog");
+ button.addActionListener(this);
+ add(button);
+ button = new Button("YesNoDialog");
+ button.addActionListener(this);
+ add(button);
+ button = new Button("YesNoCancelDialog");
+ button.addActionListener(this);
+ add(button);
+ setLocation(100,100);
+ setSize(400,200);
+ setVisible(true);
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("OKDialog")) {
+ ModalDialog.OKDialog(this,"Dream, dream, dream, ...");
+ } else if (cmd.equals("YesNoDialog")) {
+ String ret = ModalDialog.YesNoDialog(
+ this,
+ "Programm beenden?"
+ );
+ if (ret.equals("Ja")) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ } else if (cmd.equals("YesNoCancelDialog")) {
+ String msg = "Verzeichnis erstellen?";
+ String ret = ModalDialog.YesNoCancelDialog(this,msg);
+ ModalDialog.OKDialog(this,"Rückgabe: " + ret);
+ }
+ }
+}
\ No newline at end of file |
