blob: c785bb7da998fd3f1fe38c5839ba41dac6b4040a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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);
}
}
}
}
|