3599
|
1 |
/***************************************************************************
|
|
2 |
Title: awtUtilities/MessageDialog.java
|
|
3 |
ID: $Id$
|
|
4 |
Author: Stefan Berghofer, TU Muenchen
|
|
5 |
Copyright 1997 TU Muenchen
|
|
6 |
|
|
7 |
This class defines a dialog window for displaying messages and buttons.
|
|
8 |
***************************************************************************/
|
|
9 |
|
|
10 |
package awtUtilities;
|
|
11 |
|
|
12 |
import java.awt.*;
|
6541
|
13 |
import java.awt.event.*;
|
3599
|
14 |
|
6541
|
15 |
public class MessageDialog extends Dialog implements ActionListener {
|
3599
|
16 |
String txt;
|
|
17 |
|
|
18 |
public String getText() { return txt; }
|
|
19 |
|
6541
|
20 |
public void actionPerformed(ActionEvent evt) {
|
|
21 |
txt = evt.getActionCommand();
|
|
22 |
setVisible(false);
|
3599
|
23 |
}
|
|
24 |
|
|
25 |
public MessageDialog(Frame parent,String title,String text,String []buttons) {
|
|
26 |
super(parent,title,true);
|
|
27 |
int i;
|
|
28 |
Panel p1=new Panel(),p2=new Panel();
|
|
29 |
p1.setLayout(new FlowLayout(FlowLayout.CENTER,0,0));
|
|
30 |
p2.setLayout(new FlowLayout());
|
|
31 |
setFont(new Font("Helvetica", Font.PLAIN, 14));
|
|
32 |
setLayout(new GridLayout(2,1));
|
|
33 |
|
|
34 |
while (true) {
|
|
35 |
int pos=text.indexOf(' ');
|
|
36 |
if (pos<0) {
|
|
37 |
p1.add(new Label(text));
|
|
38 |
break;
|
|
39 |
} else {
|
|
40 |
p1.add(new Label(text.substring(0,pos)));
|
|
41 |
if (pos+1==text.length())
|
|
42 |
break;
|
|
43 |
else
|
|
44 |
text=text.substring(pos+1);
|
|
45 |
}
|
|
46 |
}
|
|
47 |
|
|
48 |
add(p1);add(p2);
|
6541
|
49 |
for (i=0;i<buttons.length;i++) {
|
|
50 |
Button bt = new Button(buttons[i]);
|
|
51 |
p2.add(bt);
|
|
52 |
bt.addActionListener(this);
|
|
53 |
}
|
3599
|
54 |
}
|
|
55 |
}
|