summaryrefslogtreecommitdiffstats
path: root/Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.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/DialogBeispiel.java
downloadStudium-master.tar.gz
Studium-master.tar.bz2
add new repoHEADmaster
Diffstat (limited to 'Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.java')
-rw-r--r--Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.java98
1 files changed, 98 insertions, 0 deletions
diff --git a/Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.java b/Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.java
new file mode 100644
index 0000000..94afe8c
--- /dev/null
+++ b/Master/Reference Architectures and Patterns/hjp5/examples/DialogBeispiel.java
@@ -0,0 +1,98 @@
+/* DialogBeispiel.java */
+
+import java.awt.*;
+import java.awt.event.*;
+
+class MyDialog
+extends Dialog
+implements ActionListener
+{
+ public MyDialog(Frame parent)
+ {
+ super(parent,"MyDialog",true);
+ Point parloc = parent.getLocation();
+ setBounds(parloc.x + 30, parloc.y + 30,400,300);
+ setBackground(Color.lightGray);
+ setLayout(new BorderLayout());
+ //Panel
+ Panel panel = new Panel();
+ customizeLayout(panel);
+ add(panel, BorderLayout.CENTER);
+ //Ende-Button
+ Button button = new Button("Ende");
+ button.addActionListener(this);
+ add(button, BorderLayout.SOUTH);
+ //Window-Listener
+ addWindowListener(
+ new WindowAdapter() {
+ public void windowClosing(WindowEvent event)
+ {
+ endDialog();
+ }
+ }
+ );
+ pack();
+ }
+
+ private void customizeLayout(Panel panel)
+ {
+ //Beispielcode hier
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ if (event.getActionCommand().equals("Ende")) {
+ endDialog();
+ }
+ }
+
+ void endDialog()
+ {
+ setVisible(false);
+ dispose();
+ ((Window)getParent()).toFront();
+ getParent().requestFocus();
+ }
+}
+
+public class DialogBeispiel
+extends Frame
+implements ActionListener
+{
+ public static void main(String[] args)
+ {
+ DialogBeispiel wnd = new DialogBeispiel();
+ wnd.setSize(300,200);
+ wnd.setVisible(true);
+ }
+
+ public DialogBeispiel()
+ {
+ super("Beispiel Dialogelemente");
+ 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-Listener
+ addWindowListener(new WindowClosingAdapter(true));
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ String cmd = event.getActionCommand();
+ if (cmd.equals("Dialog")) {
+ MyDialog dlg = new MyDialog(this);
+ dlg.setVisible(true);
+ } else if (cmd.equals("Ende")) {
+ setVisible(false);
+ dispose();
+ System.exit(0);
+ }
+ }
+} \ No newline at end of file