|
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.*; |
|
13 |
|
14 public class MessageDialog extends Dialog { |
|
15 String txt; |
|
16 |
|
17 public String getText() { return txt; } |
|
18 |
|
19 public boolean action(Event evt, Object arg) { |
|
20 if (evt.target instanceof Button) { |
|
21 txt=(String)arg; |
|
22 hide(); |
|
23 return true; |
|
24 } else return false; |
|
25 } |
|
26 |
|
27 public MessageDialog(Frame parent,String title,String text,String []buttons) { |
|
28 super(parent,title,true); |
|
29 int i; |
|
30 Panel p1=new Panel(),p2=new Panel(); |
|
31 p1.setLayout(new FlowLayout(FlowLayout.CENTER,0,0)); |
|
32 p2.setLayout(new FlowLayout()); |
|
33 setFont(new Font("Helvetica", Font.PLAIN, 14)); |
|
34 setLayout(new GridLayout(2,1)); |
|
35 |
|
36 while (true) { |
|
37 int pos=text.indexOf(' '); |
|
38 if (pos<0) { |
|
39 p1.add(new Label(text)); |
|
40 break; |
|
41 } else { |
|
42 p1.add(new Label(text.substring(0,pos))); |
|
43 if (pos+1==text.length()) |
|
44 break; |
|
45 else |
|
46 text=text.substring(pos+1); |
|
47 } |
|
48 } |
|
49 |
|
50 add(p1);add(p2); |
|
51 for (i=0;i<buttons.length;i++) |
|
52 p2.add(new Button(buttons[i])); |
|
53 } |
|
54 } |