blob: 94afe8c8847249cc125d73238b51b375dffba7df (
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
91
92
93
94
95
96
97
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);
}
}
}
|