import java.awt.*; import java.awt.event.*; class MsgBox extends Dialog implements ActionListener { public static final int OK = 1; public static final int CANCEL = 2; public static final int YES = 4; public static final int NO = 8; String result; // /Should/ make the result an INT equal to the value of the button. // But not today. MsgBox(String msg) { this(msg, "", OK); } MsgBox(String msg, String title) { this(msg, title, OK); } MsgBox(String msg, String title, int buttons) { super(new Frame(), title, true); setLocation(50,50); add("Center", new Label(msg, Label.CENTER)); Panel p = new Panel(); Button b; if(buttons==0 || (buttons | OK) == buttons) { b = new Button("OK"); b.addActionListener(this); p.add(b); } if((buttons | CANCEL) == buttons) { b = new Button("Cancel"); b.addActionListener(this); p.add(b); } if((buttons | YES) == buttons) { b = new Button("Yes"); b.addActionListener(this); p.add(b); } if((buttons | NO) == buttons) { b = new Button("No"); b.addActionListener(this); p.add(b); } add("South", p); pack(); } public void actionPerformed(ActionEvent e) { result = e.getActionCommand(); dispose(); } }